/
ls.go
51 lines (44 loc) · 1.14 KB
/
ls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cmd
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/spf13/cobra"
"log"
"time"
)
// lsCmd represents the ls command
var lsCmd = &cobra.Command{
Use: "ls [PREFIX]",
Short: "List parameters",
Long: `List ssm parameters, optionally with prefix. This is best effort, and may be throttled.`,
Run: func(cmd *cobra.Command, args []string) {
switch len(args) {
case 0:
listParams("")
case 1:
listParams(args[0])
default:
log.Fatal("wrong number of arguments")
}
},
}
func listParams(prefix string) {
filters := []types.ParametersFilter{}
if prefix != "" {
filters = append(filters, types.ParametersFilter{Key: types.ParametersFilterKeyName, Values: []string{prefix}})
}
paginator := ssm.NewDescribeParametersPaginator(client, &ssm.DescribeParametersInput{Filters: filters})
for paginator.HasMorePages() {
output, err := paginator.NextPage(context.TODO())
if err != nil {
log.Fatal(err)
}
for _, p := range output.Parameters {
fmt.Println(*p.Name)
}
// this api throttles hard
time.Sleep(100 * time.Millisecond)
}
}