- added the csv output format
This commit is contained in:
parent
096e365598
commit
4e9bf27021
8
main.go
8
main.go
|
@ -120,13 +120,19 @@ func processResource(rn *vaultResource, data map[string]interface{}) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
case "csv":
|
||||||
|
var buf bytes.Buffer
|
||||||
|
for key, val := range data {
|
||||||
|
buf.WriteString(fmt.Sprintf("%s,%s\n", key, val))
|
||||||
|
}
|
||||||
|
content = buf.Bytes()
|
||||||
|
|
||||||
case "txt":
|
case "txt":
|
||||||
keys := getKeys(data)
|
keys := getKeys(data)
|
||||||
if len(keys) > 1 {
|
if len(keys) > 1 {
|
||||||
// step: for plain formats we need to iterate the keys and produce a file per key
|
// step: for plain formats we need to iterate the keys and produce a file per key
|
||||||
for suffix, content := range data {
|
for suffix, content := range data {
|
||||||
filename := fmt.Sprintf("%s.%s", resourcePath, suffix)
|
filename := fmt.Sprintf("%s.%s", resourcePath, suffix)
|
||||||
// step: write the file
|
|
||||||
if err := writeFile(filename, []byte(fmt.Sprintf("%s", content))); err != nil {
|
if err := writeFile(filename, []byte(fmt.Sprintf("%s", content))); err != nil {
|
||||||
glog.Errorf("failed to write resource: %s, elemment: %s, filename: %s, error: %s",
|
glog.Errorf("failed to write resource: %s, elemment: %s, filename: %s, error: %s",
|
||||||
rn, suffix, filename, err)
|
rn, suffix, filename, err)
|
||||||
|
|
Reference in a new issue