Skip to content

Commit 210b3c5

Browse files
night556JacksonTian
authored andcommitted
add: credential type RamRoleArnWithRoleName
1 parent 4e1a550 commit 210b3c5

File tree

432 files changed

+42230
-15879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

432 files changed

+42230
-15879
lines changed

CHANGELOG.md

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

33
### Master
44

5+
- add: credential type `RamRoleArnWithRoleName`
6+
>This type is to add RamRoleArn credentials based on EcsRamRole, and does not store information such as ak locally. When the ecs role has the AssumeRole permission, it can be used to exchange permissions for another role.
7+
```shell
8+
$ aliyun configure --mode RamRoleArnWithRoleName --profile ecsarn
9+
Configuring profile 'ecsarn' in 'RamRoleArnWithRoleName' authenticate mode...
10+
Ecs Ram Role []: <YourEcsRamRole>
11+
Ram Role Arn []: <YourRamRoleArn>
12+
Role Session Name []: <YourRoleSessionName>
13+
Expired Seconds [900]:
14+
Default Region Id []: cn-hangzhou
15+
Default Output Format [json]: json (Only support json)
16+
Default Language [zh|en] en:
17+
Saving profile[ecsarn] ...Done
18+
```
519
- add: flag `--expired-seconds` to specify expiration time
620
- update: Help information for the configure command
721

config/configure.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewConfigureCommand() *cli.Command {
3838
Short: i18n.T(
3939
"configure credential and settings",
4040
"配置身份认证和其他信息"),
41-
Usage: "configure --mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair} --profile <profileName>",
41+
Usage: "configure --mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair|RamRoleArnWithRoleName} --profile <profileName>",
4242
Run: func(ctx *cli.Context, args []string) error {
4343
if len(args) > 0 {
4444
return cli.NewInvalidCommandError(args[0], ctx)
@@ -101,6 +101,9 @@ func doConfigure(ctx *cli.Context, profileName string, mode string) error {
101101
case EcsRamRole:
102102
cp.Mode = EcsRamRole
103103
configureEcsRamRole(w, &cp)
104+
case RamRoleArnWithEcs:
105+
cp.Mode = RamRoleArnWithEcs
106+
configureRamRoleArnWithEcs(w, &cp)
104107
case RsaKeyPair:
105108
cp.Mode = RsaKeyPair
106109
configureRsaKeyPair(w, &cp)
@@ -186,6 +189,21 @@ func configureEcsRamRole(w io.Writer, cp *Profile) error {
186189
return nil
187190
}
188191

192+
func configureRamRoleArnWithEcs(w io.Writer, cp *Profile) error {
193+
cli.Printf(w, "Ecs Ram Role [%s]: ", cp.RamRoleName)
194+
cp.RamRoleName = ReadInput(cp.RamRoleName)
195+
cli.Printf(w, "Ram Role Arn [%s]: ", cp.RamRoleArn)
196+
cp.RamRoleArn = ReadInput(cp.RamRoleArn)
197+
cli.Printf(w, "Role Session Name [%s]: ", cp.RoleSessionName)
198+
cp.RoleSessionName = ReadInput(cp.RoleSessionName)
199+
if cp.ExpiredSeconds == 0 {
200+
cp.ExpiredSeconds = 900
201+
}
202+
cli.Printf(w, "Expired Seconds [%v]: ", cp.ExpiredSeconds)
203+
cp.ExpiredSeconds, _ = strconv.Atoi(ReadInput(strconv.Itoa(cp.ExpiredSeconds)))
204+
return nil
205+
}
206+
189207
func configureRsaKeyPair(w io.Writer, cp *Profile) error {
190208
cli.Printf(w, "Rsa Private Key File: ")
191209
keyFile := ReadInput("")

config/configure_list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func doConfigureList(w io.Writer) {
6363
cred = "RamRoleArn:" + "***" + GetLastChars(pf.AccessKeyId, 3)
6464
case EcsRamRole:
6565
cred = "EcsRamRole:" + pf.RamRoleName
66+
case RamRoleArnWithEcs:
67+
cred = "arn:" + "***" + GetLastChars(pf.AccessKeyId, 3)
6668
case RsaKeyPair:
6769
cred = "RsaKeyPair:" + pf.KeyPairName
6870
}

config/configure_set.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func doConfigureSet(w io.Writer, flags *cli.FlagSet) {
103103
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
104104
case EcsRamRole:
105105
profile.RamRoleName = RamRoleNameFlag(flags).GetStringOrDefault(profile.RamRoleName)
106+
case RamRoleArnWithEcs:
107+
profile.RamRoleName = RamRoleNameFlag(flags).GetStringOrDefault(profile.RamRoleName)
108+
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
109+
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
110+
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
106111
case RsaKeyPair:
107112
profile.PrivateKey = PrivateKeyFlag(flags).GetStringOrDefault(profile.PrivateKey)
108113
profile.KeyPairName = KeyPairNameFlag(flags).GetStringOrDefault(profile.KeyPairName)

config/configure_set_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ func TestDoConfigureSet(t *testing.T) {
9999
doConfigureSet(w, fs)
100100
assert.Empty(t, w.String())
101101

102+
//RamRoleArnWithEcs
103+
hookLoadConfiguration = func(fn func(path string, w io.Writer) (Configuration, error)) func(path string, w io.Writer) (Configuration, error) {
104+
return func(path string, w io.Writer) (Configuration, error) {
105+
return Configuration{CurrentProfile: "default", Profiles: []Profile{Profile{Name: "default", Mode: RamRoleArnWithEcs, RamRoleName: "RamRoleName", RoleSessionName: "RoleSessionName", RamRoleArn: "RamRoleArn", AccessKeyId: "default_aliyun_access_key_id", AccessKeySecret: "default_aliyun_access_key_secret", OutputFormat: "json", RegionId: "cn-hangzhou"}, Profile{Name: "aaa", Mode: AK, AccessKeyId: "sdf", AccessKeySecret: "ddf", OutputFormat: "json"}}}, nil
106+
}
107+
}
108+
w.Reset()
109+
doConfigureSet(w, fs)
110+
assert.Empty(t, w.String())
111+
102112
//RsaKeyPair
103113
hookLoadConfiguration = func(fn func(path string, w io.Writer) (Configuration, error)) func(path string, w io.Writer) (Configuration, error) {
104114
return func(path string, w io.Writer) (Configuration, error) {

config/flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ func NewModeFlag() *cli.Flag {
149149
Category: "config",
150150
Name: ModeFlagName, DefaultValue: "AK", Persistent: true,
151151
Short: i18n.T(
152-
"use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` to assign authenticate mode",
153-
"使用 `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` 指定认证方式")}
152+
"use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair|RamRoleArnWithRoleName}` to assign authenticate mode",
153+
"使用 `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair|RamRoleArnWithRoleName}` 指定认证方式")}
154154
}
155155

156156
func NewAccessKeyIdFlag() *cli.Flag {

config/flags_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func TestAddFlag(t *testing.T) {
4848
DefaultValue: "AK",
4949
Persistent: true,
5050
Short: i18n.T(
51-
"use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` to assign authenticate mode",
52-
"使用 `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair}` 指定认证方式"),
51+
"use `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair|RamRoleArnWithRoleName}` to assign authenticate mode",
52+
"使用 `--mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair|RamRoleArnWithRoleName}` 指定认证方式"),
5353
Long: nil,
5454
Required: false,
5555
Aliases: nil,

0 commit comments

Comments
 (0)