From 65071223d8e5d1a6e67137614c4eeb593b328a1b Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Tue, 5 Mar 2024 14:39:28 -0700 Subject: [PATCH] pass oci client to commands directly Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/attestation.go | 9 ++++++--- pkg/cmd/attestation/download/download.go | 5 +++-- pkg/cmd/attestation/download/options.go | 5 ----- pkg/cmd/attestation/inspect/inspect.go | 5 ++++- pkg/cmd/attestation/verify/options.go | 5 ----- pkg/cmd/attestation/verify/verify.go | 5 +++-- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pkg/cmd/attestation/attestation.go b/pkg/cmd/attestation/attestation.go index d195e18ef..ded45a69b 100644 --- a/pkg/cmd/attestation/attestation.go +++ b/pkg/cmd/attestation/attestation.go @@ -1,6 +1,7 @@ package attestation import ( + "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" "github.com/cli/cli/v2/pkg/cmd/attestation/download" "github.com/cli/cli/v2/pkg/cmd/attestation/inspect" "github.com/cli/cli/v2/pkg/cmd/attestation/verify" @@ -28,9 +29,11 @@ func NewCmdAttestation(f *cmdutil.Factory) *cobra.Command { `, "`"), } - root.AddCommand(download.NewDownloadCmd(f)) - root.AddCommand(inspect.NewInspectCmd(f)) - root.AddCommand(verify.NewVerifyCmd(f)) + ociClient := oci.NewLiveClient() + + root.AddCommand(download.NewDownloadCmd(f, ociClient)) + root.AddCommand(inspect.NewInspectCmd(f, ociClient)) + root.AddCommand(verify.NewVerifyCmd(f, ociClient)) root.AddCommand(verifytufroot.NewVerifyTUFRootCmd(f)) return root diff --git a/pkg/cmd/attestation/download/download.go b/pkg/cmd/attestation/download/download.go index d859ba906..47fcdf4f5 100644 --- a/pkg/cmd/attestation/download/download.go +++ b/pkg/cmd/attestation/download/download.go @@ -7,6 +7,7 @@ import ( "github.com/cli/cli/v2/pkg/cmd/attestation/api" "github.com/cli/cli/v2/pkg/cmd/attestation/artifact" + "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" "github.com/cli/cli/v2/pkg/cmd/attestation/auth" "github.com/cli/cli/v2/pkg/cmd/attestation/logging" "github.com/cli/cli/v2/pkg/cmdutil" @@ -15,7 +16,7 @@ import ( "github.com/spf13/cobra" ) -func NewDownloadCmd(f *cmdutil.Factory) *cobra.Command { +func NewDownloadCmd(f *cmdutil.Factory, oc oci.Client) *cobra.Command { opts := &Options{} downloadCmd := &cobra.Command{ Use: "download [ | oci://]", @@ -61,7 +62,7 @@ func NewDownloadCmd(f *cmdutil.Factory) *cobra.Command { opts.Logger = logging.NewLogger(f.IOStreams, false, opts.Verbose) // Configure the live OCI client - opts.ConfigureOCIClient() + opts.OCIClient = oc // set the artifact path opts.ArtifactPath = args[0] diff --git a/pkg/cmd/attestation/download/options.go b/pkg/cmd/attestation/download/options.go index dcd3796d0..1e66d58d3 100644 --- a/pkg/cmd/attestation/download/options.go +++ b/pkg/cmd/attestation/download/options.go @@ -21,11 +21,6 @@ type Options struct { Verbose bool } -// ConfigureOCIClient configures an OCI client -func (opts *Options) ConfigureOCIClient() { - opts.OCIClient = oci.NewLiveClient() -} - func (opts *Options) AreFlagsValid() error { if opts.Owner == "" { return fmt.Errorf("owner must be provided") diff --git a/pkg/cmd/attestation/inspect/inspect.go b/pkg/cmd/attestation/inspect/inspect.go index e35f68f19..e0d48bd39 100644 --- a/pkg/cmd/attestation/inspect/inspect.go +++ b/pkg/cmd/attestation/inspect/inspect.go @@ -6,6 +6,7 @@ import ( "os" "github.com/cli/cli/v2/pkg/cmd/attestation/artifact" + "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" "github.com/cli/cli/v2/pkg/cmd/attestation/auth" "github.com/cli/cli/v2/pkg/cmd/attestation/logging" "github.com/cli/cli/v2/pkg/cmd/attestation/verification" @@ -15,7 +16,7 @@ import ( "github.com/spf13/cobra" ) -func NewInspectCmd(f *cmdutil.Factory) *cobra.Command { +func NewInspectCmd(f *cmdutil.Factory, oc oci.Client) *cobra.Command { opts := &Options{} inspectCmd := &cobra.Command{ Use: "inspect [ | oci://]", @@ -50,6 +51,8 @@ func NewInspectCmd(f *cmdutil.Factory) *cobra.Command { $ gh attestation inspect oci:// --bundle `), PreRunE: func(cmd *cobra.Command, args []string) error { + opts.OCIClient = oc + // Create a logger for use throughout the inspect command opts.Logger = logging.NewDefaultLogger(f.IOStreams) diff --git a/pkg/cmd/attestation/verify/options.go b/pkg/cmd/attestation/verify/options.go index 212b2af60..19b1f8008 100644 --- a/pkg/cmd/attestation/verify/options.go +++ b/pkg/cmd/attestation/verify/options.go @@ -33,11 +33,6 @@ type Options struct { OCIClient oci.Client } -// ConfigureOCIClient configures an OCI client -func (opts *Options) ConfigureOCIClient() { - opts.OCIClient = oci.NewLiveClient() -} - // Clean cleans the file path option values func (opts *Options) Clean() { if opts.BundlePath != "" { diff --git a/pkg/cmd/attestation/verify/verify.go b/pkg/cmd/attestation/verify/verify.go index d6b668cce..96eb53437 100644 --- a/pkg/cmd/attestation/verify/verify.go +++ b/pkg/cmd/attestation/verify/verify.go @@ -8,6 +8,7 @@ import ( "github.com/cli/cli/v2/pkg/cmd/attestation/api" "github.com/cli/cli/v2/pkg/cmd/attestation/artifact" + "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" "github.com/cli/cli/v2/pkg/cmd/attestation/auth" "github.com/cli/cli/v2/pkg/cmd/attestation/logging" "github.com/cli/cli/v2/pkg/cmd/attestation/verification" @@ -19,7 +20,7 @@ import ( var ErrNoMatchingSLSAPredicate = fmt.Errorf("the attestation does not have the expected SLSA predicate type: %s", SLSAPredicateType) -func NewVerifyCmd(f *cmdutil.Factory) *cobra.Command { +func NewVerifyCmd(f *cmdutil.Factory, oc oci.Client) *cobra.Command { opts := &Options{} verifyCmd := &cobra.Command{ Use: "verify ", @@ -75,7 +76,7 @@ func NewVerifyCmd(f *cmdutil.Factory) *cobra.Command { opts.Logger = logging.NewLogger(f.IOStreams, opts.Quiet, opts.Verbose) // Configure the live OCI client - opts.ConfigureOCIClient() + opts.OCIClient = oc // set the artifact path opts.ArtifactPath = args[0]