Skip to content

Commit

Permalink
'configure set' command save the STS (Security Token Service) region …
Browse files Browse the repository at this point in the history
…configuration to config file.
  • Loading branch information
CodeSpaceiiii committed Feb 6, 2025
1 parent b9ab5d4 commit 9cd6ac2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/configure_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func doConfigureSet(w io.Writer, flags *cli.FlagSet) {
profile.ReadTimeout = ReadTimeoutFlag(flags).GetIntegerOrDefault(profile.ReadTimeout)
profile.ConnectTimeout = ConnectTimeoutFlag(flags).GetIntegerOrDefault(profile.ConnectTimeout)
profile.RetryCount = RetryCountFlag(flags).GetIntegerOrDefault(profile.RetryCount)
profile.StsRegion = StsRegionFlag(flags).GetStringOrDefault(profile.StsRegion)

err = profile.Validate()
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion config/configure_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -155,4 +155,18 @@ func TestDoConfigureSet(t *testing.T) {
w.Reset()
doConfigureSet(w, fs)
assert.Empty(t, w.String())
// OIDC
hookLoadConfiguration = func(fn func(path string) (*Configuration, error)) func(path string) (*Configuration, error) {
return func(path string) (*Configuration, error) {
return &Configuration{
CurrentProfile: "default",
Profiles: []Profile{
{Name: "default", Mode: OIDC, OIDCProviderARN: "OIDCProviderARN", OIDCTokenFile: "OIDCTokenFile",
RoleSessionName: "RoleSessionName", RamRoleArn: "RamRoleArn", AccessKeyId: "default_aliyun_access_key_id",
AccessKeySecret: "default_aliyun_access_key_secret", OutputFormat: "json", RegionId: "cn-hangzhou", StsRegion: "eu-central-1"},
{Name: "aaa", Mode: AK, AccessKeyId: "sdf", AccessKeySecret: "ddf", OutputFormat: "json"}}}, nil
}
}
w.Reset()
doConfigureSet(w, fs)
}
2 changes: 2 additions & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func (cp *Profile) OverwriteWithFlags(ctx *cli.Context) {
cp.RetryCount = RetryCountFlag(ctx.Flags()).GetIntegerOrDefault(cp.RetryCount)
cp.ExpiredSeconds = ExpiredSecondsFlag(ctx.Flags()).GetIntegerOrDefault(cp.ExpiredSeconds)
cp.ProcessCommand = ProcessCommandFlag(ctx.Flags()).GetStringOrDefault(cp.ProcessCommand)
cp.OIDCProviderARN = OIDCProviderARNFlag(ctx.Flags()).GetStringOrDefault(cp.OIDCProviderARN)
cp.OIDCTokenFile = OIDCTokenFileFlag(ctx.Flags()).GetStringOrDefault(cp.OIDCTokenFile)

if cp.AccessKeyId == "" {
cp.AccessKeyId = util.GetFromEnv("ALIBABA_CLOUD_ACCESS_KEY_ID", "ALIBABACLOUD_ACCESS_KEY_ID", "ALICLOUD_ACCESS_KEY_ID", "ACCESS_KEY_ID")
Expand Down

0 comments on commit 9cd6ac2

Please sign in to comment.