in config/configure_set.go [41:142]
func doConfigureSet(w io.Writer, flags *cli.FlagSet) {
config, err := loadConfiguration()
if err != nil {
cli.Errorf(w, "load configuration failed %s", err)
return
}
profileName, ok := ProfileFlag(flags).GetValue()
if !ok {
profileName = config.CurrentProfile
}
profile, ok := config.GetProfile(profileName)
if !ok {
profile = NewProfile(profileName)
}
path, ok := ConfigurePathFlag(flags).GetValue()
if ok {
profile, err = LoadProfile(path, profileName)
if err != nil {
cli.Errorf(w, "load configuration file failed %s", err)
return
}
}
mode, ok := ModeFlag(flags).GetValue()
if ok {
profile.Mode = AuthenticateMode(mode)
} else {
if profile.Mode == "" {
profile.Mode = AK
}
}
switch profile.Mode {
case AK:
profile.AccessKeyId = AccessKeyIdFlag(flags).GetStringOrDefault(profile.AccessKeyId)
profile.AccessKeySecret = AccessKeySecretFlag(flags).GetStringOrDefault(profile.AccessKeySecret)
case StsToken:
profile.AccessKeyId = AccessKeyIdFlag(flags).GetStringOrDefault(profile.AccessKeyId)
profile.AccessKeySecret = AccessKeySecretFlag(flags).GetStringOrDefault(profile.AccessKeySecret)
profile.StsToken = StsTokenFlag(flags).GetStringOrDefault(profile.StsToken)
case RamRoleArn:
profile.AccessKeyId = AccessKeyIdFlag(flags).GetStringOrDefault(profile.AccessKeyId)
profile.AccessKeySecret = AccessKeySecretFlag(flags).GetStringOrDefault(profile.AccessKeySecret)
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
profile.ExternalId = ExternalIdFlag(flags).GetStringOrDefault(profile.ExternalId)
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
case EcsRamRole:
profile.RamRoleName = RamRoleNameFlag(flags).GetStringOrDefault(profile.RamRoleName)
case RamRoleArnWithEcs:
profile.RamRoleName = RamRoleNameFlag(flags).GetStringOrDefault(profile.RamRoleName)
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
case ChainableRamRoleArn:
profile.SourceProfile = SourceProfileFlag(flags).GetStringOrDefault(profile.SourceProfile)
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
profile.ExternalId = ExternalIdFlag(flags).GetStringOrDefault(profile.ExternalId)
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
case RsaKeyPair:
profile.PrivateKey = PrivateKeyFlag(flags).GetStringOrDefault(profile.PrivateKey)
profile.KeyPairName = KeyPairNameFlag(flags).GetStringOrDefault(profile.KeyPairName)
case External:
profile.ProcessCommand = ProcessCommandFlag(flags).GetStringOrDefault(profile.ProcessCommand)
case OIDC:
profile.OIDCProviderARN = OIDCProviderARNFlag(flags).GetStringOrDefault(profile.OIDCProviderARN)
profile.OIDCTokenFile = OIDCTokenFileFlag(flags).GetStringOrDefault(profile.OIDCTokenFile)
profile.RamRoleArn = RamRoleArnFlag(flags).GetStringOrDefault(profile.RamRoleArn)
profile.RoleSessionName = RoleSessionNameFlag(flags).GetStringOrDefault(profile.RoleSessionName)
profile.ExpiredSeconds = ExpiredSecondsFlag(flags).GetIntegerOrDefault(profile.ExpiredSeconds)
case CloudSSO:
profile.CloudSSOAccessConfig = CloudSSOAccessConfigFlag(flags).GetStringOrDefault(profile.CloudSSOAccessConfig)
profile.CloudSSOAccountId = CloudSSOAccountIdFlag(flags).GetStringOrDefault(profile.CloudSSOAccountId)
profile.CloudSSOSignInUrl = CloudSSOSignInUrlFlag(flags).GetStringOrDefault(profile.CloudSSOSignInUrl)
}
profile.RegionId = RegionFlag(flags).GetStringOrDefault(profile.RegionId)
profile.Language = LanguageFlag(flags).GetStringOrDefault(profile.Language)
profile.OutputFormat = "json" // "output", profile.OutputFormat)
profile.Site = "china" // "site", profile.Site)
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 {
cli.Errorf(w, "fail to set configuration: %s", err.Error())
return
}
config.PutProfile(profile)
config.CurrentProfile = profile.Name
err = hookSaveConfiguration(SaveConfiguration)(config)
if err != nil {
cli.Errorf(w, "save configuration failed %s", err)
}
}