diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f58d5ce424..0d25a6ef19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,14 +23,13 @@ repos: rev: v0.4.0 hooks: - id: go-fmt -# Commenting this one out for now since it fails ## Normally we wouldn't need to do a local hook but we need to modify the shell script that gets run to first change directories into the `cli` folder -# - repo: local -# hooks: -# - id: golangci-lint -# name: golangci-lint -# entry: hooks/run-golangci-lint.sh -# types: [ go ] -# language: script -# pass_filenames: false -# description: "Runs `golangci-lint`, requires https://github.com/golangci/golangci-lint" + - repo: local + hooks: + - id: golangci-lint + name: golangci-lint + entry: hooks/run-golangci-lint.sh + types: [ go ] + language: script + pass_filenames: false + description: "Runs `golangci-lint`, requires https://github.com/golangci/golangci-lint" diff --git a/cli/cmd/root.go b/cli/cmd/root.go index e6e2e73765..4edf70fbdb 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -34,7 +34,7 @@ var rootCmd = &cobra.Command{ return } } - cmd.Help() + _ = cmd.Help() }, } @@ -64,6 +64,6 @@ func setLogLevel(logLevel string) { case "panic": logrus.SetLevel(logrus.PanicLevel) default: - logrus.Fatal("Unrecognized log level entry: %s", logLevel) + logrus.Fatalf("Unrecognized log level entry: %s", logLevel) } } diff --git a/cli/internal/git/checkout.go b/cli/internal/git/checkout.go index 974a59421e..a1683fc9ac 100644 --- a/cli/internal/git/checkout.go +++ b/cli/internal/git/checkout.go @@ -59,25 +59,27 @@ func checkoutHashAsBranch(path string, hash plumbing.Hash, branch plumbing.Refer objRef, err := repo.Object(plumbing.AnyObject, hash) - var commitHash plumbing.Hash - switch objRef := objRef.(type) { - case *object.Tag: - commitHash = objRef.Target - case *object.Commit: - commitHash = objRef.Hash - default: - // This shouldn't ever hit, but we should at least log it if someday it - // does get hit - logContext.Debug("Unsupported tag hash type: " + objRef.Type().String()) - logContext.Fatal("Checkout failed. Hash type not supported.") - } + if err != nil { + var commitHash plumbing.Hash + switch objRef := objRef.(type) { + case *object.Tag: + commitHash = objRef.Target + case *object.Commit: + commitHash = objRef.Hash + default: + // This shouldn't ever hit, but we should at least log it if someday it + // does get hit + logContext.Debug("Unsupported tag hash type: " + objRef.Type().String()) + logContext.Fatal("Checkout failed. Hash type not supported.") + } - options := &git.CheckoutOptions{ - Hash: commitHash, - Branch: branch, - Create: true, + options := &git.CheckoutOptions{ + Hash: commitHash, + Branch: branch, + Create: true, + } + checkout(path, options) } - checkout(path, options) } // checkout performs a `git checkout` on the path provided using the options provided diff --git a/cli/internal/git/utils.go b/cli/internal/git/utils.go index 55dfbfef6e..bc7052f8f9 100644 --- a/cli/internal/git/utils.go +++ b/cli/internal/git/utils.go @@ -4,7 +4,6 @@ import ( "bufio" "net/url" "os" - "path" "regexp" "strings" @@ -48,11 +47,6 @@ func transformURL(baseUrl string, url string) string { return output } -func transformRepoDirToURL(baseUrl string, repoDir string) string { - baseDir := path.Base(repoDir) - return baseUrl + "/zarf-git-user/" + baseDir -} - func credentialFilePath() string { homePath, _ := os.UserHomeDir() return homePath + "/.git-credentials" diff --git a/cli/internal/helm/charts.go b/cli/internal/helm/charts.go index 03040158af..42b9e37afc 100644 --- a/cli/internal/helm/charts.go +++ b/cli/internal/helm/charts.go @@ -34,7 +34,12 @@ func DownloadChartFromGit(chart config.ZarfChart, destination string) { // Tell helm where to save the archive and create the package client.Destination = destination - client.Run(tempPath+"/chart", nil) + name, err := client.Run(tempPath+"/chart", nil) + + if err != nil { + logContext.Debug(err) + logContext.Fatal("Helm is unable to save the archive and create the package:", name) + } _ = os.RemoveAll(tempPath) } @@ -79,7 +84,12 @@ func DownloadPublishedChart(chart config.ZarfChart, destination string) { // Ensure the name is consistent for deployments destinationTarball := StandardName(destination, chart) - os.Rename(saved, destinationTarball) + err = os.Rename(saved, destinationTarball) + + if err != nil { + logContext.Debug(err) + logContext.Fatal("Unable to rename tarball") + } } // StandardName generates a predictable full path for a helm chart for Zarf diff --git a/cli/internal/packager/common.go b/cli/internal/packager/common.go index 4638572fc4..2b3e4b9836 100644 --- a/cli/internal/packager/common.go +++ b/cli/internal/packager/common.go @@ -144,7 +144,7 @@ func HandleIfURL(packagePath string, shasum string, insecureDeploy bool) string // Check the extension on the package is what we expect if !isValidFileExtension(providedURL.Path) { - logrus.Fatalf("Only %s file extensions are permitted.\n", config.GetValidPackageExtensions) + logrus.Fatalf("Only %s file extensions are permitted.\n", config.GetValidPackageExtensions()) } // Download the package diff --git a/cli/internal/packager/create.go b/cli/internal/packager/create.go index aa4c3aed86..5a4a2754b1 100644 --- a/cli/internal/packager/create.go +++ b/cli/internal/packager/create.go @@ -74,10 +74,11 @@ func Create(confirm bool) { func addLocalAssets(tempPath componentPaths, assets config.ZarfComponent) { if len(assets.Charts) > 0 { logrus.Info("Loading static helm charts") - utils.CreateDirectory(tempPath.charts, 0700) + _ = utils.CreateDirectory(tempPath.charts, 0700) + re := regexp.MustCompile(`\\.git$`) for _, chart := range assets.Charts { - isGitURL, _ := regexp.MatchString("\\.git$", chart.Url) - if isGitURL { + matched := re.MatchString(chart.Url) + if matched { helm.DownloadChartFromGit(chart, tempPath.charts) } else { helm.DownloadPublishedChart(chart, tempPath.charts) diff --git a/cli/internal/packager/inspect.go b/cli/internal/packager/inspect.go index 5071c4c051..f9bddbb71d 100644 --- a/cli/internal/packager/inspect.go +++ b/cli/internal/packager/inspect.go @@ -32,7 +32,11 @@ func Inspect(packageName string) { utils.ColorPrintYAML(text) // Load the config to get the build version - config.LoadConfig(tempPath.base + "/zarf.yaml") + if err := config.LoadConfig(tempPath.base + "/zarf.yaml"); err != nil { + logrus.Fatal(err) + logrus.Fatalf("Unable to read the zarf.yaml file from %s", tempPath.base) + } + fmt.Printf("The package was built with Zarf CLI version %s\n", config.GetBuildData().Version) cleanup(tempPath) diff --git a/cli/internal/pki/pki.go b/cli/internal/pki/pki.go index 566853db19..2f19680ad0 100644 --- a/cli/internal/pki/pki.go +++ b/cli/internal/pki/pki.go @@ -201,7 +201,10 @@ func generateFromTemplate(certFile, keyFile string, template, parent *x509.Certi if err != nil { return err } - pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) + err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}) + if err != nil { + return err + } certOut.Close() return savePrivateKey(key, keyFile) @@ -216,7 +219,10 @@ func savePrivateKey(key *rsa.PrivateKey, keyFile string) error { defer keyOut.Close() keyBytes := x509.MarshalPKCS1PrivateKey(key) - pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: keyBytes}) + err = pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: keyBytes}) + if err != nil { + return err + } return nil }