diff --git a/README.md b/README.md index 434e0dc..39977b7 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ already on your `PATH`. ### Curl -Run the below command to download the 1.4.0 binary and add it to +Run the below command to download the 1.5.0 binary and add it to `/usr/local/bin`. #### Linux ```console -curl -LO https://github.com/WillJCJ/param/releases/download/1.4.0/param-linux-amd64 && \ +curl -LO https://github.com/WillJCJ/param/releases/download/1.5.0/param-linux-amd64 && \ chmod +x param-linux-amd64 && \ sudo mv param-linux-amd64 /usr/local/bin/param ``` @@ -51,7 +51,7 @@ sudo mv param-linux-amd64 /usr/local/bin/param #### MacOS ```console -curl -LO https://github.com/WillJCJ/param/releases/download/1.4.0/param-darwin-amd64 && \ +curl -LO https://github.com/WillJCJ/param/releases/download/1.5.0/param-darwin-amd64 && \ chmod +x param-darwin-amd64 && \ sudo mv param-darwin-amd64 /usr/local/bin/param ``` @@ -60,6 +60,10 @@ sudo mv param-darwin-amd64 /usr/local/bin/param Make sure your terminal session has the correct AWS credentials. +Below is a brief overview for each command. +Full docs for each command can be found at [`/docs`](docs/param.md). + + ### Copy Copy a parameter to your clipboard: @@ -98,6 +102,26 @@ prefix1.prod.password prefix2.key ``` +### Set + +Set a parameter with type `SecureString`: + +```console +$ param set parameter_name password123 +``` + +If the parameter already exists, you must specify the `-f` flag +to overwrite it: + +```console +$ param set parameter_name password456 -f +``` + +#### Auto-completion + +With shell completion enabled, you can press tab to auto-complete the parameter +names. + ### Show If you'd like to print out the decrypted parameter without copying it the @@ -160,9 +184,9 @@ export PARAM_NO_CACHE=1 ## Docs -Docs for each command can be found at [`/docs`](docs/param.md) +Docs for each command can be found at [`/docs`](docs/param.md). -They are automatically generated by Cobra. +They are generated by Cobra by running `go run build/generate_docs.go`. ## CI @@ -172,16 +196,18 @@ a new tag is pushed to GitHub. ## TODO - New Commands - - Set command - Command to set parameters - Delete command - Command to delete parameters + - Maybe with a `--yes` flag to confim. - Improvements - Add a flag to specify parameter type. Currently only works with `SecureString`s. + - Better logging and a verbose option to see what calls are made to AWS. - Shell Completion - `zsh` completion doesn't seem to work. - Update or delete the bash completion cache after creating/deleting parameters - Add bash completion for other subcommands and flags. + - Command to reset the cache. - Write Tests - Improve Documentation - More Examples diff --git a/cmd/add.go b/cmd/add.go deleted file mode 100644 index 13756a6..0000000 --- a/cmd/add.go +++ /dev/null @@ -1,21 +0,0 @@ -package cmd - -import ( - "fmt" - - "github.com/spf13/cobra" -) - -var addCmd = &cobra.Command{ - Use: "add", - Short: "Add a paramter to Parameter Store.", - Long: `Add a paramter to Parameter Store. - Doesn't work yet.`, - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("add called") - }, -} - -func init() { - RootCmd.AddCommand(addCmd) -} diff --git a/cmd/copy.go b/cmd/copy.go index 6d7fe4a..502e87c 100644 --- a/cmd/copy.go +++ b/cmd/copy.go @@ -8,7 +8,7 @@ import ( var verbose bool var copyCmd = &cobra.Command{ - Use: "copy parameter_name", + Use: "copy name", Short: "Copy a parameter to clipboard.", Long: "Copy the specified SSM Parameter from Paramter Store to your clipboard.", Args: cobra.ExactArgs(1), diff --git a/cmd/list.go b/cmd/list.go index 2f0db62..8921816 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -1,7 +1,6 @@ package cmd import ( - "fmt" "strings" "github.com/spf13/cobra" @@ -16,7 +15,8 @@ var listCmd = &cobra.Command{ Long: `List all parameters from parameter store with an optional prefix. Results are sorted in alphabetical order.`, Run: func(cmd *cobra.Command, args []string) { - listParameters() + prefixSlice := strings.Split(prefixes, ",") + param.List(prefixSlice) }, } @@ -25,10 +25,3 @@ func init() { listCmd.Flags().StringVarP(&prefixes, "prefix", "p", "", "Prefixes to fileter by") } - -func listParameters() { - prefixSlice := strings.Split(prefixes, ",") - for _, param := range param.DescribeParameters(prefixSlice) { - fmt.Println(param) - } -} diff --git a/cmd/root.go b/cmd/root.go index bc4a299..8c4d2eb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -101,7 +101,7 @@ const ( __custom_func() { case ${last_command} in - param_copy | param_show) + param_copy | param_set | param_show) __param_list return ;; diff --git a/cmd/set.go b/cmd/set.go new file mode 100644 index 0000000..8234e11 --- /dev/null +++ b/cmd/set.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/spf13/cobra" + "github.com/willjcj/param/pkg/param" +) + +var force bool + +var setCmd = &cobra.Command{ + Use: "set name value", + Short: "Set a paramter in Parameter Store.", + Long: "Add a SecureString paramter to Parameter Store.", + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + param.Set(args[0], args[1], force) + }, +} + +func init() { + RootCmd.AddCommand(setCmd) + setCmd.Flags().BoolVarP(&force, "force", "f", false, "Overwrite the parameter if it exists.") + +} diff --git a/docs/param.md b/docs/param.md index 44766cf..f383a76 100644 --- a/docs/param.md +++ b/docs/param.md @@ -15,10 +15,10 @@ Param is a cli tool to improve interacting with AWS Parameter Store. ### SEE ALSO -* [param add](param_add.md) - Add a paramter to Parameter Store. * [param completion](param_completion.md) - Generates shell completion scripts * [param copy](param_copy.md) - Copy a parameter to clipboard. * [param list](param_list.md) - List parameters in Parameter Store. +* [param set](param_set.md) - Set a paramter in Parameter Store. * [param show](param_show.md) - Show a decrypted parameter in the console. -###### Auto generated by spf13/cobra on 14-Jul-2018 +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/docs/param_completion.md b/docs/param_completion.md index 4a0b1ab..c1b742c 100644 --- a/docs/param_completion.md +++ b/docs/param_completion.md @@ -36,4 +36,4 @@ param completion (bash|zsh) [flags] * [param](param.md) - Tools to improve Parameter Store on the command line. -###### Auto generated by spf13/cobra on 14-Jul-2018 +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/docs/param_copy.md b/docs/param_copy.md index 32c8f5f..e090eaa 100644 --- a/docs/param_copy.md +++ b/docs/param_copy.md @@ -7,7 +7,7 @@ Copy a parameter to clipboard. Copy the specified SSM Parameter from Paramter Store to your clipboard. ``` -param copy parameter_name [flags] +param copy name [flags] ``` ### Options @@ -27,4 +27,4 @@ param copy parameter_name [flags] * [param](param.md) - Tools to improve Parameter Store on the command line. -###### Auto generated by spf13/cobra on 14-Jul-2018 +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/docs/param_list.md b/docs/param_list.md index a31965e..9d76874 100644 --- a/docs/param_list.md +++ b/docs/param_list.md @@ -28,4 +28,4 @@ param list [flags] * [param](param.md) - Tools to improve Parameter Store on the command line. -###### Auto generated by spf13/cobra on 14-Jul-2018 +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/docs/param_set.md b/docs/param_set.md new file mode 100644 index 0000000..7aa3145 --- /dev/null +++ b/docs/param_set.md @@ -0,0 +1,30 @@ +## param set + +Set a paramter in Parameter Store. + +### Synopsis + +Add a SecureString paramter to Parameter Store. + +``` +param set name value [flags] +``` + +### Options + +``` + -f, --force Overwrite the parameter if it exists. + -h, --help help for set +``` + +### Options inherited from parent commands + +``` + --config string config file (default is $HOME/.param.yaml) +``` + +### SEE ALSO + +* [param](param.md) - Tools to improve Parameter Store on the command line. + +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/docs/param_show.md b/docs/param_show.md index 8899b68..42f3eb0 100644 --- a/docs/param_show.md +++ b/docs/param_show.md @@ -26,4 +26,4 @@ param show parameter_name [flags] * [param](param.md) - Tools to improve Parameter Store on the command line. -###### Auto generated by spf13/cobra on 14-Jul-2018 +###### Auto generated by spf13/cobra on 15-Jul-2018 diff --git a/pkg/param/list.go b/pkg/param/list.go index 8ebae4f..d6c93bf 100644 --- a/pkg/param/list.go +++ b/pkg/param/list.go @@ -1,13 +1,20 @@ package param import ( + "fmt" "sort" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ssm" ) -func DescribeParameters(prefixes []string) []string { +func List(prefixes []string) { + for _, param := range describeParameters(prefixes) { + fmt.Println(param) + } +} + +func describeParameters(prefixes []string) []string { paramNames := []string{} if len(prefixes) <= 0 { paramNames = getAllParamNames() @@ -32,6 +39,7 @@ func getParamNames(prefix string) []string { Key: aws.String("Name"), Values: []*string{aws.String(prefix)}, }} + paramNames := []string{} err := service.DescribeParametersPages(&ssm.DescribeParametersInput{ Filters: filters}, diff --git a/pkg/param/set.go b/pkg/param/set.go new file mode 100644 index 0000000..133ae2f --- /dev/null +++ b/pkg/param/set.go @@ -0,0 +1,23 @@ +package param + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ssm" +) + +func Set(name string, value string, force bool) { + putSecureStringParameter(name, value, force) +} + +func putSecureStringParameter(name string, value string, overwrite bool) { + _, err := service.PutParameter(&ssm.PutParameterInput{ + Name: aws.String(name), + Type: aws.String("SecureString"), + Value: aws.String(value), + Overwrite: aws.Bool(overwrite), + }) + + if err != nil { + exitErrorf("Unable to set parameter, %v", err) + } +}