Skip to content

Commit 4e0d476

Browse files
committed
add registry options to cosign save
Signed-off-by: JasonPowr <[email protected]>
1 parent 6206f5a commit 4e0d476

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

cmd/cosign/cli/options/save.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222
// SaveOptions is the top level wrapper for the load command.
2323
type SaveOptions struct {
2424
Directory string
25+
Registry RegistryOptions
2526
}
2627

2728
var _ Interface = (*SaveOptions)(nil)
2829

2930
// AddFlags implements Interface
3031
func (o *SaveOptions) AddFlags(cmd *cobra.Command) {
32+
o.Registry.AddFlags(cmd)
3133
cmd.Flags().StringVar(&o.Directory, "dir", "",
3234
"path to dir where the signed image should be stored on disk")
3335
_ = cmd.Flags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})

cmd/cosign/cli/save.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,33 @@ func Save() *cobra.Command {
4747
return cmd
4848
}
4949

50-
func SaveCmd(_ context.Context, opts options.SaveOptions, imageRef string) error {
51-
ref, err := name.ParseReference(imageRef)
50+
func SaveCmd(ctx context.Context, opts options.SaveOptions, imageRef string) error {
51+
regOpts := opts.Registry
52+
regClientOpts, err := regOpts.ClientOpts(ctx)
53+
if err != nil {
54+
return fmt.Errorf("constructing client options: %w", err)
55+
}
56+
57+
ref, err := name.ParseReference(imageRef, opts.Registry.NameOptions()...)
5258
if err != nil {
5359
return fmt.Errorf("parsing image name %s: %w", imageRef, err)
5460
}
5561

56-
se, err := ociremote.SignedEntity(ref)
62+
se, err := ociremote.SignedEntity(ref, regClientOpts...)
5763
if err != nil {
5864
return fmt.Errorf("signed entity: %w", err)
5965
}
6066

6167
if _, ok := se.(oci.SignedImage); ok {
62-
si, err := ociremote.SignedImage(ref)
68+
si, err := ociremote.SignedImage(ref, regClientOpts...)
6369
if err != nil {
6470
return fmt.Errorf("getting signed image: %w", err)
6571
}
6672
return layout.WriteSignedImage(opts.Directory, si)
6773
}
6874

6975
if _, ok := se.(oci.SignedImageIndex); ok {
70-
sii, err := ociremote.SignedImageIndex(ref)
76+
sii, err := ociremote.SignedImageIndex(ref, regClientOpts...)
7177
if err != nil {
7278
return fmt.Errorf("getting signed image index: %w", err)
7379
}

doc/cosign_save.md

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)