pass oci client to commands directly

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-05 14:39:28 -07:00
parent af90403ecb
commit 65071223d8
6 changed files with 16 additions and 18 deletions

View file

@ -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

View file

@ -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 [<file path> | oci://<OCI image URI>]",
@ -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]

View file

@ -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")

View file

@ -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 [<file path> | oci://<OCI image URI>]",
@ -50,6 +51,8 @@ func NewInspectCmd(f *cmdutil.Factory) *cobra.Command {
$ gh attestation inspect oci://<my-OCI-image> --bundle <path-to-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)

View file

@ -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 != "" {

View file

@ -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 <artifact-path-or-url>",
@ -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]