@@ -18,6 +18,7 @@ import (
1818
1919type fnEncode func (interface {}) string
2020
21+ // VaultBackup is all ths information required to make a backup
2122type VaultBackup struct {
2223 client * vault.Client
2324 paths []string
@@ -36,6 +37,7 @@ var encode = map[string]fnEncode{
3637 },
3738}
3839
40+ // NewBackup creates a new backup
3941func NewBackup () (* VaultBackup , error ) {
4042 config := vault .DefaultConfig ()
4143
@@ -56,7 +58,7 @@ func (b *VaultBackup) store(src map[string]string) error {
5658 return nil
5759}
5860
59- func (b * VaultBackup ) walk (parent string , paths []string ) error {
61+ func (b * VaultBackup ) walk (parent string , paths []string ) {
6062 for _ , p := range paths {
6163 if p != "" {
6264 p = fmt .Sprintf ("%s%s" , parent , p )
@@ -70,7 +72,9 @@ func (b *VaultBackup) walk(parent string, paths []string) error {
7072 log .Printf ("[ERROR] unable to read secret '%s' (%v). \n " , p , err )
7173 }
7274
73- b .store (secrets )
75+ if err := b .store (secrets ); err != nil {
76+ log .Printf ("[ERROR] unabled to merge the secrets (%v)" , err )
77+ }
7478
7579 continue
7680 }
@@ -91,8 +95,6 @@ func (b *VaultBackup) walk(parent string, paths []string) error {
9195 b .walk (p , keys )
9296 }
9397 }
94-
95- return nil
9698}
9799
98100func (b * VaultBackup ) read (path string ) (map [string ]string , error ) {
@@ -153,7 +155,7 @@ func (b *VaultBackup) write() error {
153155 return err
154156 }
155157
156- return os .WriteFile (b .filename , out , 0644 )
158+ return os .WriteFile (b .filename , out , 0600 )
157159}
158160
159161func main () {
@@ -184,9 +186,7 @@ func main() {
184186 client .encode = "base64"
185187 }
186188
187- if err := client .walk ("" , client .paths ); err != nil {
188- log .Fatal (err )
189- }
189+ client .walk ("" , client .paths )
190190
191191 if err = client .write (); err != nil {
192192 log .Fatal (err )
0 commit comments