Skip to content

Commit

Permalink
use existing opts to add it
Browse files Browse the repository at this point in the history
Signed-off-by: Mritunjay <[email protected]>
  • Loading branch information
mritunjaysharma394 committed May 23, 2023
1 parent 5e7b7fa commit 5534ad2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
19 changes: 4 additions & 15 deletions cmd/cosign/cli/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ package cli

import (
"context"
"crypto/tls"
"fmt"
"net/http"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"

"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/pkg/oci/layout"
"github.com/sigstore/cosign/v2/pkg/oci/remote"

ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"github.com/spf13/cobra"
)

Expand All @@ -49,25 +47,16 @@ func Load() *cobra.Command {
return cmd
}

func LoadCmd(ctx context.Context, opts options.LoadOptions, imageRef string) error {
func LoadCmd(_ context.Context, opts options.LoadOptions, imageRef string) error {
ref, err := name.ParseReference(imageRef)
if err != nil {
return fmt.Errorf("parsing image name %s: %w", imageRef, err)
}

remoteOpts := []remote.Option{
remote.WithContext(ctx),
remote.WithUserAgent(options.UserAgent()),
}
// get the signed image from disk
sii, err := layout.SignedImageIndex(opts.Directory)
if err != nil {
return fmt.Errorf("signed image index: %w", err)
}

if opts.AllowInsecure {
remoteOpts = append(remoteOpts, remote.WithTransport(&http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}})) // #nosec G402
}

return ociremote.WriteSignedImageIndexImages(ref, sii, ociremote.WithRemoteOptions(remoteOpts...))
return remote.WriteSignedImageIndexImages(ref, sii)
}
8 changes: 3 additions & 5 deletions cmd/cosign/cli/options/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ import (

// LoadOptions is the top level wrapper for the load command.
type LoadOptions struct {
Directory string
AllowInsecure bool
Directory string
Registry RegistryOptions
}

var _ Interface = (*LoadOptions)(nil)

// AddFlags implements Interface
func (o *LoadOptions) AddFlags(cmd *cobra.Command) {
o.Registry.AddFlags(cmd)
cmd.Flags().StringVar(&o.Directory, "dir", "",
"path to directory where the signed image is stored on disk")
_ = cmd.Flags().SetAnnotation("dir", cobra.BashCompSubdirsInDir, []string{})
_ = cmd.MarkFlagRequired("dir")

cmd.Flags().BoolVar(&o.AllowInsecure, "allow-insecure-registry", false,
"whether to allow insecure connections to registries (e.g., with expired or self-signed TLS certificates). Don't use this for anything but testing")
}
9 changes: 6 additions & 3 deletions doc/cosign_load.md

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

0 comments on commit 5534ad2

Please sign in to comment.