Skip to content

Commit

Permalink
Merge bdd38ff into ec47ee8
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed May 30, 2023
2 parents ec47ee8 + bdd38ff commit 1ad696b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/services/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (s *ScanService) GenerateSBOM(ctx context.Context) error {
ctx, span := otel.Tracer("").Start(ctx, "ScanService.GenerateSBOM")
defer span.End()

ctx = addTimestamp(ctx)

// retrieve workload from context
workload, ok := ctx.Value(domain.WorkloadKey{}).(domain.ScanCommand)
if !ok {
Expand Down Expand Up @@ -115,6 +117,8 @@ func (s *ScanService) ScanCVE(ctx context.Context) error {
ctx, span := otel.Tracer("").Start(ctx, "ScanService.ScanCVE")
defer span.End()

ctx = addTimestamp(ctx)

// retrieve workload from context
workload, ok := ctx.Value(domain.WorkloadKey{}).(domain.ScanCommand)
if !ok {
Expand Down Expand Up @@ -236,6 +240,8 @@ func (s *ScanService) ScanRegistry(ctx context.Context) error {
ctx, span := otel.Tracer("").Start(ctx, "ScanService.ScanRegistry")
defer span.End()

ctx = addTimestamp(ctx)

// retrieve workload from context
workload, ok := ctx.Value(domain.WorkloadKey{}).(domain.ScanCommand)
if !ok {
Expand Down Expand Up @@ -287,12 +293,13 @@ func (s *ScanService) ScanRegistry(ctx context.Context) error {
return nil
}

func addTimestamp(ctx context.Context) context.Context {
return context.WithValue(ctx, domain.TimestampKey{}, time.Now().Unix())
}

func enrichContext(ctx context.Context, workload domain.ScanCommand) context.Context {
// record start time
ctx = context.WithValue(ctx, domain.TimestampKey{}, time.Now().Unix())
// generate unique scanID and add to context
scanID := generateScanID(workload)

ctx = context.WithValue(ctx, domain.ScanIDKey{}, scanID)
// add workload to context
ctx = context.WithValue(ctx, domain.WorkloadKey{}, workload)
Expand Down

0 comments on commit 1ad696b

Please sign in to comment.