From 5bc98e002727744b2944405fac7e8c31a64b9de2 Mon Sep 17 00:00:00 2001 From: Deric Miguel Date: Fri, 31 Jul 2020 02:15:16 -0700 Subject: [PATCH 1/3] fixes aws/amazon-ssm-agent#296 --- .../configurepackage/configurepackage.go | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/agent/plugins/configurepackage/configurepackage.go b/agent/plugins/configurepackage/configurepackage.go index 96b2fb82a..358c694fb 100644 --- a/agent/plugins/configurepackage/configurepackage.go +++ b/agent/plugins/configurepackage/configurepackage.go @@ -16,6 +16,7 @@ package configurepackage import ( + "encoding/json" "errors" "fmt" "regexp" @@ -73,6 +74,30 @@ type ConfigurePackagePluginInput struct { Repository string `json:"repository"` } +//Unpacker helper for handling additionalParameters +type Unpacker struct { + Data map[string]interface{} +} + +//UnmarshalJSON should do something +func (u *Unpacker) UnmarshalJSON(b []byte) error { + + err := json.Unmarshal(b, &u.Data) + if err != nil { + return err + } + + for _, v := range u.Data { + switch v.(type) { + case map[string]interface{}: + u.Data["additionalArguments"] = "" + default: + } + } + + return nil +} + // NewPlugin returns a new instance of the plugin. func NewPlugin() (*Plugin, error) { var plugin Plugin @@ -292,9 +317,20 @@ func getVersionToUninstall( // parseAndValidateInput marshals raw JSON and returns the result of input validation or an error func parseAndValidateInput(rawPluginInput interface{}) (*ConfigurePackagePluginInput, error) { - var input ConfigurePackagePluginInput var err error - if err = jsonutil.Remarshal(rawPluginInput, &input); err != nil { + u := &Unpacker{} + b, err := json.Marshal(rawPluginInput) + if err != nil { + return nil, fmt.Errorf("could not marshal rawPluginInput") + } + + err = json.Unmarshal(b, u) + if err != nil { + return nil, fmt.Errorf("could not Umarshal to Unpacker") + } + + var input ConfigurePackagePluginInput + if err = jsonutil.Remarshal(u, &input); err != nil { return nil, fmt.Errorf("invalid format in plugin properties %v; \nerror %v", rawPluginInput, err) } From f3634b784e9858ecfd149d4b813816a44d1f694e Mon Sep 17 00:00:00 2001 From: Deric Miguel Date: Fri, 31 Jul 2020 02:23:26 -0700 Subject: [PATCH 2/3] fix formating error reported in travis --- .../inventory/gatherers/application/dataProvider_unix_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/plugins/inventory/gatherers/application/dataProvider_unix_test.go b/agent/plugins/inventory/gatherers/application/dataProvider_unix_test.go index af51fa2de..a27570058 100644 --- a/agent/plugins/inventory/gatherers/application/dataProvider_unix_test.go +++ b/agent/plugins/inventory/gatherers/application/dataProvider_unix_test.go @@ -241,4 +241,4 @@ func TestApplicationDataWithPackageRepositoryData(t *testing.T) { data := CollectApplicationData(mockContext) assert.Equal(t, len(sampleDataParsed), len(data)) assert.NotEqual(t, len(mockData), len(data)) -} \ No newline at end of file +} From e6de99ad66de5125dbbefddce23c9098444ca9d6 Mon Sep 17 00:00:00 2001 From: Deric Miguel Date: Fri, 31 Jul 2020 02:26:11 -0700 Subject: [PATCH 3/3] gomports fix --- agent/plugins/inventory/gatherers/application/dataProvider.go | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/plugins/inventory/gatherers/application/dataProvider.go b/agent/plugins/inventory/gatherers/application/dataProvider.go index 30943dda4..e0b28126c 100644 --- a/agent/plugins/inventory/gatherers/application/dataProvider.go +++ b/agent/plugins/inventory/gatherers/application/dataProvider.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/aws/amazon-ssm-agent/agent/context" - "github.com/aws/amazon-ssm-agent/agent/plugins/configurepackage/localpackages" "github.com/aws/amazon-ssm-agent/agent/plugins/inventory/model" )