Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Improve mimetype handling and mapstructure downgrade
Browse files Browse the repository at this point in the history
mitchellh/mapstructure added mitchellh/mapstructure#187
with 1.3.2 which somehow breaks the decode() function of kusible.

Added TODOs where applicable to check later
  • Loading branch information
mgruener committed Jan 21, 2021
1 parent 4710346 commit e4926c2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/imdario/mergo v0.3.11
github.com/kjk/lzmadec v0.0.0-20200118223809-980b947af806
github.com/kr/pretty v0.2.1 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/mitchellh/mapstructure v1.3.1
github.com/pborman/ansi v1.0.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Expand Up @@ -534,9 +534,10 @@ github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.3.1 h1:cCBH2gTD2K0OtLlv/Y5H01VQCqmlDxz30kS5Y5bqfLA=
github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f h1:2+myh5ml7lgEU/51gbeLHfKGNfgEQQIWrlbdaOsidbQ=
github.com/mitchellh/osext v0.0.0-20151018003038-5e2d6d41470f/go.mod h1:OkQIRizQZAeMln+1tSwduZz7+Af5oFlKirV/MSYes2A=
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
Expand Down
2 changes: 2 additions & 0 deletions pkg/inventory/config/types.go
Expand Up @@ -56,6 +56,8 @@ type Params map[string]interface{}

// decode the given data with the default decoder settings
func decode(data *map[string]interface{}, result interface{}) error {
// TODO: check https://github.com/mitchellh/mapstructure/issues/187 to
// support mitchellh/mapstructure > 1.3.1
decoderConfig := &mapstructure.DecoderConfig{
ZeroFields: true,
ErrorUnused: false,
Expand Down
9 changes: 4 additions & 5 deletions pkg/loader/file.go
Expand Up @@ -69,23 +69,22 @@ func (b *FileBackend) Load() ([]byte, error) {
}

var raw []byte
switch mime.String() {
case "text/plain":
if mime.Is("text/plain") {
raw, err = ioutil.ReadFile(b.config.Path)
if err != nil {
return nil, err
}
case "application/x-7z-compressed":
} else if mime.Is("application/x-7z-compressed") {
raw, err = extractSingleTar7ZipFile(b.config.Path, b.config.DecryptKey)
if err != nil {
return nil, err
}
case "application/octet-stream":
} else if mime.Is("application/octet-stream") {
raw, err = decryptOpensslSymmetricFile(b.config.Path, b.config.DecryptKey)
if err != nil {
return nil, err
}
default:
} else {
return nil, errors.New("Unknown source file type: " + mime.String())
}

Expand Down
9 changes: 4 additions & 5 deletions pkg/loader/s3.go
Expand Up @@ -138,20 +138,19 @@ func (b *S3Backend) Load() ([]byte, error) {

var rawKubeconfig []byte

switch mime.String() {
case "text/plain":
if mime.Is("text/plain") {
rawKubeconfig = data
case "application/x-7z-compressed":
} else if mime.Is("application/x-7z-compressed") {
rawKubeconfig, err = extractSingleTar7Zip(data, b.config.DecryptKey)
if err != nil {
return nil, err
}
case "application/octet-stream":
} else if mime.Is("application/octet-stream") {
rawKubeconfig, err = decryptOpensslSymmetric(data, b.config.DecryptKey)
if err != nil {
return nil, err
}
default:
} else {
return nil, errors.New("Unknown kubeconfig source file type: " + mime.String())
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/loader/util.go
Expand Up @@ -58,7 +58,7 @@ func extractSingleTar7ZipFile(path string, password string) ([]byte, error) {
if err != nil {
return nil, err
}
if mime.String() != "application/x-7z-compressed" {
if !mime.Is("application/x-7z-compressed") {
return nil, errors.New("expected MIME type application/x-7z-compressed but got " + mime.String())
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/playbook/config/config.go
Expand Up @@ -28,6 +28,8 @@ import (

// decode the given data with the default decoder settings
func decode(data *map[string]interface{}, result interface{}) error {
// TODO: check https://github.com/mitchellh/mapstructure/issues/187 to
// support mitchellh/mapstructure > 1.3.1
decoderConfig := &mapstructure.DecoderConfig{
ZeroFields: true,
ErrorUnused: false,
Expand Down

0 comments on commit e4926c2

Please sign in to comment.