Skip to content

Commit

Permalink
Add config set/unset commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Jan 6, 2021
1 parent 28d5d4a commit 22eee9e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,57 @@ var getCmd = &cobra.Command{
},
}

// setCmd represents the config set command
var setCmd = &cobra.Command{
Use: "set <variable>=<value>",
Short: "set the value of a single config variable",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
Example: "apppack -a my-app config set ENVIRONMENT=production",
Run: func(cmd *cobra.Command, args []string) {
if !strings.Contains(args[0], "=") {
checkErr(fmt.Errorf("argument should be in the form <variable>=<value>"))
}
parts := strings.SplitN(args[0], "=", 2)
name := parts[0]
value := parts[1]
startSpinner()
a, err := app.Init(AppName)
checkErr(err)
svc := ssm.New(a.Session)
_, err = svc.PutParameter(&ssm.PutParameterInput{
Name: aws.String(fmt.Sprintf("/paaws/apps/%s/config/%s", AppName, name)),
Type: aws.String("SecureString"),
Overwrite: aws.Bool(true),
Value: &value,
})
Spinner.Stop()
checkErr(err)
printSuccess(fmt.Sprintf("stored config variable %s", name))
},
}

// unsetCmd represents the get command
var unsetCmd = &cobra.Command{
Use: "unset <variable>",
Short: "remove a config variable",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
startSpinner()
name := args[0]
a, err := app.Init(AppName)
checkErr(err)
svc := ssm.New(a.Session)
_, err = svc.DeleteParameter(&ssm.DeleteParameterInput{
Name: aws.String(fmt.Sprintf("/paaws/apps/%s/config/%s", AppName, args[0])),
})
Spinner.Stop()
checkErr(err)
printSuccess(fmt.Sprintf("removed config variable %s", name))
},
}

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Expand Down Expand Up @@ -98,5 +149,7 @@ func init() {
configCmd.MarkPersistentFlagRequired("app-name")

configCmd.AddCommand(getCmd)
configCmd.AddCommand(setCmd)
configCmd.AddCommand(unsetCmd)
configCmd.AddCommand(listCmd)
}

0 comments on commit 22eee9e

Please sign in to comment.