Skip to content

Commit

Permalink
Merge pull request #680 from souvikinator/souvik/supported-file-type
Browse files Browse the repository at this point in the history
Add support for .tgz file
  • Loading branch information
souvikinator authored Feb 12, 2025
2 parents c99eaae + 7846d90 commit 205ee6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package encoding

import (
"bytes"
"encoding/json"

"github.com/layer5io/meshkit/utils"
Expand Down Expand Up @@ -59,12 +60,16 @@ func unmarshalJSON(data []byte, result interface{}) error {
}

func Marshal(in interface{}) ([]byte, error) {
result, err := json.Marshal(in)
result, err := json.MarshalIndent(in, "", " ")
if err != nil {
result, err = yaml.Marshal(in)
var buf bytes.Buffer
enc := yaml.NewEncoder(&buf)
enc.SetIndent(2)
err = enc.Encode(in)
if err != nil {
return nil, utils.ErrMarshal(err)
}
result = buf.Bytes()
}

return result, nil
Expand Down
2 changes: 1 addition & 1 deletion files/sanitization.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var ValidIacExtensions = map[string]bool{
".tar.tgz": true,
".zip": true,
".gz": true,
".tgz": true,
}

func SanitizeFile(data []byte, fileName string, tempDir string, validExts map[string]bool) (SanitizedFile, error) {
Expand All @@ -44,7 +45,6 @@ func SanitizeFile(data []byte, fileName string, tempDir string, validExts map[st
if !validExts[ext] && !validExts[filepath.Ext(strings.TrimSuffix(fileName, ".gz"))] {
return SanitizedFile{}, ErrUnsupportedExtension(fileName, ext, validExts)
}

switch ext {

case ".yml", ".yaml":
Expand Down

0 comments on commit 205ee6b

Please sign in to comment.