Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: addresses github linter findings #447

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@ import (
"github.com/defenseunicorns/uds-cli/src/types"
)

// Bundler is used for bundling packages
type Bundler struct {
bundle *types.UDSBundle
output string
tmpDstDir string
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
TmpDstDir string
SourceDir string
}

// NewBundler creates a new bundler
func NewBundler(opts *Options) *Bundler {
b := Bundler{
bundle: opts.Bundle,
Expand All @@ -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})
Expand Down
4 changes: 3 additions & 1 deletion src/pkg/bundler/fetcher/fetcher.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/bundler/fetcher/local.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion src/pkg/bundler/fetcher/remote.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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 := ""
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/bundler/localbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions src/pkg/bundler/remotebundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/utils/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading