Skip to content

Commit

Permalink
added new rm flag for aliyun profile deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
arafato committed Mar 10, 2020
1 parent ba0bf4e commit f3e5597
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 16 additions & 3 deletions cli/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

type RemoveCommandInput struct {
ProfileName string
Keyring *vault.CredentialKeyring
ProfileName string
AliyunCliProfil bool
Keyring *vault.CredentialKeyring
}

func ConfigureRemoveCommand(app *kingpin.Application) {
Expand All @@ -24,6 +25,10 @@ func ConfigureRemoveCommand(app *kingpin.Application) {
HintAction(getProfileNames).
StringVar(&input.ProfileName)

cmd.Flag("aliyun", "Delete the according Aliyun CLI profile").
Short('a').
BoolVar(&input.AliyunCliProfil)

cmd.Action(func(c *kingpin.ParseContext) error {
input.Keyring = &vault.CredentialKeyring{Keyring: keyringImpl}
RemoveCommand(app, input)
Expand All @@ -44,5 +49,13 @@ func RemoveCommand(app *kingpin.Application, input RemoveCommandInput) {
app.Fatalf(err.Error())
return
}
fmt.Printf("Deleted profile.\n")
fmt.Printf("Deleted profile from Keyvault.\n")

if input.AliyunCliProfil {
if err := configLoader.DeleteProfile(input.ProfileName); err != nil {
app.Fatalf(err.Error())
return
}
fmt.Printf("Deleted profile from Aliyun CLI config.\n")
}
}
11 changes: 11 additions & 0 deletions vault/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func (cl *ConfigLoader) LoadProfile(profileName string) (*Config, error) {
return &cl.BaseConfig, nil
}

func (cl *ConfigLoader) DeleteProfile(profileName string) error {
newConfig := config.NewConfiguration()
for _, p := range cl.AliyunConfig.Profiles {
if p.Name != profileName {
newConfig.PutProfile(p)
}
}
err := config.SaveConfiguration(newConfig)
return err
}

func (cl *ConfigLoader) AddNewProfile(name string) error {
p, exists := cl.AliyunConfig.GetProfile(name)
if !exists {
Expand Down

0 comments on commit f3e5597

Please sign in to comment.