Skip to content

Commit

Permalink
base64 decode helm charts when downloading a kots release (#180)
Browse files Browse the repository at this point in the history
* base64 decode helm charts when downloading a kots release
  • Loading branch information
sgalsaleh authored Aug 4, 2021
1 parent 7ce8ebb commit 783bd92
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cli/cmd/release_download.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package cmd

import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/spf13/cobra"
"io/ioutil"
"os"
"path/filepath"
"strconv"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/spf13/cobra"
)

func (r *runners) InitReleaseDownload(parent *cobra.Command) {
Expand Down Expand Up @@ -64,7 +66,23 @@ func (r *runners) releaseDownload(command *cobra.Command, args []string) error {
for _, releaseYaml := range releaseYamls {
path := filepath.Join(r.args.releaseDownloadDest, releaseYaml.Path)
log.ChildActionWithoutSpinner(releaseYaml.Path)
err := ioutil.WriteFile(path, []byte(releaseYaml.Content), 0644)

var content []byte

ext := filepath.Ext(releaseYaml.Path)
switch ext {
case ".tgz", ".gz":
decoded, err := base64.StdEncoding.DecodeString(releaseYaml.Content)
if err == nil {
content = decoded
} else {
content = []byte(releaseYaml.Content)
}
default:
content = []byte(releaseYaml.Content)
}

err := ioutil.WriteFile(path, content, 0644)
if err != nil {
return errors.Wrapf(err, "write file %q", path)
}
Expand Down

0 comments on commit 783bd92

Please sign in to comment.