Skip to content

Commit

Permalink
Fix copy --only for signatures + update/align docs
Browse files Browse the repository at this point in the history
See
https://github.com/sigstore/cosign/blob/main/cmd/cosign/cli/copy/copy.go#L192
requires to have value `sig` instead of `sign`.

Also aligned the option docs order to align with the order of the
example. https://github.com/sigstore/cosign/blob/main/cmd/cosign/cli/copy.go#L40

Signed-off-by: Marco Franssen <[email protected]>
  • Loading branch information
marcofranssen committed Oct 11, 2024
1 parent a0752eb commit ac48b3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions cmd/cosign/cli/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ func CopyCmd(ctx context.Context, regOpts options.RegistryOptions, srcImg, dstIm
}

onlyFlagSet := false
tags := parseOnlyOpt(copyOnly, sigOnly)
tags, err := parseOnlyOpt(copyOnly, sigOnly)
if err != nil {
return err
}
if len(tags) > 0 {
onlyFlagSet = true
} else {
Expand Down Expand Up @@ -180,13 +183,20 @@ func remoteCopy(ctx context.Context, pusher *remote.Pusher, src, dest name.Refer
return pusher.Push(ctx, dest, got)
}

func parseOnlyOpt(onlyFlag string, sigOnly bool) []tagMap {
func parseOnlyOpt(onlyFlag string, sigOnly bool) ([]tagMap, error) {
var tags []tagMap
tagSet := sets.New(strings.Split(onlyFlag, ",")...)

if sigOnly {
fmt.Fprintf(os.Stderr, "--sig-only is deprecated, use --only=sig instead")
tagSet.Insert("sign")
tagSet.Insert("sig")
}

validTags := sets.New("sig", "sbom", "att")
for tag := range tagSet {
if !validTags.Has(tag) {
return nil, fmt.Errorf("invalid value for --only: %s, only following values are supported, %s", tag, validTags)
}
}

if tagSet.Has("sig") {
Expand All @@ -198,5 +208,5 @@ func parseOnlyOpt(onlyFlag string, sigOnly bool) []tagMap {
if tagSet.Has("att") {
tags = append(tags, ociremote.AttestationTag)
}
return tags
return tags, nil
}
2 changes: 1 addition & 1 deletion cmd/cosign/cli/options/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (o *CopyOptions) AddFlags(cmd *cobra.Command) {
o.Registry.AddFlags(cmd)

cmd.Flags().StringVar(&o.CopyOnly, "only", "",
"custom string array to only copy specific items, this flag is comma delimited. ex: --only=sbom,sign,att")
"custom string array to only copy specific items, this flag is comma delimited. ex: --only=sig,att,sbom")

cmd.Flags().BoolVar(&o.SignatureOnly, "sig-only", false,
"[DEPRECATED] only copy the image signature")
Expand Down
2 changes: 1 addition & 1 deletion doc/cosign_copy.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac48b3d

Please sign in to comment.