Skip to content

Commit 4c8b715

Browse files
night556JacksonTian
authored andcommitted
fix: unable to get accessKeyID from env
1 parent 84cc8fb commit 4c8b715

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Master
44

5+
- fix: unable to get accessKeyID from environment variable
6+
57
### 3.0.40
68

79
- update: meta data

config/profile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ func (cp *Profile) OverwriteWithFlags(ctx *cli.Context) {
159159
if cp.AccessKeySecret == "" {
160160
switch {
161161
case os.Getenv("ALIBABACLOUD_ACCESS_KEY_SECRET") != "":
162-
cp.AccessKeyId = os.Getenv("ALIBABACLOUD_ACCESS_KEY_SECRET")
162+
cp.AccessKeySecret = os.Getenv("ALIBABACLOUD_ACCESS_KEY_SECRET")
163163
case os.Getenv("ALICLOUD_ACCESS_KEY_SECRET") != "":
164-
cp.AccessKeyId = os.Getenv("ALICLOUD_ACCESS_KEY_SECRET")
164+
cp.AccessKeySecret = os.Getenv("ALICLOUD_ACCESS_KEY_SECRET")
165165
case os.Getenv("ACCESS_KEY_SECRET") != "":
166-
cp.AccessKeyId = os.Getenv("ACCESS_KEY_SECRET")
166+
cp.AccessKeySecret = os.Getenv("ACCESS_KEY_SECRET")
167167
}
168168
}
169169

config/profile_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ func TestProfile(t *testing.T) {
151151
p.OverwriteWithFlags(ctx)
152152
assert.Equal(t, Profile{Name: "default", Mode: EcsRamRole, RamRoleArn: "----", RamRoleName: "RamRoleName", OutputFormat: "json", RetryCount: 0, ReadTimeout: 0, Language: "en"}, p)
153153

154+
p.Mode = AK
155+
p.AccessKeyId = ""
156+
p.AccessKeySecret = ""
157+
os.Setenv("ACCESS_KEY_ID", "accessKeyID")
158+
os.Setenv("ACCESS_KEY_SECRET", "accessKeySecret")
159+
p.OverwriteWithFlags(ctx)
160+
assert.Equal(t, Profile{Name: "default", Mode: AK, AccessKeyId: "accessKeyID", AccessKeySecret: "accessKeySecret", RamRoleName: "RamRoleName", RamRoleArn: "----", OutputFormat: "json", RetryCount: 0, ReadTimeout: 0, Language: "en"}, p)
161+
os.Setenv("ACCESS_KEY_ID", "")
162+
os.Setenv("ACCESS_KEY_SECRET", "")
163+
p.AccessKeyId = ""
164+
p.AccessKeySecret = ""
165+
154166
//GetClient
155167
p.ReadTimeout = 1
156168
p.RetryCount = 1

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2
8080
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
8181
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
8282
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
83+
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
8384
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8485
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
8586
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

0 commit comments

Comments
 (0)