Skip to content

Commit 6cc7bbe

Browse files
authored
Merge pull request #16 from akamai-developers/bugfix/pulumi-user-login
bugfix(setup): handle unnecessary output from pulumi whoami command, and then resolve golangci-lint errors
2 parents fd27ba8 + 3b4a778 commit 6cc7bbe

9 files changed

Lines changed: 35 additions & 5 deletions

File tree

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ linters:
5050
- gocheckcompilerdirectives
5151
- gochecksumtype
5252
- gocognit
53-
- goconst
5453
- gocritic
5554
- gocyclo
5655
- godoclint
@@ -125,6 +124,7 @@ linters:
125124
- funlen
126125
- gochecknoglobals
127126
- gochecknoinits
127+
- goconst
128128
- lll
129129
- mirror
130130
- mnd
@@ -153,6 +153,8 @@ linters:
153153
- 'utils.+'
154154
gosec:
155155
confidence: medium
156+
excludes:
157+
- G704
156158
varnamelen:
157159
check-type-param: true
158160
ignore-type-assert-ok: true

cmd/automation.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"strconv"
1111
"strings"
12+
"time"
1213

1314
"github.com/pulumi/pulumi/sdk/v3/go/auto"
1415
"github.com/pulumi/pulumi/sdk/v3/go/auto/optdestroy"
@@ -182,7 +183,11 @@ func stackExists(ctx context.Context, fqsn string) bool {
182183
req.Header.Add("Accept", "application/json")
183184
req.Header.Add("Authorization", auth)
184185

185-
res, err := http.DefaultClient.Do(req)
186+
httpAPIClient := &http.Client{
187+
Timeout: time.Second * 30,
188+
}
189+
190+
res, err := httpAPIClient.Do(req)
186191
if err != nil {
187192
logger.Error("client http request: " + err.Error())
188193
}

cmd/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var createCmd = &cobra.Command{
5757
if err != nil {
5858
logger.Error("generate age keys: " + err.Error())
5959
}
60+
6061
ageKeyMap := map[string]any{
6162
"publicKey": ageKeys.Recipient().String(),
6263
"privateKey": FnSecret(ageKeys.String()),

cmd/deploy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var deployCmd = &cobra.Command{
3131
}
3232

3333
var idx int
34+
3435
for k, i := range stacks {
3536
i.Path = filepath.Join(paths.Projects, platform.Name, "cmd", i.Name)
3637
i.GetFullName(ctx)

cmd/destroy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ var destroyCmd = &cobra.Command{
2828

2929
addPrePostRun := func(action, s string, b bool, i int) {
3030
funcs := make([]string, 0)
31+
3132
switch action {
3233
case "pre":
3334
funcs = destroyStacks[i].PreRun
3435
case "post":
3536
funcs = destroyStacks[i].PostRun
3637
}
38+
3739
if b {
3840
funcs = append(funcs, s)
3941
if action == "pre" {
@@ -53,18 +55,21 @@ var destroyCmd = &cobra.Command{
5355
if destroyTarget != "apl" {
5456
if !purgeObj {
5557
prompt := "WARNING: purge data in app platform obj buckets? (type YES to confirm)"
58+
5659
purgeObj = InputPrompt("warn", "YES", prompt)
5760
if !purgeObj {
5861
logger.Warn("line:ignoring obj buckets")
5962
}
6063
}
64+
6165
addPrePostRun("pre", "deleteObj", purgeObj, 2)
6266
}
6367
},
6468
Run: func(cmd *cobra.Command, args []string) {
6569
ctx := context.Background()
6670

6771
var idx int
72+
6873
for k, i := range destroyStacks {
6974
i.Path = filepath.Join(paths.Projects, platform.Name, "cmd", i.Name)
7075
i.GetFullName(ctx)

cmd/rclone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type PurgeRequest struct {
3131
RmDirs bool `json:"rmdirs,omitempty"` // add --rmDirs flag to rclone delete command
3232
}
3333

34+
//nolint:gosec
3435
type s3Remote struct {
3536
AccessKeyId string `json:"accessKey,omitempty"`
3637
Acl string `json:"acl,omitempty"`

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var initCmd = &cobra.Command{
6262
Short: "Initialize a new aplcli environment",
6363
PreRunE: func(cmd *cobra.Command, args []string) error {
6464
path := projPath()
65+
6566
err := os.MkdirAll(path.Projects, 0754)
6667
if err != nil {
6768
logger.Error("project directory creation: " + err.Error())
@@ -112,6 +113,7 @@ var initCmd = &cobra.Command{
112113
fsDir := "templates/values"
113114
exTpl := "values-example.tpl"
114115
fname := filepath.Join(paths.Values, exTpl)
116+
115117
v, err := templates.ReadFile(fsDir + "/" + exTpl)
116118
if err != nil {
117119
msg := fmt.Sprintf("read %s: %s", exTpl, err.Error())

cmd/setup.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"bufio"
55
"context"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"os"
@@ -12,6 +13,10 @@ import (
1213
"time"
1314
)
1415

16+
type PulumiUser struct {
17+
User string `json:"user"`
18+
}
19+
1520
func missingToken(tokenVar string) {
1621
var (
1722
envTxt string
@@ -81,7 +86,7 @@ func GetPulumiUser() string {
8186
logger.Error("skip update check: " + err.Error())
8287
}
8388

84-
cmd := exec.CommandContext(ctx, "pulumi", "whoami", "--non-interactive")
89+
cmd := exec.CommandContext(ctx, "pulumi", "whoami", "--non-interactive", "--json")
8590

8691
stdout, err := cmd.CombinedOutput()
8792
if err != nil {
@@ -94,7 +99,13 @@ func GetPulumiUser() string {
9499
}
95100
}
96101

97-
return string(stdout)
102+
var pulumiUser PulumiUser
103+
104+
if err := json.Unmarshal(stdout, &pulumiUser); err != nil {
105+
logger.Error("json unmarshal data from `pulumi whoami` command: " + err.Error())
106+
}
107+
108+
return pulumiUser.User
98109
}
99110

100111
func SetupPrompt(promptStr string) string {

cmd/templates/ci/golangci.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ linters:
5050
- gocheckcompilerdirectives
5151
- gochecksumtype
5252
- gocognit
53-
- goconst
5453
- gocritic
5554
- gocyclo
5655
- godoclint
@@ -125,6 +124,7 @@ linters:
125124
- funlen
126125
- gochecknoglobals
127126
- gochecknoinits
127+
- goconst
128128
- lll
129129
- mirror
130130
- mnd
@@ -153,6 +153,8 @@ linters:
153153
- 'utils.+'
154154
gosec:
155155
confidence: medium
156+
excludes:
157+
- G704
156158
varnamelen:
157159
check-type-param: true
158160
ignore-type-assert-ok: true

0 commit comments

Comments
 (0)