fix: use temporary file for secret file to prevent deletion collision (#250)

Fixes #167
This commit is contained in:
Shane Starcher 2018-08-29 17:28:26 -07:00 committed by KUOKA Yusuke
parent 822cc13e72
commit 9b71c64ef2
1 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,8 @@ package helmexec
import (
"io"
"io/ioutil"
"os"
"strings"
"go.uber.org/zap"
@ -102,7 +104,19 @@ func (helm *execer) DecryptSecret(name string) (string, error) {
helm.logger.Infof("Decrypting secret %v", name)
out, err := helm.exec(append([]string{"secrets", "dec", name})...)
helm.write(out)
return name + ".dec", err
tmpFile, err := ioutil.TempFile("", "secret")
if err != nil {
return "", err
}
tmpFile.Close()
err = os.Rename(name+".dec", tmpFile.Name())
if err != nil {
return "", err
}
return tmpFile.Name(), err
}
func (helm *execer) DiffRelease(name, chart string, flags ...string) error {