Skip to content

Commit dfa2c9f

Browse files
night556JacksonTian
authored andcommitted
utomatic type recognition and update test file
1 parent 3ec520b commit dfa2c9f

File tree

3 files changed

+402
-173
lines changed

3 files changed

+402
-173
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+
- feature: Automatic type recognition `AK`,`StsToken`,`RamRoleArn`,`RsaKeyPair`,`EcsRamRole`
6+
57
### 3.0.42
68

79
- update: meta data

config/profile.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ func (cp *Profile) OverwriteWithFlags(ctx *cli.Context) {
181181
cp.RegionId = os.Getenv("REGION")
182182
}
183183
}
184+
AutoModeRecognition(cp)
185+
}
186+
187+
func AutoModeRecognition(cp *Profile) {
188+
if cp.Mode != AuthenticateMode("") {
189+
return
190+
}
191+
if cp.AccessKeyId != "" && cp.AccessKeySecret != "" {
192+
cp.Mode = AK
193+
if cp.StsToken != "" {
194+
cp.Mode = StsToken
195+
} else if cp.RamRoleArn != "" {
196+
cp.Mode = RamRoleArn
197+
}
198+
} else if cp.PrivateKey != "" && cp.KeyPairName != "" {
199+
cp.Mode = RsaKeyPair
200+
} else if cp.RamRoleName != "" {
201+
cp.Mode = EcsRamRole
202+
}
184203
}
185204

186205
func (cp *Profile) ValidateAK() error {

0 commit comments

Comments
 (0)