Skip to content

Commit 4e1a550

Browse files
authored
update (#230)
* update:Help information for the configure command * add: flag --expired-seconds
1 parent aa960bf commit 4e1a550

File tree

6 files changed

+48
-5
lines changed

6 files changed

+48
-5
lines changed

CHANGELOG.md

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

33
### Master
44

5+
- add: flag `--expired-seconds` to specify expiration time
6+
- update: Help information for the configure command
7+
58
### 3.0.29
69

710
- update: meta data

config/configure.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"io"
1919
"io/ioutil"
20+
"strconv"
2021
"strings"
2122

2223
"github.com/aliyun/aliyun-cli/cli"
@@ -37,7 +38,7 @@ func NewConfigureCommand() *cli.Command {
3738
Short: i18n.T(
3839
"configure credential and settings",
3940
"配置身份认证和其他信息"),
40-
Usage: "configure --mode <AuthenticateMode> --profile <profileName>",
41+
Usage: "configure --mode {AK|StsToken|RamRoleArn|EcsRamRole|RsaKeyPair} --profile <profileName>",
4142
Run: func(ctx *cli.Context, args []string) error {
4243
if len(args) > 0 {
4344
return cli.NewInvalidCommandError(args[0], ctx)
@@ -171,7 +172,11 @@ func configureRamRoleArn(w io.Writer, cp *Profile) error {
171172
cp.RamRoleArn = ReadInput(cp.RamRoleArn)
172173
cli.Printf(w, "Role Session Name [%s]: ", cp.RoleSessionName)
173174
cp.RoleSessionName = ReadInput(cp.RoleSessionName)
174-
cp.ExpiredSeconds = 900
175+
if cp.ExpiredSeconds == 0 {
176+
cp.ExpiredSeconds = 900
177+
}
178+
cli.Printf(w, "Expired Seconds [%v]: ", cp.ExpiredSeconds)
179+
cp.ExpiredSeconds, _ = strconv.Atoi(ReadInput(strconv.Itoa(cp.ExpiredSeconds)))
175180
return nil
176181
}
177182

config/configure_set.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func doConfigureSet(w io.Writer, flags *cli.FlagSet) {
100100
profile.AccessKeySecret = AccessKeySecretFlag(flags).GetStringOrDefault(profile.AccessKeySecret)
101101
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
102102
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
103+
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
103104
case EcsRamRole:
104105
profile.RamRoleName = RamRoleNameFlag(flags).GetStringOrDefault(profile.RamRoleName)
105106
case RsaKeyPair:

config/configure_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestConfigureStsToken(t *testing.T) {
158158
func TestConfigureRamRoleArn(t *testing.T) {
159159
w := new(bytes.Buffer)
160160
err := configureRamRoleArn(w, &Profile{Name: "default", Mode: AK, AccessKeyId: "access_key_id", AccessKeySecret: "access_key_secret", RamRoleArn: "RamRoleArn", RoleSessionName: "RoleSessionName", RegionId: "cn-hangzhou", OutputFormat: "json"})
161-
assert.Equal(t, "Access Key Id [**********_id]: Access Key Secret [**************ret]: Ram Role Arn [RamRoleArn]: Role Session Name [RoleSessionName]: ", w.String())
161+
assert.Equal(t, "Access Key Id [**********_id]: Access Key Secret [**************ret]: Ram Role Arn [RamRoleArn]: Role Session Name [RoleSessionName]: Expired Seconds [900]: ", w.String())
162162
assert.Nil(t, err)
163163
}
164164

config/flags.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
RetryCountFlagName = "retry-count"
3636
SkipSecureVerifyName = "skip-secure-verify"
3737
ConfigurePathFlagName = "config-path"
38+
ExpiredSecondsFlagName = "expired-seconds"
3839
)
3940

4041
func AddFlags(fs *cli.FlagSet) {
@@ -54,6 +55,7 @@ func AddFlags(fs *cli.FlagSet) {
5455
fs.Add(NewRetryTimeoutFlag())
5556
fs.Add(NewRetryCountFlag())
5657
fs.Add(NewSkipSecureVerify())
58+
fs.Add(NewExpiredSecondsFlag())
5759
}
5860

5961
func ProfileFlag(fs *cli.FlagSet) *cli.Flag {
@@ -118,6 +120,9 @@ func SkipSecureVerify(fs *cli.FlagSet) *cli.Flag {
118120
func ConfigurePathFlag(fs *cli.FlagSet) *cli.Flag {
119121
return fs.Get(ConfigurePathFlagName)
120122
}
123+
func ExpiredSecondsFlag(fs *cli.FlagSet) *cli.Flag {
124+
return fs.Get(ExpiredSecondsFlagName)
125+
}
121126

122127
//var OutputFlag = &cli.Flag{Category: "config",
123128
// Name: "output", AssignedMode: cli.AssignedOnce, Hidden: true,
@@ -207,7 +212,15 @@ func NewRoleSessionNameFlag() *cli.Flag {
207212
"use `--role-session-name <RoleSessionName>` to assign RoleSessionName",
208213
"使用 `--role-session-name <RoleSessionName>` 指定RoleSessionName")}
209214
}
210-
215+
func NewExpiredSecondsFlag() *cli.Flag {
216+
return &cli.Flag{
217+
Category: "config",
218+
Name: ExpiredSecondsFlagName,
219+
AssignedMode: cli.AssignedOnce,
220+
Short: i18n.T(
221+
"use `--expired-seconds <seconds>` to specify expiration time",
222+
"使用 `--expired-seconds <seconds>` 指定凭证过期时间")}
223+
}
211224
func NewPrivateKeyFlag() *cli.Flag {
212225
return &cli.Flag{Category: "config",
213226
Name: PrivateKeyFlagName,

config/flags_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,29 @@ func TestAddFlag(t *testing.T) {
295295
Shorthand: 0,
296296
DefaultValue: "",
297297
}
298+
newExpiredSecondsFlag = &cli.Flag{
299+
Category: "config",
300+
Name: ExpiredSecondsFlagName,
301+
AssignedMode: cli.AssignedOnce,
302+
Short: i18n.T(
303+
"use `--expired-seconds <seconds>` to specify expiration time",
304+
"使用 `--expired-seconds <seconds>` 指定凭证过期时间"),
305+
Long: nil,
306+
Required: false,
307+
Aliases: nil,
308+
Hidden: false,
309+
Validate: nil,
310+
Fields: nil,
311+
ExcludeWith: nil,
312+
Shorthand: 0,
313+
DefaultValue: "",
314+
Persistent: false,
315+
}
298316
)
299-
f := NewProfileFlag()
317+
f := NewExpiredSecondsFlag()
318+
assert.Equal(t, newExpiredSecondsFlag, f)
319+
320+
f = NewProfileFlag()
300321
assert.Equal(t, newProfileFlag, f)
301322

302323
f = NewModeFlag()

0 commit comments

Comments
 (0)