diff --git a/src/cmd/root.go b/src/cmd/root.go index 55faf571..1072735b 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -80,7 +80,7 @@ func init() { zarfCmd := &cobra.Command{ Use: "zarf COMMAND", Aliases: []string{"z"}, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { os.Args = os.Args[1:] // grab 'zarf' and onward from the CLI args zarfCLI.Execute() }, diff --git a/src/cmd/run.go b/src/cmd/run.go index 8fa81f39..430f2026 100644 --- a/src/cmd/run.go +++ b/src/cmd/run.go @@ -25,7 +25,7 @@ var runCmd = &cobra.Command{ Use: "run [ TASK NAME ]", Short: "run a task", Long: `run a task from an tasks file`, - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { var tasksFile types.TasksFile if _, err := os.Stat(config.TaskFileLocation); os.IsNotExist(err) { @@ -43,13 +43,13 @@ var runCmd = &cobra.Command{ } return taskNames, cobra.ShellCompDirectiveNoFileComp }, - Args: func(cmd *cobra.Command, args []string) error { + Args: func(_ *cobra.Command, args []string) error { if len(args) > 1 && !config.ListTasks { return fmt.Errorf("accepts 0 or 1 arg(s), received %d", len(args)) } return nil }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { var tasksFile types.TasksFile if _, err := os.Stat(config.TaskFileLocation); os.IsNotExist(err) { diff --git a/src/cmd/uds.go b/src/cmd/uds.go index b55b16db..e6630f08 100644 --- a/src/cmd/uds.go +++ b/src/cmd/uds.go @@ -95,12 +95,12 @@ var inspectCmd = &cobra.Command{ Aliases: []string{"i"}, Short: lang.CmdBundleInspectShort, Args: cobra.MaximumNArgs(1), - PreRun: func(cmd *cobra.Command, args []string) { + PreRun: func(cmd *cobra.Command, _ []string) { if cmd.Flag("extract").Value.String() == "true" && cmd.Flag("sbom").Value.String() == "false" { message.Fatal(nil, "cannot use 'extract' flag without 'sbom' flag") } }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { bundleCfg.InspectOpts.Source = chooseBundle(args) configureZarf() @@ -119,7 +119,7 @@ var removeCmd = &cobra.Command{ Aliases: []string{"r"}, Args: cobra.ExactArgs(1), Short: lang.CmdBundleRemoveShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { bundleCfg.RemoveOpts.Source = args[0] configureZarf() @@ -138,12 +138,12 @@ var publishCmd = &cobra.Command{ Aliases: []string{"p"}, Short: lang.CmdPublishShort, Args: cobra.ExactArgs(2), - PreRun: func(cmd *cobra.Command, args []string) { + PreRun: func(_ *cobra.Command, args []string) { if _, err := os.Stat(args[0]); err != nil { message.Fatalf(err, "First argument (%q) must be a valid local Bundle path: %s", args[0], err.Error()) } }, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { bundleCfg.PublishOpts.Source = args[0] bundleCfg.PublishOpts.Destination = args[1] configureZarf() @@ -162,7 +162,7 @@ var pullCmd = &cobra.Command{ Aliases: []string{"p"}, Short: lang.CmdBundlePullShort, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { bundleCfg.PullOpts.Source = args[0] configureZarf() bndlClient := bundle.NewOrDie(&bundleCfg) diff --git a/src/pkg/bundler/bundler.go b/src/pkg/bundler/bundler.go index 008af960..1ce7ae02 100644 --- a/src/pkg/bundler/bundler.go +++ b/src/pkg/bundler/bundler.go @@ -8,6 +8,7 @@ import ( "github.com/defenseunicorns/uds-cli/src/types" ) +// Bundler is used for bundling packages type Bundler struct { bundle *types.UDSBundle output string @@ -15,9 +16,11 @@ type Bundler struct { sourceDir string } +// Pusher is the interface for pushing bundles type Pusher interface { } +// Options are the options for creating a bundler type Options struct { Bundle *types.UDSBundle Output string @@ -25,6 +28,7 @@ type Options struct { SourceDir string } +// NewBundler creates a new bundler func NewBundler(opts *Options) *Bundler { b := Bundler{ bundle: opts.Bundle, @@ -35,6 +39,7 @@ func NewBundler(opts *Options) *Bundler { return &b } +// Create creates a bundle func (b *Bundler) Create() error { if b.output == "" { localBundle := NewLocalBundle(&LocalBundleOpts{Bundle: b.bundle, TmpDstDir: b.tmpDstDir, SourceDir: b.sourceDir}) diff --git a/src/pkg/bundler/fetcher/fetcher.go b/src/pkg/bundler/fetcher/fetcher.go index e454e325..2d68e2cb 100644 --- a/src/pkg/bundler/fetcher/fetcher.go +++ b/src/pkg/bundler/fetcher/fetcher.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023-Present The UDS Authors -// Package fetcher contains functionality to fetch local and remote Zarf pkgs for bundling +// Package fetcher contains functionality to fetch local and remote Zarf pkgs for local bundling package fetcher import ( @@ -17,11 +17,13 @@ import ( ocistore "oras.land/oras-go/v2/content/oci" ) +// Fetcher is the interface for fetching packages type Fetcher interface { Fetch() ([]ocispec.Descriptor, error) GetPkgMetadata() (zarfTypes.ZarfPackage, error) } +// Config is the configuration for the fetcher type Config struct { Store *ocistore.Store TmpDstDir string diff --git a/src/pkg/bundler/fetcher/local.go b/src/pkg/bundler/fetcher/local.go index 399e4b69..aa19a9d0 100644 --- a/src/pkg/bundler/fetcher/local.go +++ b/src/pkg/bundler/fetcher/local.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023-Present The UDS Authors -// Package fetcher contains functionality to fetch local and remote Zarf pkgs for bundling +// Package fetcher contains functionality to fetch local and remote Zarf pkgs for local bundling package fetcher import ( @@ -109,7 +109,7 @@ func (f *localFetcher) GetPkgMetadata() (zarfTypes.ZarfPackage, error) { return zarfYAML, err } -// Extract extracts a compressed Zarf archive into a directory +// extract extracts a compressed Zarf archive into a directory func (f *localFetcher) extract() error { err := av3.Unarchive(f.pkg.Path, f.extractDst) // todo: awkward to use old version of mholt/archiver if err != nil { @@ -118,7 +118,7 @@ func (f *localFetcher) extract() error { return nil } -// Load loads a zarf.yaml into a Zarf object +// load loads a zarf.yaml into a Zarf object func (f *localFetcher) load() (zarfTypes.ZarfPackage, error) { // grab zarf.yaml from extracted archive p, err := os.ReadFile(filepath.Join(f.extractDst, config.ZarfYAML)) diff --git a/src/pkg/bundler/fetcher/remote.go b/src/pkg/bundler/fetcher/remote.go index edf31ed0..ab11ec10 100644 --- a/src/pkg/bundler/fetcher/remote.go +++ b/src/pkg/bundler/fetcher/remote.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: 2023-Present The UDS Authors -// Package fetcher contains functionality to fetch local and remote Zarf pkgs for bundling +// Package fetcher contains functionality to fetch local and remote Zarf pkgs for local bundling package fetcher import ( @@ -33,6 +33,7 @@ type remoteFetcher struct { remote *oci.OrasRemote } +// Fetch fetches a Zarf pkg and puts it into a local bundle func (f *remoteFetcher) Fetch() ([]ocispec.Descriptor, error) { fetchSpinner := message.NewProgressSpinner("Fetching package %s", f.pkg.Name) zarfPackageName := "" diff --git a/src/pkg/bundler/localbundle.go b/src/pkg/bundler/localbundle.go index 8399a210..e02abe63 100644 --- a/src/pkg/bundler/localbundle.go +++ b/src/pkg/bundler/localbundle.go @@ -26,18 +26,21 @@ import ( ocistore "oras.land/oras-go/v2/content/oci" ) +// LocalBundleOpts are the options for creating a local bundle type LocalBundleOpts struct { Bundle *types.UDSBundle TmpDstDir string SourceDir string } +// LocalBundle enables create ops with local bundles type LocalBundle struct { bundle *types.UDSBundle tmpDstDir string sourceDir string } +// NewLocalBundle creates a new local bundle func NewLocalBundle(opts *LocalBundleOpts) *LocalBundle { return &LocalBundle{ bundle: opts.Bundle, diff --git a/src/pkg/bundler/remotebundle.go b/src/pkg/bundler/remotebundle.go index 6c779588..4df60590 100644 --- a/src/pkg/bundler/remotebundle.go +++ b/src/pkg/bundler/remotebundle.go @@ -17,18 +17,21 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) +// RemoteBundleOpts are the options for creating a remote bundle type RemoteBundleOpts struct { Bundle *types.UDSBundle TmpDstDir string Output string } +// RemoteBundle enables create ops with remote bundles type RemoteBundle struct { bundle *types.UDSBundle tmpDstDir string output string } +// NewRemoteBundle creates a new remote bundle func NewRemoteBundle(opts *RemoteBundleOpts) *RemoteBundle { return &RemoteBundle{ bundle: opts.Bundle, @@ -71,8 +74,8 @@ func (r *RemoteBundle) create(signature []byte) error { for i, pkg := range bundle.Packages { // todo: can leave this block here or move to pusher.NewPkgPusher (would be closer to NewPkgFetcher pattern) - pkgUrl := fmt.Sprintf("%s:%s", pkg.Repository, pkg.Ref) - src, err := oci.NewOrasRemote(pkgUrl, platform) + pkgURL := fmt.Sprintf("%s:%s", pkg.Repository, pkg.Ref) + src, err := oci.NewOrasRemote(pkgURL, platform) if err != nil { return err } diff --git a/src/pkg/utils/sbom.go b/src/pkg/utils/sbom.go index 3836fee8..151b5af5 100644 --- a/src/pkg/utils/sbom.go +++ b/src/pkg/utils/sbom.go @@ -44,8 +44,8 @@ func MoveExtractedSBOMs(src, dst string) error { } // SBOMExtractor is the extraction fn for extracting HTML and JSON files from an sboms.tar archive -func SBOMExtractor(dst string, SBOMArtifactPathMap map[string]string) func(ctx context.Context, f archiver.File) error { - extractor := func(ctx context.Context, f archiver.File) error { +func SBOMExtractor(dst string, SBOMArtifactPathMap map[string]string) func(_ context.Context, f archiver.File) error { + extractor := func(_ context.Context, f archiver.File) error { open, err := f.Open() if err != nil { return err