Skip to content

Commit ad038d0

Browse files
author
suaas21
committed
Add DumpEnv func
1 parent 6c12732 commit ad038d0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pkg/restic/config.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package restic
22

33
import (
4+
"fmt"
45
shell "github.com/codeskyblue/go-sh"
56
ofst "kmodules.xyz/offshoot-api/api/v1"
7+
"os"
8+
"path/filepath"
69
"stash.appscode.dev/stash/apis/stash/v1alpha1"
710
)
811

@@ -97,6 +100,28 @@ func (w *ResticWrapper) SetEnv(key, value string) {
97100
}
98101
}
99102

103+
func (w *ResticWrapper) DumpEnv(path string, resticEnvs string) error{
104+
if err := os.MkdirAll(path, 0755); err != nil {
105+
return err
106+
}
107+
108+
file, err := os.Create(filepath.Join(path, resticEnvs))
109+
if err != nil {
110+
return err
111+
}
112+
113+
if w.sh != nil {
114+
for k,v:= range w.sh.Env{
115+
kv := fmt.Sprintf("%s=%s\n", k, v)
116+
_, err = file.Write([]byte(kv))
117+
if err != nil {
118+
return err
119+
}
120+
}
121+
}
122+
return nil
123+
}
124+
100125
func (w *ResticWrapper) HideCMD() {
101126
if w.sh != nil {
102127
w.sh.ShowCMD = false

0 commit comments

Comments
 (0)