From 5e1c6dfd04563d1b62cd451620a1404ceb792fc3 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 13:25:49 -0700 Subject: [PATCH 1/2] chore: hotfix fix codeql issues across Zarf (#2322) ## Description This fixes the codeql issues that are currently in the Zarf codebase ## Related Issue Fixes #N/A ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [X] Other (security config, docs update, etc) ## Checklist before merging - [X] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --- src/cmd/connect.go | 4 ++-- src/cmd/destroy.go | 2 +- src/cmd/dev.go | 12 ++++++------ src/cmd/initialize.go | 2 +- src/cmd/internal.go | 20 ++++++++++---------- src/cmd/package.go | 16 ++++++++-------- src/cmd/root.go | 2 +- src/cmd/tools/archiver.go | 4 ++-- src/cmd/tools/common.go | 2 +- src/cmd/tools/crane.go | 2 +- src/cmd/tools/helm/dependency.go | 2 +- src/cmd/tools/helm/dependency_build.go | 2 +- src/cmd/tools/helm/dependency_update.go | 2 +- src/cmd/tools/helm/flags.go | 2 +- src/cmd/tools/helm/load_plugins.go | 2 +- src/cmd/tools/helm/repo_add.go | 2 +- src/cmd/tools/helm/repo_index.go | 4 ++-- src/cmd/tools/helm/repo_list.go | 2 +- src/cmd/tools/helm/repo_remove.go | 4 ++-- src/cmd/tools/helm/repo_update.go | 4 ++-- src/cmd/tools/helm/root.go | 4 ++-- src/cmd/tools/k9s.go | 2 +- src/cmd/tools/kubectl.go | 2 +- src/cmd/tools/wait.go | 2 +- src/cmd/tools/zarf.go | 12 ++++++------ src/cmd/version.go | 4 ++-- src/internal/agent/http/proxy.go | 2 +- src/internal/agent/http/server.go | 2 +- src/internal/packager/images/pull.go | 2 +- src/pkg/k8s/common.go | 2 +- src/pkg/packager/common_test.go | 2 +- src/pkg/packager/sources/validate.go | 2 +- src/pkg/transform/git_test.go | 2 +- 33 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/cmd/connect.go b/src/cmd/connect.go index 73fab7665a..fe3442e395 100644 --- a/src/cmd/connect.go +++ b/src/cmd/connect.go @@ -31,7 +31,7 @@ var ( Aliases: []string{"c"}, Short: lang.CmdConnectShort, Long: lang.CmdConnectLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { var target string if len(args) > 0 { target = args[0] @@ -89,7 +89,7 @@ var ( Use: "list", Aliases: []string{"l"}, Short: lang.CmdConnectListShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { cluster.NewClusterOrDie().PrintConnectTable() }, } diff --git a/src/cmd/destroy.go b/src/cmd/destroy.go index be3ffbe2a9..0a60d05503 100644 --- a/src/cmd/destroy.go +++ b/src/cmd/destroy.go @@ -28,7 +28,7 @@ var destroyCmd = &cobra.Command{ Aliases: []string{"d"}, Short: lang.CmdDestroyShort, Long: lang.CmdDestroyLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { c, err := cluster.NewClusterWithWait(cluster.DefaultTimeout) if err != nil { message.Fatalf(err, lang.ErrNoClusterConnection) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 63426692ea..bccac8b781 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -39,7 +39,7 @@ var devDeployCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevDeployShort, Long: lang.CmdDevDeployLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { common.SetBaseDirectory(args, &pkgConfig) v := common.GetViper() @@ -65,7 +65,7 @@ var devTransformGitLinksCmd = &cobra.Command{ Aliases: []string{"p"}, Short: lang.CmdDevPatchGitShort, Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { host, fileName := args[0], args[1] // Read the contents of the given file @@ -108,7 +108,7 @@ var devSha256SumCmd = &cobra.Command{ Aliases: []string{"s"}, Short: lang.CmdDevSha256sumShort, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { fileName := args[0] var tmp string @@ -184,7 +184,7 @@ var devFindImagesCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevFindImagesShort, Long: lang.CmdDevFindImagesLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { // If a directory was provided, use that as the base directory common.SetBaseDirectory(args, &pkgConfig) @@ -210,7 +210,7 @@ var devGenConfigFileCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevGenerateConfigShort, Long: lang.CmdDevGenerateConfigLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { fileName := "zarf-config.toml" // If a filename was provided, use that @@ -231,7 +231,7 @@ var devLintCmd = &cobra.Command{ Aliases: []string{"l"}, Short: lang.CmdDevLintShort, Long: lang.CmdDevLintLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { common.SetBaseDirectory(args, &pkgConfig) v := common.GetViper() pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap( diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 192fb961e0..906f484720 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -33,7 +33,7 @@ var initCmd = &cobra.Command{ Short: lang.CmdInitShort, Long: lang.CmdInitLong, Example: lang.CmdInitExample, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { zarfLogo := message.GetLogo() _, _ = fmt.Fprintln(os.Stderr, zarfLogo) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index a10067398c..68e512d1c6 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -37,7 +37,7 @@ var agentCmd = &cobra.Command{ Use: "agent", Short: lang.CmdInternalAgentShort, Long: lang.CmdInternalAgentLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { agent.StartWebhook() }, } @@ -46,7 +46,7 @@ var httpProxyCmd = &cobra.Command{ Use: "http-proxy", Short: lang.CmdInternalProxyShort, Long: lang.CmdInternalProxyLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { agent.StartHTTPProxy() }, } @@ -54,7 +54,7 @@ var httpProxyCmd = &cobra.Command{ var genCLIDocs = &cobra.Command{ Use: "gen-cli-docs", Short: lang.CmdInternalGenerateCliDocsShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Don't include the datestamp in the output rootCmd.DisableAutoGenTag = true @@ -126,7 +126,7 @@ var genConfigSchemaCmd = &cobra.Command{ Use: "gen-config-schema", Aliases: []string{"gc"}, Short: lang.CmdInternalConfigSchemaShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { schema := jsonschema.Reflect(&types.ZarfPackage{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { @@ -146,7 +146,7 @@ var genTypesSchemaCmd = &cobra.Command{ Use: "gen-types-schema", Aliases: []string{"gt"}, Short: lang.CmdInternalTypesSchemaShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { schema := jsonschema.Reflect(&zarfTypes{}) output, err := json.MarshalIndent(schema, "", " ") if err != nil { @@ -160,7 +160,7 @@ var createReadOnlyGiteaUser = &cobra.Command{ Use: "create-read-only-gitea-user", Short: lang.CmdInternalCreateReadOnlyGiteaUserShort, Long: lang.CmdInternalCreateReadOnlyGiteaUserLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Load the state so we can get the credentials for the admin git user state, err := cluster.NewClusterOrDie().LoadZarfState() if err != nil { @@ -178,7 +178,7 @@ var createPackageRegistryToken = &cobra.Command{ Use: "create-artifact-registry-token", Short: lang.CmdInternalArtifactRegistryGiteaTokenShort, Long: lang.CmdInternalArtifactRegistryGiteaTokenLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Load the state so we can get the credentials for the admin git user c := cluster.NewClusterOrDie() state, err := c.LoadZarfState() @@ -204,7 +204,7 @@ var updateGiteaPVC = &cobra.Command{ Use: "update-gitea-pvc", Short: lang.CmdInternalUpdateGiteaPVCShort, Long: lang.CmdInternalUpdateGiteaPVCLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // There is a possibility that the pvc does not yet exist and Gitea helm chart should create it helmShouldCreate, err := git.UpdateGiteaPVC(rollback) @@ -219,7 +219,7 @@ var updateGiteaPVC = &cobra.Command{ var isValidHostname = &cobra.Command{ Use: "is-valid-hostname", Short: lang.CmdInternalIsValidHostnameShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { if valid := helpers.IsValidHostName(); !valid { hostname, _ := os.Hostname() message.Fatalf(nil, lang.CmdInternalIsValidHostnameErr, hostname) @@ -232,7 +232,7 @@ var computeCrc32 = &cobra.Command{ Aliases: []string{"c"}, Short: lang.CmdInternalCrc32Short, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { text := args[0] hash := helpers.GetCRCHash(text) fmt.Printf("%d\n", hash) diff --git a/src/cmd/package.go b/src/cmd/package.go index 1ccd3e3061..3e29b74b64 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -39,7 +39,7 @@ var packageCreateCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdPackageCreateShort, Long: lang.CmdPackageCreateLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { common.SetBaseDirectory(args, &pkgConfig) var isCleanPathRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-\/\.\~\\:]+$`) @@ -70,7 +70,7 @@ var packageDeployCmd = &cobra.Command{ Short: lang.CmdPackageDeployShort, Long: lang.CmdPackageDeployLong, Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = choosePackage(args) // Ensure uppercase keys from viper and CLI --set @@ -98,7 +98,7 @@ var packageMirrorCmd = &cobra.Command{ Long: lang.CmdPackageMirrorLong, Example: lang.CmdPackageMirrorExample, Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = choosePackage(args) // Configure the packager @@ -118,7 +118,7 @@ var packageInspectCmd = &cobra.Command{ Short: lang.CmdPackageInspectShort, Long: lang.CmdPackageInspectLong, Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = choosePackage(args) src := identifyAndFallbackToClusterSource() @@ -139,7 +139,7 @@ var packageListCmd = &cobra.Command{ Use: "list", Aliases: []string{"l", "ls"}, Short: lang.CmdPackageListShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Get all the deployed packages deployedZarfPackages, errs := cluster.NewClusterOrDie().GetDeployedZarfPackages() if len(errs) > 0 && len(deployedZarfPackages) == 0 { @@ -177,7 +177,7 @@ var packageRemoveCmd = &cobra.Command{ Aliases: []string{"u", "rm"}, Args: cobra.MaximumNArgs(1), Short: lang.CmdPackageRemoveShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = choosePackage(args) src := identifyAndFallbackToClusterSource() @@ -197,7 +197,7 @@ var packagePublishCmd = &cobra.Command{ Short: lang.CmdPackagePublishShort, Example: lang.CmdPackagePublishExample, Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = args[0] if !helpers.IsOCIURL(args[1]) { @@ -236,7 +236,7 @@ var packagePullCmd = &cobra.Command{ Short: lang.CmdPackagePullShort, Example: lang.CmdPackagePullExample, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pkgConfig.PkgOpts.PackageSource = args[0] // Configure the packager diff --git a/src/cmd/root.go b/src/cmd/root.go index 3d5660e8a2..9563f382d3 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -26,7 +26,7 @@ var ( var rootCmd = &cobra.Command{ Use: "zarf COMMAND", - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { // Skip for vendor-only commands if common.CheckVendorOnlyFromPath(cmd) { return diff --git a/src/cmd/tools/archiver.go b/src/cmd/tools/archiver.go index e392b8c3ad..b6110b7a18 100644 --- a/src/cmd/tools/archiver.go +++ b/src/cmd/tools/archiver.go @@ -28,7 +28,7 @@ var archiverCompressCmd = &cobra.Command{ Aliases: []string{"c"}, Short: lang.CmdToolsArchiverCompressShort, Args: cobra.MinimumNArgs(2), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { sourceFiles, destinationArchive := args[:len(args)-1], args[len(args)-1] err := archiver.Archive(sourceFiles, destinationArchive) if err != nil { @@ -44,7 +44,7 @@ var archiverDecompressCmd = &cobra.Command{ Aliases: []string{"d"}, Short: lang.CmdToolsArchiverDecompressShort, Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { sourceArchive, destinationPath := args[0], args[1] err := archiver.Unarchive(sourceArchive, destinationPath) if err != nil { diff --git a/src/cmd/tools/common.go b/src/cmd/tools/common.go index 81d33af4ec..d0fa000e86 100644 --- a/src/cmd/tools/common.go +++ b/src/cmd/tools/common.go @@ -14,7 +14,7 @@ import ( var toolsCmd = &cobra.Command{ Use: "tools", Aliases: []string{"t"}, - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { config.SkipLogFile = true // Skip for vendor-only commands diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index 80030fd361..6d0919067d 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -37,7 +37,7 @@ func init() { Use: "registry", Aliases: []string{"r", "crane"}, Short: lang.CmdToolsRegistryShort, - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(cmd *cobra.Command, _ []string) { exec.ExitOnInterrupt() diff --git a/src/cmd/tools/helm/dependency.go b/src/cmd/tools/helm/dependency.go index b96d1e39b2..4ab004b036 100644 --- a/src/cmd/tools/helm/dependency.go +++ b/src/cmd/tools/helm/dependency.go @@ -111,7 +111,7 @@ func newDependencyListCmd(out io.Writer) *cobra.Command { Short: "list the dependencies for the given chart", Long: dependencyListDesc, Args: require.MaximumNArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { chartpath := "." if len(args) > 0 { chartpath = filepath.Clean(args[0]) diff --git a/src/cmd/tools/helm/dependency_build.go b/src/cmd/tools/helm/dependency_build.go index 0e84e244bb..618c137174 100644 --- a/src/cmd/tools/helm/dependency_build.go +++ b/src/cmd/tools/helm/dependency_build.go @@ -54,7 +54,7 @@ func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Comm Short: "rebuild the charts/ directory based on the Chart.lock file", Long: dependencyBuildDesc, Args: require.MaximumNArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { chartpath := "." if len(args) > 0 { chartpath = filepath.Clean(args[0]) diff --git a/src/cmd/tools/helm/dependency_update.go b/src/cmd/tools/helm/dependency_update.go index 86c9f48de3..f069b7f59d 100644 --- a/src/cmd/tools/helm/dependency_update.go +++ b/src/cmd/tools/helm/dependency_update.go @@ -57,7 +57,7 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com Short: "update charts/ based on the contents of Chart.yaml", Long: dependencyUpDesc, Args: require.MaximumNArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { chartpath := "." if len(args) > 0 { chartpath = filepath.Clean(args[0]) diff --git a/src/cmd/tools/helm/flags.go b/src/cmd/tools/helm/flags.go index d567d920ec..d0130a6fb1 100644 --- a/src/cmd/tools/helm/flags.go +++ b/src/cmd/tools/helm/flags.go @@ -44,7 +44,7 @@ func bindOutputFlag(cmd *cobra.Command, varRef *output.Format) { cmd.Flags().VarP(newOutputValue(output.Table, varRef), outputFlag, "o", fmt.Sprintf("prints the output in the specified format. Allowed values: %s", strings.Join(output.Formats(), ", "))) - err := cmd.RegisterFlagCompletionFunc(outputFlag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + err := cmd.RegisterFlagCompletionFunc(outputFlag, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { var formatNames []string for format, desc := range output.FormatsWithDesc() { formatNames = append(formatNames, fmt.Sprintf("%s\t%s", format, desc)) diff --git a/src/cmd/tools/helm/load_plugins.go b/src/cmd/tools/helm/load_plugins.go index 6890f52edc..39edb9c3d9 100644 --- a/src/cmd/tools/helm/load_plugins.go +++ b/src/cmd/tools/helm/load_plugins.go @@ -305,7 +305,7 @@ func addPluginCommands(plugin *plugin.Plugin, baseCmd *cobra.Command, cmds *plug // to the dynamic completion script of the plugin. DisableFlagParsing: true, // A Run is required for it to be a valid command without subcommands - Run: func(cmd *cobra.Command, args []string) {}, + Run: func(_ *cobra.Command, _ []string) {}, } baseCmd.AddCommand(subCmd) addPluginCommands(plugin, subCmd, &cmd) diff --git a/src/cmd/tools/helm/repo_add.go b/src/cmd/tools/helm/repo_add.go index ce2e236267..d167adc3fc 100644 --- a/src/cmd/tools/helm/repo_add.go +++ b/src/cmd/tools/helm/repo_add.go @@ -76,7 +76,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command { Use: "add [NAME] [URL]", Short: "add a chart repository", Args: require.ExactArgs(2), - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.name = args[0] o.url = args[1] o.repoFile = settings.RepositoryConfig diff --git a/src/cmd/tools/helm/repo_index.go b/src/cmd/tools/helm/repo_index.go index 79f941e79a..1770cedcf9 100644 --- a/src/cmd/tools/helm/repo_index.go +++ b/src/cmd/tools/helm/repo_index.go @@ -58,7 +58,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { Short: "generate an index file given a directory containing packaged charts", Long: repoIndexDesc, Args: require.ExactArgs(1), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { // Allow file completion when completing the argument for the directory return nil, cobra.ShellCompDirectiveDefault @@ -66,7 +66,7 @@ func newRepoIndexCmd(out io.Writer) *cobra.Command { // No more completions, so disable file completion return nil, cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.dir = args[0] return o.run(out) }, diff --git a/src/cmd/tools/helm/repo_list.go b/src/cmd/tools/helm/repo_list.go index 02b4e34d86..7bf65bc95f 100644 --- a/src/cmd/tools/helm/repo_list.go +++ b/src/cmd/tools/helm/repo_list.go @@ -41,7 +41,7 @@ func newRepoListCmd(out io.Writer) *cobra.Command { Aliases: []string{"ls"}, Short: "list chart repositories", Args: require.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { f, _ := repo.LoadFile(settings.RepositoryConfig) if len(f.Repositories) == 0 && !(outfmt == output.JSON || outfmt == output.YAML) { return errors.New("no repositories to show") diff --git a/src/cmd/tools/helm/repo_remove.go b/src/cmd/tools/helm/repo_remove.go index 61340f8a49..13110072cd 100644 --- a/src/cmd/tools/helm/repo_remove.go +++ b/src/cmd/tools/helm/repo_remove.go @@ -49,10 +49,10 @@ func newRepoRemoveCmd(out io.Writer) *cobra.Command { Aliases: []string{"rm"}, Short: "remove one or more chart repositories", Args: require.MinimumNArgs(1), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return compListRepos(toComplete, args), cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.repoFile = settings.RepositoryConfig o.repoCache = settings.RepositoryCache o.names = args diff --git a/src/cmd/tools/helm/repo_update.go b/src/cmd/tools/helm/repo_update.go index c74d1eae75..92f82e261e 100644 --- a/src/cmd/tools/helm/repo_update.go +++ b/src/cmd/tools/helm/repo_update.go @@ -62,10 +62,10 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command { Short: "update information of available charts locally from chart repositories", Long: updateDesc, Args: require.MinimumNArgs(0), - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return compListRepos(toComplete, args), cobra.ShellCompDirectiveNoFileComp }, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, args []string) error { o.repoFile = settings.RepositoryConfig o.repoCache = settings.RepositoryCache o.names = args diff --git a/src/cmd/tools/helm/root.go b/src/cmd/tools/helm/root.go index 63b9bf8f17..e496a93cec 100644 --- a/src/cmd/tools/helm/root.go +++ b/src/cmd/tools/helm/root.go @@ -105,7 +105,7 @@ func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string addKlogFlags(flags) // Setup shell completion for the namespace flag - err := cmd.RegisterFlagCompletionFunc("namespace", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + err := cmd.RegisterFlagCompletionFunc("namespace", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { if client, err := actionConfig.KubernetesClientSet(); err == nil { // Choose a long enough timeout that the user notices something is not working // but short enough that the user is not made to wait very long @@ -128,7 +128,7 @@ func NewRootCmd(actionConfig *action.Configuration, out io.Writer, args []string } // Setup shell completion for the kube-context flag - err = cmd.RegisterFlagCompletionFunc("kube-context", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + err = cmd.RegisterFlagCompletionFunc("kube-context", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { cobra.CompDebugln("About to get the different kube-contexts", settings.Debug) loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() diff --git a/src/cmd/tools/k9s.go b/src/cmd/tools/k9s.go index d38992ead9..ceabe6a547 100644 --- a/src/cmd/tools/k9s.go +++ b/src/cmd/tools/k9s.go @@ -23,7 +23,7 @@ func init() { Use: "monitor", Aliases: []string{"m", "k9s"}, Short: lang.CmdToolsMonitorShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Hack to make k9s think it's all alone os.Args = []string{os.Args[0]} k9s.Execute() diff --git a/src/cmd/tools/kubectl.go b/src/cmd/tools/kubectl.go index ab9f16e920..e9eb820ff5 100644 --- a/src/cmd/tools/kubectl.go +++ b/src/cmd/tools/kubectl.go @@ -22,7 +22,7 @@ func init() { // Kubectl stub command. kubectlCmd := &cobra.Command{ Short: lang.CmdToolsKubectlDocs, - Run: func(cmd *cobra.Command, args []string) {}, + Run: func(_ *cobra.Command, _ []string) {}, } // Only load this command if it is being called directly. diff --git a/src/cmd/tools/wait.go b/src/cmd/tools/wait.go index 183fd226e8..9977c58011 100644 --- a/src/cmd/tools/wait.go +++ b/src/cmd/tools/wait.go @@ -28,7 +28,7 @@ var waitForCmd = &cobra.Command{ Long: lang.CmdToolsWaitForLong, Example: lang.CmdToolsWaitForExample, Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { // Parse the timeout string timeout, err := time.ParseDuration(waitTimeout) if err != nil { diff --git a/src/cmd/tools/zarf.go b/src/cmd/tools/zarf.go index 27cc36da6a..f0820962f8 100644 --- a/src/cmd/tools/zarf.go +++ b/src/cmd/tools/zarf.go @@ -35,7 +35,7 @@ var deprecatedGetGitCredsCmd = &cobra.Command{ Hidden: true, Short: lang.CmdToolsGetGitPasswdShort, Long: lang.CmdToolsGetGitPasswdLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { message.Warn(lang.CmdToolsGetGitPasswdDeprecation) getCredsCmd.Run(getCredsCmd, []string{"git"}) }, @@ -48,7 +48,7 @@ var getCredsCmd = &cobra.Command{ Example: lang.CmdToolsGetCredsExample, Aliases: []string{"gc"}, Args: cobra.MaximumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { state, err := cluster.NewClusterOrDie().LoadZarfState() if err != nil || state.Distro == "" { // If no distro the zarf secret did not load properly @@ -168,7 +168,7 @@ var clearCacheCmd = &cobra.Command{ Use: "clear-cache", Aliases: []string{"c"}, Short: lang.CmdToolsClearCacheShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { message.Notef(lang.CmdToolsClearCacheDir, config.GetAbsCachePath()) if err := os.RemoveAll(config.GetAbsCachePath()); err != nil { message.Fatalf(err, lang.CmdToolsClearCacheErr, config.GetAbsCachePath()) @@ -180,7 +180,7 @@ var clearCacheCmd = &cobra.Command{ var downloadInitCmd = &cobra.Command{ Use: "download-init", Short: lang.CmdToolsDownloadInitShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { url := oci.GetInitPackageURL(config.CLIVersion) remote, err := oci.NewOrasRemote(url, oci.PlatformForArch(config.GetArch())) @@ -202,7 +202,7 @@ var generatePKICmd = &cobra.Command{ Aliases: []string{"pki"}, Short: lang.CmdToolsGenPkiShort, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { pki := pki.GeneratePKI(args[0], subAltNames...) if err := os.WriteFile("tls.ca", pki.CA, 0644); err != nil { message.Fatalf(err, lang.ErrWritingFile, "tls.ca", err.Error()) @@ -221,7 +221,7 @@ var generateKeyCmd = &cobra.Command{ Use: "gen-key", Aliases: []string{"key"}, Short: lang.CmdToolsGenKeyShort, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { // Utility function to prompt the user for the password to the private key passwordFunc := func(bool) ([]byte, error) { // perform the first prompt diff --git a/src/cmd/version.go b/src/cmd/version.go index 18984a6e82..1daa7af61f 100644 --- a/src/cmd/version.go +++ b/src/cmd/version.go @@ -24,12 +24,12 @@ var outputFormat string var versionCmd = &cobra.Command{ Use: "version", Aliases: []string{"v"}, - PersistentPreRun: func(cmd *cobra.Command, args []string) { + PersistentPreRun: func(_ *cobra.Command, _ []string) { config.SkipLogFile = true }, Short: lang.CmdVersionShort, Long: lang.CmdVersionLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { output := make(map[string]interface{}) buildInfo, ok := debug.ReadBuildInfo() diff --git a/src/internal/agent/http/proxy.go b/src/internal/agent/http/proxy.go index b805d53564..ea0a54f024 100644 --- a/src/internal/agent/http/proxy.go +++ b/src/internal/agent/http/proxy.go @@ -30,7 +30,7 @@ func ProxyHandler() http.HandlerFunc { return } - proxy := &httputil.ReverseProxy{Director: func(r *http.Request) {}, ModifyResponse: proxyResponseTransform} + proxy := &httputil.ReverseProxy{Director: func(_ *http.Request) {}, ModifyResponse: proxyResponseTransform} proxy.ServeHTTP(w, r) } } diff --git a/src/internal/agent/http/server.go b/src/internal/agent/http/server.go index aa86133d85..4087308d3a 100644 --- a/src/internal/agent/http/server.go +++ b/src/internal/agent/http/server.go @@ -55,7 +55,7 @@ func NewProxyServer(port string) *http.Server { } func healthz() http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("ok")) } diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 160c0d506a..92ed0d5775 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -379,7 +379,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) { }() } - onImageSavingProgress := func(finishedImage digestInfo, iteration int) { + onImageSavingProgress := func(finishedImage digestInfo, _ int) { referenceToDigest[finishedImage.refInfo.Reference] = finishedImage.digest } diff --git a/src/pkg/k8s/common.go b/src/pkg/k8s/common.go index bb678050e4..d11be666d2 100644 --- a/src/pkg/k8s/common.go +++ b/src/pkg/k8s/common.go @@ -22,7 +22,7 @@ import ( // New creates a new K8s client. func New(logger Log, defaultLabels Labels) (*K8s, error) { - klog.SetLogger(funcr.New(func(prefix, args string) { + klog.SetLogger(funcr.New(func(_, args string) { logger(args) }, funcr.Options{})) diff --git a/src/pkg/packager/common_test.go b/src/pkg/packager/common_test.go index 690837f6c3..105daf0242 100644 --- a/src/pkg/packager/common_test.go +++ b/src/pkg/packager/common_test.go @@ -104,7 +104,7 @@ func TestValidatePackageArchitecture(t *testing.T) { } // Set up test data for fetching cluster architecture. - mockClient.Fake.PrependReactor("list", "nodes", func(action k8sTesting.Action) (handled bool, ret runtime.Object, err error) { + mockClient.Fake.PrependReactor("list", "nodes", func(_ k8sTesting.Action) (bool, runtime.Object, error) { // Return an error for cases that test this error path. if testCase.getArchError != nil { return true, nil, testCase.getArchError diff --git a/src/pkg/packager/sources/validate.go b/src/pkg/packager/sources/validate.go index 2e06f85056..38e4581b0a 100644 --- a/src/pkg/packager/sources/validate.go +++ b/src/pkg/packager/sources/validate.go @@ -157,7 +157,7 @@ func pathCheckMap(dir string) (map[string]bool, error) { return nil } filepathMap[path] = false - return nil + return err }) return filepathMap, err } diff --git a/src/pkg/transform/git_test.go b/src/pkg/transform/git_test.go index 0bee04260d..70145275aa 100644 --- a/src/pkg/transform/git_test.go +++ b/src/pkg/transform/git_test.go @@ -44,7 +44,7 @@ var badGitURLs = []string{ } func TestMutateGitURLsInText(t *testing.T) { - dummyLogger := func(content string, args ...any) {} + dummyLogger := func(_ string, _ ...any) {} originalText := ` # Here we handle invalid URLs (see below comment) # We transform https://*/*.git URLs From 714f7c017bc13985f294ade45d47daca0137306c Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Wed, 21 Feb 2024 14:20:30 -0700 Subject: [PATCH 2/2] feat: improve `zarf tools registry prune` messaging (#2323) ## Description This PR fixes the `zarf tools registry prune` messaging to be more verbose. ## Related Issue Fixes #N/A ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [X] Other (security config, docs update, etc) ## Checklist before merging - [X] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --- src/cmd/tools/crane.go | 14 ++++++++++++++ src/config/lang/english.go | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index 6d0919067d..c0a521c153 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -246,6 +246,9 @@ func pruneImages(_ *cobra.Command, _ []string) error { func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.DeployedPackage, registryEndpoint string) error { authOption := config.GetCraneAuthOption(zarfState.RegistryInfo.PushUsername, zarfState.RegistryInfo.PushPassword) + spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneLookup) + defer spinner.Stop() + // Determine which image digests are currently used by Zarf packages pkgImages := map[string]bool{} for _, pkg := range zarfPackages { @@ -273,6 +276,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Updatef(lang.CmdToolsRegistryPruneCatalog) + // Find which images and tags are in the registry currently imageCatalog, err := crane.Catalog(registryEndpoint, authOption) if err != nil { @@ -295,6 +300,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Updatef(lang.CmdToolsRegistryPruneCalculate) + // Figure out which images are in the registry but not needed by packages imageDigestsToPrune := map[string]bool{} for digestRef, digest := range referenceToDigest { @@ -308,6 +315,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } + spinner.Success() + if len(imageDigestsToPrune) > 0 { message.Note(lang.CmdToolsRegistryPruneImageList) @@ -328,6 +337,9 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D } } if confirm { + spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneDelete) + defer spinner.Stop() + // Delete the digest references that are to be pruned for digestRef := range imageDigestsToPrune { err = crane.Delete(digestRef, authOption) @@ -335,6 +347,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D return err } } + + spinner.Success() } } else { message.Note(lang.CmdToolsRegistryPruneNoImages) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 6a666474d7..14e3b19887 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -455,6 +455,10 @@ $ zarf tools registry digest reg.example.com/stefanprodan/podinfo:6.4.0 CmdToolsRegistryPruneFlagConfirm = "Confirm the image prune action to prevent accidental deletions" CmdToolsRegistryPruneImageList = "The following image digests will be pruned from the registry:" CmdToolsRegistryPruneNoImages = "There are no images to prune" + CmdToolsRegistryPruneLookup = "Looking up images within package definitions" + CmdToolsRegistryPruneCatalog = "Cataloging images in the registry" + CmdToolsRegistryPruneCalculate = "Calculating images to prune" + CmdToolsRegistryPruneDelete = "Deleting unused images" CmdToolsRegistryInvalidPlatformErr = "Invalid platform '%s': %s" CmdToolsRegistryFlagVerbose = "Enable debug logs"