Skip to content

Commit 783bd92

Browse files
authored
base64 decode helm charts when downloading a kots release (#180)
* base64 decode helm charts when downloading a kots release
1 parent 7ce8ebb commit 783bd92

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cli/cmd/release_download.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package cmd
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"fmt"
6-
"github.com/pkg/errors"
7-
"github.com/replicatedhq/replicated/cli/print"
8-
"github.com/spf13/cobra"
97
"io/ioutil"
108
"os"
119
"path/filepath"
1210
"strconv"
11+
12+
"github.com/pkg/errors"
13+
"github.com/replicatedhq/replicated/cli/print"
14+
"github.com/spf13/cobra"
1315
)
1416

1517
func (r *runners) InitReleaseDownload(parent *cobra.Command) {
@@ -64,7 +66,23 @@ func (r *runners) releaseDownload(command *cobra.Command, args []string) error {
6466
for _, releaseYaml := range releaseYamls {
6567
path := filepath.Join(r.args.releaseDownloadDest, releaseYaml.Path)
6668
log.ChildActionWithoutSpinner(releaseYaml.Path)
67-
err := ioutil.WriteFile(path, []byte(releaseYaml.Content), 0644)
69+
70+
var content []byte
71+
72+
ext := filepath.Ext(releaseYaml.Path)
73+
switch ext {
74+
case ".tgz", ".gz":
75+
decoded, err := base64.StdEncoding.DecodeString(releaseYaml.Content)
76+
if err == nil {
77+
content = decoded
78+
} else {
79+
content = []byte(releaseYaml.Content)
80+
}
81+
default:
82+
content = []byte(releaseYaml.Content)
83+
}
84+
85+
err := ioutil.WriteFile(path, content, 0644)
6886
if err != nil {
6987
return errors.Wrapf(err, "write file %q", path)
7088
}

0 commit comments

Comments
 (0)