Skip to content

Commit

Permalink
Fix for openvex report oci id
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsugara22 committed Oct 16, 2024
1 parent 973c6d2 commit e0e7a5f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
log.Warnf("Image name has no tag or digest, using latest as tag")
imageName = reference.TagNameOnly(imageName)
}
var tag string
taggedName, ok := imageName.(reference.Tagged)
if ok {
var tag string
var digest string
if taggedName, ok := imageName.(reference.Tagged); ok {
tag = taggedName.Tag()
digest, err = FetchImageDigest(taggedName)

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: FetchImageDigest

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: FetchImageDigest

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: FetchImageDigest

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: FetchImageDigest

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Unit Test

undefined: FetchImageDigest

Check failure on line 90 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / vuln-check

undefined: FetchImageDigest
if err != nil {
return err
}
imageName, err = reference.WithDigest(imageName, digest)

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Unit Test

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest

Check failure on line 94 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / vuln-check

cannot use digest (variable of type string) as "github.com/opencontainers/go-digest".Digest value in argument to reference.WithDigest
if err != nil {
return err
}
} else {
log.Warnf("Image name has no tag")
}
Expand All @@ -102,7 +110,12 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
if err != nil {
return fmt.Errorf("%w with patched tag %s", err, patchedTag)
}
patchedImageName := fmt.Sprintf("%s:%s", imageName.Name(), patchedTag)
// Make sure the digest was successfully fetched earlier and is valid
if digest == "" {
return fmt.Errorf("failed to fetch digest for image %s", imageName)
}

patchedImageName := fmt.Sprintf("%s@sha256:%s", imageName.Name(), digest)

// Ensure working folder exists for call to InstallUpdates
if workingFolder == "" {
Expand Down Expand Up @@ -134,6 +147,13 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
log.Debugf("updates to apply: %v", updates)
}

if updates != nil && len(updates.Updates) > 0 {
if err := vex.TryOutputVexDocument(updates, manager, patchedImageName, format, output); err != nil {

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: manager

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: manager

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: manager

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: manager

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Unit Test

undefined: manager

Check failure on line 151 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / vuln-check

undefined: manager
return err
}
}
return eg.Wait()

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: eg

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

undefined: eg

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: eg) (typecheck)

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / lint

undefined: eg (typecheck)

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / Unit Test

undefined: eg

Check failure on line 155 in pkg/patch/patch.go

View workflow job for this annotation

GitHub Actions / vuln-check

undefined: eg

bkClient, err := buildkit.NewClient(ctx, bkOpts)
if err != nil {
return err
Expand Down

0 comments on commit e0e7a5f

Please sign in to comment.