-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_backup.go
66 lines (55 loc) · 1.33 KB
/
cmd_backup.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2021 Ronny Bangsund
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/grimdork/opt"
)
// BackupCmd options.
type BackupCmd struct {
opt.DefaultHelp
Bucket string `placeholder:"BUCKET" help:"S3 bucket to back up everything to."`
}
func (cmd *BackupCmd) Run(in []string) error {
if cmd.Help || cmd.Bucket == "" {
return opt.ErrUsage
}
client, err := getClient()
if err != nil {
return nil
}
filter := types.ParameterStringFilter{
Key: aws.String("Name"),
Option: aws.String("BeginsWith"),
Values: []string{validKey("/")},
}
input := &ssm.DescribeParametersInput{
MaxResults: 25,
ParameterFilters: []types.ParameterStringFilter{filter},
}
loop := true
for loop {
po, err := client.DescribeParameters(context.Background(), input)
if err != nil {
return err
}
for _, p := range po.Parameters {
if p.Description == nil {
p.Description = aws.String("")
}
fmt.Printf("%s\t%s\t%s\n", *p.Name, p.LastModifiedDate.String(), *p.Description)
}
if po.NextToken == nil {
loop = false
} else {
input.NextToken = po.NextToken
}
}
return nil
}