Skip to content

Commit

Permalink
Base64-decode SBOM
Browse files Browse the repository at this point in the history
Signed-off-by: felipecruz91 <[email protected]>
  • Loading branch information
felipecruz91 committed Feb 2, 2024
1 parent 5851fe9 commit ad3ef08
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions policy/policy_handler/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package policy_handler

import (
"context"
"encoding/base64"
"fmt"

"github.com/atomist-skills/go-skill"
Expand All @@ -18,7 +19,7 @@ type SyncRequestMetadata struct {
QueryResults map[edn.Keyword]edn.RawMessage `edn:"fixedQueryResults"`
Packages []legacy.Package `edn:"packages"` // todo remove when no longer used
User string `edn:"imgConfigUser"` // The user from the image config blob // todo remove when no longer used
SBOM *types.SBOM `edn:"sbom"`
SBOM string `edn:"sbom"`
}

func WithLocal() Opt {
Expand Down Expand Up @@ -59,8 +60,16 @@ func buildLocalDataSources(ctx context.Context, req skill.RequestContext, _ goal
return nil, fmt.Errorf("failed to unmarshal SyncRequest metadata: %w", err)
}

if srMeta.SBOM != nil {
srMeta.QueryResults = legacy.BuildLocalEvalMocks(srMeta.SBOM, req.Log)
if srMeta.SBOM != "" {
decodedSBOM, err := base64.StdEncoding.DecodeString(srMeta.SBOM)
if err != nil {
return nil, fmt.Errorf("failed to base64-decode SBOM: %w", err)
}
var sbom *types.SBOM
if err := edn.Unmarshal(decodedSBOM, &sbom); err != nil {
return nil, fmt.Errorf("failed to unmarshal SBOM: %w", err)
}
srMeta.QueryResults = legacy.BuildLocalEvalMocks(sbom, req.Log)
}

fixedQueryResults := map[string][]byte{}
Expand Down

0 comments on commit ad3ef08

Please sign in to comment.