/
commands.go
53 lines (48 loc) · 1.45 KB
/
commands.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
package ssmParameterStore
import "fmt"
import "bufio"
import "os"
// CMDPull handles the command line's ssm-parameter-store get
func CMDPull(paths []string, format string, directory string) {
p := NewParameterStatesFromSSM(paths)
p.toDisk(directory)
}
// CMDPush executes ssm-parameter-store push from the CLI
func CMDPush(paths []string, format string, directory string, noInput bool) {
desired := NewParameterStatesFromDisk(paths, format, directory)
current := NewParameterStatesFromSSM(paths)
diff, err := desired.diff(current)
Check(err)
if diff.String() != "\n" {
fmt.Print(diff)
// push without prompt
if noInput {
err = diff.commit()
} else {
// prompt user for confirmation
reader := bufio.NewReader(os.Stdin)
fmt.Print(`Do you want to perform these actions?
ssm-parameter-store will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: `)
text, _ := reader.ReadString('\n')
if text == "yes\n" {
err = diff.commit()
} else {
fmt.Println("Error: Push cancelled.")
}
}
Check(err)
fmt.Println("Push completed.")
} else {
fmt.Println("Nothing to change.")
}
}
// CMDDiff executes ssm-parameter-store diff from the CLI
func CMDDiff(paths []string, format string, directory string) {
desired := NewParameterStatesFromDisk(paths, format, directory)
current := NewParameterStatesFromSSM(paths)
diff, err := desired.diff(current)
Check(err)
fmt.Print(diff)
}