Skip to content

Commit

Permalink
fix(saas) change saas upload s3 key (future-architect#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadayuki-matsuno authored Jan 27, 2021
1 parent dd2959a commit a8c0926
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
10 changes: 9 additions & 1 deletion saas/saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package saas
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
9 changes: 0 additions & 9 deletions saas/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"regexp"
"sort"
"strings"
"time"

"github.com/BurntSushi/toml"
c "github.com/future-architect/vuls/config"
Expand All @@ -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,
Expand Down

0 comments on commit a8c0926

Please sign in to comment.