File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,28 @@ Global Flags:
9191 --version show version
9292```
9393
94+ ### ` get `
95+
96+ Get a single parameter by path.
97+
98+ ``` console
99+ Get parameter value by path
100+
101+ Usage:
102+ easy-params get <path> [flags]
103+
104+ Flags:
105+ -d, --decrypt decrypt "SecureString" value (default true)
106+ -h, --help help for get
107+
108+ Global Flags:
109+ --config string config file (default is $HOME/.easy-params.yaml)
110+ --load-config load aws config from ~/.aws/config (default true)
111+ -l, --local-time convert UTC to local time (default true)
112+ --region string AWS region to use
113+ --version show version
114+ ```
115+
94116### ` put `
95117
96118Put a parameter to the specified path.
Original file line number Diff line number Diff line change 1+ package cmd
2+
3+ import (
4+ "context"
5+ "errors"
6+ "fmt"
7+ "strings"
8+
9+ "github.com/aws/aws-sdk-go-v2/service/ssm"
10+ "github.com/spf13/cobra"
11+ )
12+
13+ var getCmd = & cobra.Command {
14+ Use : "get <path>" ,
15+ Short : "Get parameter value by path" ,
16+ Args : func (cmd * cobra.Command , args []string ) error {
17+ if len (args ) == 0 {
18+ return errors .New ("requires a path" )
19+ }
20+
21+ return nil
22+ },
23+ Run : runGetCmd ,
24+ }
25+
26+ func runGetCmd (cmd * cobra.Command , args []string ) {
27+ path := fmt .Sprintf ("/%s" , stripSlash (args [0 ]))
28+ decrypt , _ := cmd .Flags ().GetBool ("decrypt" )
29+
30+ client := ssm .NewFromConfig (awsConfig )
31+
32+ out , err := client .GetParameter (context .TODO (), & ssm.GetParameterInput {
33+ Name : & path ,
34+ WithDecryption : decrypt ,
35+ })
36+ if err != nil {
37+ panic (err )
38+ }
39+
40+ val := * out .Parameter .Value
41+
42+ if strings .HasSuffix (val , "\n " ) {
43+ val = strings .TrimSuffix (val , "\n " )
44+ }
45+
46+ fmt .Println (val )
47+ }
48+
49+ func init () {
50+ getCmd .Flags ().BoolP ("decrypt" , "d" , true , "decrypt \" SecureString\" value" )
51+
52+ rootCmd .AddCommand (getCmd )
53+ }
You can’t perform that action at this time.
0 commit comments