in agent/session/plugin/config/configure.go [64:167]
func doConfigure(ctx *cli.Context, profileName string, mode string) error {
w := ctx.Writer()
conf, err := hookLoadConfiguration(LoadConfiguration)(GetConfigPath2())
if err != nil {
return err
}
if profileName == "" {
if conf.CurrentProfile == "" {
profileName = "default"
} else {
profileName = conf.CurrentProfile
originMode := string(conf.GetCurrentProfile(ctx).Mode)
if mode == "" {
mode = originMode
} else if mode != originMode {
cli.Printf(w, "Warning: You are changing the authentication type of profile '%s' from '%s' to '%s'\n", profileName, originMode, mode)
}
}
}
if mode == "" {
mode = "AK"
}
cp, ok := conf.GetProfile(profileName)
if !ok {
cp = conf.NewProfile(profileName)
}
cli.Printf(w, "Configuring profile '%s' in '%s' authenticate mode...\n", profileName, mode)
if mode != "" {
switch AuthenticateMode(mode) {
case AK:
cp.Mode = AK
configureAK(w, &cp, ctx)
case StsToken:
cp.Mode = StsToken
configureStsToken(w, &cp, ctx)
case RamRoleArn:
cp.Mode = RamRoleArn
configureRamRoleArn(w, &cp, ctx)
case EcsRamRole:
cp.Mode = EcsRamRole
configureEcsRamRole(w, &cp)
case RamRoleArnWithEcs:
cp.Mode = RamRoleArnWithEcs
configureRamRoleArnWithEcs(w, &cp)
case RsaKeyPair:
cp.Mode = RsaKeyPair
configureRsaKeyPair(w, &cp)
case External:
cp.Mode = External
configureExternal(w, &cp)
case CredentialsURI:
cp.Mode = CredentialsURI
configureCredentialsURI(w, &cp)
default:
return fmt.Errorf("unexcepted authenticate mode: %s", mode)
}
} else {
configureAK(w, &cp, ctx)
}
ak, _ := AccessKeyIdFlag(ctx.Flags()).GetValue()
if ak == "" {
// configure common
cli.Printf(w, "Default Region Id [%s]: ", cp.RegionId)
cp.RegionId = ReadInput(cp.RegionId)
cli.Printf(w, "Default Output Format [%s]: json (Only support json)\n", cp.OutputFormat)
// cp.OutputFormat = ReadInput(cp.OutputFormat)
cp.OutputFormat = "json"
cli.Printf(w, "Default Language [zh|en] %s: ", cp.Language)
cp.Language = ReadInput(cp.Language)
if cp.Language != "zh" && cp.Language != "en" {
cp.Language = "en"
}
} else {
region, _ := RegionFlag(ctx.Flags()).GetValue()
if region != "" {
cp.RegionId = region
}
}
//fmt.Printf("User site: [china|international|japan] %s", cp.Site)
//cp.Site = ReadInput(cp.Site)
cli.Printf(w, "Saving profile[%s] ...", profileName)
conf.PutProfile(cp)
conf.CurrentProfile = cp.Name
err = hookSaveConfiguration(SaveConfiguration)(conf)
if err != nil {
return err
}
cli.Printf(w, "Done.\n")
// DoHello(ctx, &cp)
return nil
}