Skip to content

Commit

Permalink
updated golangci-lint and many cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: catsby <clint@defenseunicorns.com>
  • Loading branch information
catsby committed Dec 10, 2024
1 parent 17ea95b commit b0d1467
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func cliSetup(cmd *cobra.Command) error {
if !config.SkipLogFile && !config.ListTasks {
err := utils.ConfigureLogs(cmd)
if err != nil {
return fmt.Errorf(err.Error())
return err
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,16 @@ var logsCmd = &cobra.Command{
if err != nil {
var pathError *os.PathError
if errors.As(err, &pathError) {
msg := fmt.Sprintf("No cached logs found at %s", logFilePath)
return fmt.Errorf(msg)
return fmt.Errorf("no cached logs found at %s", logFilePath)
}
return fmt.Errorf("error opening log file: %s", err.Error())
return fmt.Errorf("error opening log file: %w", err)
}
defer logfile.Close()

// Copy the contents of the log file to stdout
if _, err := io.Copy(os.Stdout, logfile); err != nil {
// Handle the error if the contents can't be read or written to stdout
return fmt.Errorf("error reading or printing log file: %v", err.Error())
return fmt.Errorf("error reading or printing log file: %w", err)
}
return nil
},
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/vendored.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

runnerCLI "github.com/defenseunicorns/maru-runner/src/cmd"
runnerConfig "github.com/defenseunicorns/maru-runner/src/config"
"github.com/zarf-dev/zarf/src/pkg/message"

"github.com/defenseunicorns/pkg/exec"

"github.com/defenseunicorns/uds-cli/src/config"
Expand Down Expand Up @@ -57,7 +59,9 @@ var runnerCmd = &cobra.Command{
}

runnerCLI.RootCmd().SetArgs(os.Args)
runnerCLI.RootCmd().PersistentFlags().Set("log-level", "warn")
if err := runnerCLI.RootCmd().PersistentFlags().Set("log-level", "warn"); err != nil {
message.Warnf("unable to set log-level: %s", err)
}
runnerCLI.Execute()

return nil
Expand Down
6 changes: 3 additions & 3 deletions src/pkg/bundle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@ func (b *Bundle) setPackageRef(pkg types.Package) (types.Package, error) {
}
remote, err := zoci.NewRemote(ctx, url, platform)
if err != nil {
return pkg, fmt.Errorf(errMsg)
return pkg, errors.New(errMsg)
}
if err := remote.Repo().Reference.ValidateReferenceAsDigest(); err != nil {
manifestDesc, err := remote.ResolveRoot(ctx)
if err != nil {
return pkg, fmt.Errorf(errMsg)
return pkg, errors.New(errMsg)
}
pkg.Ref = ref + "@sha256:" + manifestDesc.Digest.Encoded()
} else {
return pkg, fmt.Errorf(errMsg)
return pkg, errors.New(errMsg)
}
}
return pkg, nil
Expand Down
4 changes: 3 additions & 1 deletion src/pkg/bundle/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (b *Bundle) Create() error {
// confirmBundleCreation prompts the user to confirm bundle creation
func (b *Bundle) confirmBundleCreation() (confirm bool) {
message.HeaderInfof("🎁 BUNDLE DEFINITION")
zarfUtils.ColorPrintYAML(b.bundle, nil, false)
if err := zarfUtils.ColorPrintYAML(b.bundle, nil, false); err != nil {
message.WarnErr(err, "unable to print yaml")
}

message.HorizontalRule()
pterm.Println()
Expand Down
17 changes: 12 additions & 5 deletions src/pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func deployPackages(packagesToDeploy []types.Package, b *Bundle) error {
pkgExportedVars[strings.ToUpper(exp.Name)] = setVariable.Value
}
bundleExportedVars[pkg.Name] = pkgExportedVars

}
return nil
}
Expand Down Expand Up @@ -289,20 +288,28 @@ func (b *Bundle) ConfirmBundleDeploy() (confirm bool) {
message.HeaderInfof("🎁 BUNDLE DEFINITION")

message.Title("Metadata:", "information about this bundle")
zarfUtils.ColorPrintYAML(b.bundle.Metadata, nil, false)
if err := zarfUtils.ColorPrintYAML(b.bundle.Metadata, nil, false); err != nil {
message.WarnErr(err, "unable to print bundle metadata yaml")
}

message.HorizontalRule()

message.Title("Build:", "info about the machine, UDS version, and the user that created this bundle")
zarfUtils.ColorPrintYAML(b.bundle.Build, nil, false)
if err := zarfUtils.ColorPrintYAML(b.bundle.Build, nil, false); err != nil {
message.WarnErr(err, "unable to print bundle build yaml")
}

message.HorizontalRule()

message.Title("Packages:", "definition of packages this bundle deploys, including variable overrides")

for _, pkg := range pkgviews {
zarfUtils.ColorPrintYAML(pkg.meta, nil, false)
zarfUtils.ColorPrintYAML(pkg.overrides, nil, false)
if err := zarfUtils.ColorPrintYAML(pkg.meta, nil, false); err != nil {
message.WarnErr(err, "unable to print package metadata yaml")
}
if err := zarfUtils.ColorPrintYAML(pkg.overrides, nil, false); err != nil {
message.WarnErr(err, "unable to print package overrides yaml")
}
}

message.HorizontalRule()
Expand Down
10 changes: 7 additions & 3 deletions src/pkg/bundle/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ func (b *Bundle) Inspect() error {
return nil
}

zarfUtils.ColorPrintYAML(b.bundle, nil, false)
if err := zarfUtils.ColorPrintYAML(b.bundle, nil, false); err != nil {
message.Warn("error printing bundle yaml")
}

// print warnings to stderr
pterm.SetDefaultOutput(os.Stderr)
for _, warn := range warns {
message.Warnf(warn)
message.Warn(warn)
}

return nil
Expand Down Expand Up @@ -167,7 +169,9 @@ func (b *Bundle) listVariables() error {
}

varMap := map[string]map[string]interface{}{pkg.Name: {"variables": variables}}
zarfUtils.ColorPrintYAML(varMap, nil, false)
if err := zarfUtils.ColorPrintYAML(varMap, nil, false); err != nil {
message.Warn("error printing variables")
}
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions src/pkg/bundle/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func getOCIValidatedSource(source string) (string, error) {
_, err = remote.ResolveRoot(ctx)
if err != nil {
originalErr = err
message.Debugf(err.Error())
message.Debug(err)
}
}
// if root didn't resolve, expand the path
Expand All @@ -256,15 +256,15 @@ func getOCIValidatedSource(source string) (string, error) {
_, err = remote.ResolveRoot(ctx)
}
if err != nil {
message.Debugf(err.Error())
message.Debug(err)
// Check in delivery bundle path
source = GHCRDeliveryBundlePath + originalSource
remote, err = zoci.NewRemote(ctx, source, platform)
if err == nil {
_, err = remote.ResolveRoot(ctx)
}
if err != nil {
message.Debugf(err.Error())
message.Debug()
// Check in packages bundle path
source = GHCRPackagesPath + originalSource
remote, err = zoci.NewRemote(ctx, source, platform)
Expand All @@ -273,7 +273,7 @@ func getOCIValidatedSource(source string) (string, error) {
}
// All checks failed, return error
if err != nil {
message.Debugf(err.Error())
message.Debug(err)
if originalErr == nil {
errMsg := fmt.Sprintf("%s: not found", originalSource)
return "", errors.New(errMsg)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/sources/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (t *TarballBundle) LoadPackageMetadata(_ context.Context, dst *layout.Packa
}

if zarfYamlSHA == "" {
return v1alpha1.ZarfPackage{}, nil, fmt.Errorf(fmt.Sprintf("zarf.yaml with SHA %s not found", zarfYamlSHA))
return v1alpha1.ZarfPackage{}, nil, fmt.Errorf("zarf.yaml with SHA %s not found", zarfYamlSHA)
}

// grab SHA of checksums.txt
Expand Down

0 comments on commit b0d1467

Please sign in to comment.