Skip to content

Commit

Permalink
Add DumpEnv func to Restic Config file (#870)
Browse files Browse the repository at this point in the history
  • Loading branch information
suaas21 authored and tamalsaha committed Aug 21, 2019
1 parent ebde15d commit 9bbcaba
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/restic/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package restic

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"

shell "github.com/codeskyblue/go-sh"
ofst "kmodules.xyz/offshoot-api/api/v1"
"stash.appscode.dev/stash/apis/stash/v1alpha1"
Expand Down Expand Up @@ -97,6 +103,29 @@ func (w *ResticWrapper) SetEnv(key, value string) {
}
}

func (w *ResticWrapper) DumpEnv(path string, dumpedFile string) error {
if err := os.MkdirAll(path, 0755); err != nil {
return err
}

var envs string
if w.sh != nil {
sortedKeys := make([]string, 0, len(w.sh.Env))
for k := range w.sh.Env {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys) //sort by key
for _, v := range sortedKeys {
envs = envs + fmt.Sprintln(v+"="+w.sh.Env[v])
}
}

if err := ioutil.WriteFile(filepath.Join(path, dumpedFile), []byte(envs), 0600); err != nil {
return err
}
return nil
}

func (w *ResticWrapper) HideCMD() {
if w.sh != nil {
w.sh.ShowCMD = false
Expand Down

0 comments on commit 9bbcaba

Please sign in to comment.