From 3b4a778732406649b93823bca1f650e9939ef1df Mon Sep 17 00:00:00 2001 From: ruckus-voxi Date: Wed, 11 Mar 2026 17:56:18 -0400 Subject: [PATCH] bugfix(setup): handle unnecessary output from pulumi whoami command, and then resolve golangci-lint errors --- .golangci.yml | 4 +++- cmd/automation.go | 7 ++++++- cmd/create.go | 1 + cmd/deploy.go | 1 + cmd/destroy.go | 5 +++++ cmd/rclone.go | 1 + cmd/root.go | 2 ++ cmd/setup.go | 15 +++++++++++++-- cmd/templates/ci/golangci.tpl | 4 +++- 9 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 65e4084..665d9de 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -50,7 +50,6 @@ linters: - gocheckcompilerdirectives - gochecksumtype - gocognit - - goconst - gocritic - gocyclo - godoclint @@ -125,6 +124,7 @@ linters: - funlen - gochecknoglobals - gochecknoinits + - goconst - lll - mirror - mnd @@ -153,6 +153,8 @@ linters: - 'utils.+' gosec: confidence: medium + excludes: + - G704 varnamelen: check-type-param: true ignore-type-assert-ok: true diff --git a/cmd/automation.go b/cmd/automation.go index 73575f3..dc6e506 100644 --- a/cmd/automation.go +++ b/cmd/automation.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "github.com/pulumi/pulumi/sdk/v3/go/auto" "github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy" @@ -182,7 +183,11 @@ func stackExists(ctx context.Context, fqsn string) bool { req.Header.Add("Accept", "application/json") req.Header.Add("Authorization", auth) - res, err := http.DefaultClient.Do(req) + httpAPIClient := &http.Client{ + Timeout: time.Second * 30, + } + + res, err := httpAPIClient.Do(req) if err != nil { logger.Error("client http request: " + err.Error()) } diff --git a/cmd/create.go b/cmd/create.go index 83a5e8c..6e07f8f 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -57,6 +57,7 @@ var createCmd = &cobra.Command{ if err != nil { logger.Error("generate age keys: " + err.Error()) } + ageKeyMap := map[string]any{ "publicKey": ageKeys.Recipient().String(), "privateKey": FnSecret(ageKeys.String()), diff --git a/cmd/deploy.go b/cmd/deploy.go index e0cf619..da3ba83 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -31,6 +31,7 @@ var deployCmd = &cobra.Command{ } var idx int + for k, i := range stacks { i.Path = filepath.Join(paths.Projects, platform.Name, "cmd", i.Name) i.GetFullName(ctx) diff --git a/cmd/destroy.go b/cmd/destroy.go index e6d2dc1..5bbf4e9 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -28,12 +28,14 @@ var destroyCmd = &cobra.Command{ addPrePostRun := func(action, s string, b bool, i int) { funcs := make([]string, 0) + switch action { case "pre": funcs = destroyStacks[i].PreRun case "post": funcs = destroyStacks[i].PostRun } + if b { funcs = append(funcs, s) if action == "pre" { @@ -53,11 +55,13 @@ var destroyCmd = &cobra.Command{ if destroyTarget != "apl" { if !purgeObj { prompt := "WARNING: purge data in app platform obj buckets? (type YES to confirm)" + purgeObj = InputPrompt("warn", "YES", prompt) if !purgeObj { logger.Warn("line:ignoring obj buckets") } } + addPrePostRun("pre", "deleteObj", purgeObj, 2) } }, @@ -65,6 +69,7 @@ var destroyCmd = &cobra.Command{ ctx := context.Background() var idx int + for k, i := range destroyStacks { i.Path = filepath.Join(paths.Projects, platform.Name, "cmd", i.Name) i.GetFullName(ctx) diff --git a/cmd/rclone.go b/cmd/rclone.go index 05a3616..d6ddb60 100644 --- a/cmd/rclone.go +++ b/cmd/rclone.go @@ -31,6 +31,7 @@ type PurgeRequest struct { RmDirs bool `json:"rmdirs,omitempty"` // add --rmDirs flag to rclone delete command } +//nolint:gosec type s3Remote struct { AccessKeyId string `json:"accessKey,omitempty"` Acl string `json:"acl,omitempty"` diff --git a/cmd/root.go b/cmd/root.go index e7ff71e..45d9c1b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -62,6 +62,7 @@ var initCmd = &cobra.Command{ Short: "Initialize a new aplcli environment", PreRunE: func(cmd *cobra.Command, args []string) error { path := projPath() + err := os.MkdirAll(path.Projects, 0754) if err != nil { logger.Error("project directory creation: " + err.Error()) @@ -112,6 +113,7 @@ var initCmd = &cobra.Command{ fsDir := "templates/values" exTpl := "values-example.tpl" fname := filepath.Join(paths.Values, exTpl) + v, err := templates.ReadFile(fsDir + "/" + exTpl) if err != nil { msg := fmt.Sprintf("read %s: %s", exTpl, err.Error()) diff --git a/cmd/setup.go b/cmd/setup.go index a3ff856..f96ea7f 100644 --- a/cmd/setup.go +++ b/cmd/setup.go @@ -3,6 +3,7 @@ package cmd import ( "bufio" "context" + "encoding/json" "errors" "fmt" "os" @@ -12,6 +13,10 @@ import ( "time" ) +type PulumiUser struct { + User string `json:"user"` +} + func missingToken(tokenVar string) { var ( envTxt string @@ -81,7 +86,7 @@ func GetPulumiUser() string { logger.Error("skip update check: " + err.Error()) } - cmd := exec.CommandContext(ctx, "pulumi", "whoami", "--non-interactive") + cmd := exec.CommandContext(ctx, "pulumi", "whoami", "--non-interactive", "--json") stdout, err := cmd.CombinedOutput() if err != nil { @@ -94,7 +99,13 @@ func GetPulumiUser() string { } } - return string(stdout) + var pulumiUser PulumiUser + + if err := json.Unmarshal(stdout, &pulumiUser); err != nil { + logger.Error("json unmarshal data from `pulumi whoami` command: " + err.Error()) + } + + return pulumiUser.User } func SetupPrompt(promptStr string) string { diff --git a/cmd/templates/ci/golangci.tpl b/cmd/templates/ci/golangci.tpl index 65e4084..665d9de 100644 --- a/cmd/templates/ci/golangci.tpl +++ b/cmd/templates/ci/golangci.tpl @@ -50,7 +50,6 @@ linters: - gocheckcompilerdirectives - gochecksumtype - gocognit - - goconst - gocritic - gocyclo - godoclint @@ -125,6 +124,7 @@ linters: - funlen - gochecknoglobals - gochecknoinits + - goconst - lll - mirror - mnd @@ -153,6 +153,8 @@ linters: - 'utils.+' gosec: confidence: medium + excludes: + - G704 varnamelen: check-type-param: true ignore-type-assert-ok: true