From a89079c0051e9180ac4e242aa113b50378b5af11 Mon Sep 17 00:00:00 2001 From: sadayuki-matsuno Date: Wed, 27 Jan 2021 14:43:09 +0900 Subject: [PATCH] fix(saas) change saas upload s3 key (#1116) --- saas/saas.go | 10 +++++++++- saas/uuid.go | 9 --------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/saas/saas.go b/saas/saas.go index eb46cca1..a7a78063 100644 --- a/saas/saas.go +++ b/saas/saas.go @@ -3,6 +3,7 @@ package saas import ( "bytes" "encoding/json" + "fmt" "io/ioutil" "net/http" "net/url" @@ -120,7 +121,7 @@ func (w Writer) Write(rs ...models.ScanResult) (err error) { svc := s3.New(sess) for _, r := range rs { - s3Key := renameKeyNameUTC(r.ScannedAt, r.ServerUUID, r.Container) + s3Key := renameKeyName(r.ServerUUID, r.Container) var b []byte if b, err = json.Marshal(r); err != nil { return xerrors.Errorf("Failed to Marshal to JSON: %w", err) @@ -140,3 +141,10 @@ func (w Writer) Write(rs ...models.ScanResult) (err error) { util.Log.Infof("done") return nil } + +func renameKeyName(uuid string, container models.Container) string { + if len(container.ContainerID) == 0 { + return fmt.Sprintf("%s.json", uuid) + } + return fmt.Sprintf("%s@%s.json", container.UUID, uuid) +} diff --git a/saas/uuid.go b/saas/uuid.go index c44051f1..f1bf1d87 100644 --- a/saas/uuid.go +++ b/saas/uuid.go @@ -9,7 +9,6 @@ import ( "regexp" "sort" "strings" - "time" "github.com/BurntSushi/toml" c "github.com/future-architect/vuls/config" @@ -19,14 +18,6 @@ import ( "golang.org/x/xerrors" ) -func renameKeyNameUTC(scannedAt time.Time, uuid string, container models.Container) string { - timestr := scannedAt.UTC().Format(time.RFC3339) - if len(container.ContainerID) == 0 { - return fmt.Sprintf("%s/%s.json", timestr, uuid) - } - return fmt.Sprintf("%s/%s@%s.json", timestr, container.UUID, uuid) -} - const reUUID = "[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}" // Scanning with the -containers-only flag at scan time, the UUID of Container Host may not be generated,