Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update go mod #119

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions commands/fetch-oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ import (

// FetchOracleCmd is Subcommand for fetch Oracle OVAL
type FetchOracleCmd struct {
// Debug bool
// DebugSQL bool
// Quiet bool
// NoDetails bool
LogDir string
LogJSON bool
// DBPath string
// DBType string
// HTTPProxy string
}

// Name return subcommand name
Expand Down
20 changes: 7 additions & 13 deletions db/redis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package db

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/go-redis/redis/v8"
"github.com/go-redis/redis"
"github.com/inconshreveable/log15"
c "github.com/kotakanbe/goval-dictionary/config"
"github.com/kotakanbe/goval-dictionary/models"
Expand Down Expand Up @@ -102,14 +101,13 @@ func (d *RedisDriver) Name() string {

// OpenDB opens Database
func (d *RedisDriver) OpenDB(dbType, dbPath string, debugSQL bool) (err error) {
ctx := context.Background()
var option *redis.Options
if option, err = redis.ParseURL(dbPath); err != nil {
log15.Error("Failed to parse url", "err", err)
return fmt.Errorf("Failed to Parse Redis URL. dbpath: %s, err: %s", dbPath, err)
}
d.conn = redis.NewClient(option)
if err = d.conn.Ping(ctx).Err(); err != nil {
if err = d.conn.Ping().Err(); err != nil {
return fmt.Errorf("Failed to open DB. dbtype: %s, dbpath: %s, err: %s", dbType, dbPath, err)
}
return nil
Expand All @@ -126,7 +124,6 @@ func (d *RedisDriver) CloseDB() (err error) {

// GetByPackName select OVAL definition related to OS Family, osVer, packName, arch
func (d *RedisDriver) GetByPackName(family, osVer, packName, arch string) ([]models.Definition, error) {
ctx := context.Background()
switch family {
case c.CentOS:
family = c.RedHat
Expand All @@ -149,7 +146,7 @@ func (d *RedisDriver) GetByPackName(family, osVer, packName, arch string) ([]mod
}

var result *redis.StringSliceCmd
if result = d.conn.ZRange(ctx, zkey, 0, -1); result.Err() != nil {
if result = d.conn.ZRange(zkey, 0, -1); result.Err() != nil {
log15.Error("Failed to get definition from package", "err", result.Err())
return nil, result.Err()
}
Expand Down Expand Up @@ -183,7 +180,6 @@ func (d *RedisDriver) GetByCveID(family, osVer, cveID string) ([]models.Definiti

// InsertOval inserts OVAL
func (d *RedisDriver) InsertOval(family string, root *models.Root, meta models.FetchMeta) (err error) {
ctx := context.Background()
definitions := aggregateAffectedPackages(root.Definitions)
total := map[string]struct{}{}
for chunked := range chunkSlice(definitions, 10) {
Expand All @@ -209,7 +205,7 @@ func (d *RedisDriver) InsertOval(family string, root *models.Root, meta models.F
}
for cveID := range cveIDs {
hashKey := getHashKey(root.Family, root.OSVersion, cveID)
if result := pipe.HSet(ctx, hashKey, def.DefinitionID, string(dj)); result.Err() != nil {
if result := pipe.HSet(hashKey, def.DefinitionID, string(dj)); result.Err() != nil {
return fmt.Errorf("Failed to HSet Definition. err: %s", result.Err())
}
for _, pack := range def.AffectedPacks {
Expand All @@ -219,9 +215,8 @@ func (d *RedisDriver) InsertOval(family string, root *models.Root, meta models.F
zkey = hashKeyPrefix + pack.Name + hashKeySeparator + pack.Arch
}
if result := pipe.ZAdd(
ctx,
zkey,
&redis.Z{
redis.Z{
Score: 0,
Member: hashKey,
}); result.Err() != nil {
Expand All @@ -231,7 +226,7 @@ func (d *RedisDriver) InsertOval(family string, root *models.Root, meta models.F
total[cveID] = struct{}{}
}
}
if _, err = pipe.Exec(ctx); err != nil {
if _, err = pipe.Exec(); err != nil {
return fmt.Errorf("Failed to exec pipeline. err: %s", err)
}
}
Expand Down Expand Up @@ -284,8 +279,7 @@ func chunkSlice(l []models.Definition, n int) chan []models.Definition {
}

func getByHashKey(hashKey string, driver *redis.Client) ([]models.Definition, error) {
ctx := context.Background()
result := driver.HGetAll(ctx, hashKey)
result := driver.HGetAll(hashKey)
if result.Err() != nil {
log15.Error("Failed to get definition.", "err", result.Err())
return nil, result.Err()
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module github.com/kotakanbe/goval-dictionary

go 1.12
go 1.15

require (
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/go-redis/redis/v8 v8.4.0
github.com/google/subcommands v1.0.1
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/subcommands v1.2.0
github.com/htcat/htcat v1.0.2
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
github.com/jinzhu/gorm v1.9.10
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
github.com/jinzhu/gorm v1.9.16
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/k0kubun/pp v3.0.1+incompatible
github.com/kr/pretty v0.2.1 // indirect
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.2.9 // indirect
github.com/mattn/go-sqlite3 v1.11.0
github.com/labstack/echo/v4 v4.1.17
github.com/mattn/go-sqlite3 v1.14.6
github.com/onsi/ginkgo v1.14.2 // indirect
github.com/onsi/gomega v1.10.4 // indirect
github.com/ymomoi/goval-parser v0.0.0-20170813122243-0a0be1dd9d08
gopkg.in/yaml.v2 v2.3.0
)
Loading