-
Notifications
You must be signed in to change notification settings - Fork 2
/
chefKnife.go
45 lines (40 loc) · 1.01 KB
/
chefKnife.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
package main
import (
"bytes"
"log"
"os/exec"
"strings"
)
// lets you substitute data bags for token files! So cool!
// knife data bag show {data_bag} {bag_entry.json} -F json
// TODO: add debugging options so commands are displayed as executed.
func collectEncrytpedDataBagJSON(bag, blob, secret string) []byte {
cmd := exec.Command("knife", "data", "bag", "show", "--secret-file", secret, bag, blob, "-F", "json")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
return out.Bytes()
}
func listDataBagEntries(bag string) []string {
cmd := exec.Command("knife", "data", "bag", "show", bag)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
return strings.Split(out.String(), "\n")
}
func collectDataBagJSON(bag, blob string) []byte {
cmd := exec.Command("knife", "data", "bag", "show", bag, blob, "-F", "json")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
return out.Bytes()
}