From 5ef25eea3fd2588661c422dc3cd59a1eee4f5f02 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Mon, 30 Mar 2020 09:50:41 -0500 Subject: [PATCH] Split mixin arguments Do not assume that mixin arguments and flags should be passed as a quoted string to the cli. Require that they are wrapped in quotes instead and otherwise split on space to pass them separately. See https://github.com/deislabs/porter/pull/931 for how this works. --- go.mod | 2 +- go.sum | 9 +++++++++ pkg/helm/action.go | 38 +++++++++++++++++++++++++++++--------- pkg/helm/execute_test.go | 4 ++-- pkg/helm/version.go | 3 ++- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 9bb6762..232cc73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module get.porter.sh/mixin/helm go 1.13 require ( - get.porter.sh/porter v0.22.1-beta.1 + get.porter.sh/porter v0.25.0-beta.1 github.com/dsnet/compress v0.0.1 // indirect github.com/ghodss/yaml v1.0.0 github.com/gobuffalo/packr/v2 v2.7.1 diff --git a/go.sum b/go.sum index d1953d0..fee1410 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ cloud.google.com/go v0.39.0 h1:UgQP9na6OTfp4dsAiz/eFpFA1C6tPdH5wiRdi19tuMw= cloud.google.com/go v0.39.0/go.mod h1:rVLT6fkc8chs9sfPtFc1SBH6em7n+ZoXaG+87tDISts= get.porter.sh/porter v0.22.1-beta.1 h1:0s2k+RIYj+r3DC4dhKQSgFKlGh4UIUTt2xJSPxVFizM= get.porter.sh/porter v0.22.1-beta.1/go.mod h1:JwT78lFVY8PUo+H0GBF3XcR5NMeXDK0bZTz17Gzyr9g= +get.porter.sh/porter v0.25.0-beta.1 h1:1LV6fAw41pwysJfHgD0vCrIJqlAkcMi7Hpj3B0GiCbs= +get.porter.sh/porter v0.25.0-beta.1/go.mod h1:UgEUpCJsgRmlzJgyloGodL/nCVbmGWPeuR1xN/WpYo0= github.com/Azure/azure-sdk-for-go v19.1.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v10.15.5+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -28,6 +30,7 @@ github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbt github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= +github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= @@ -38,6 +41,7 @@ github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8= github.com/PaesslerAG/jsonpath v0.1.1 h1:c1/AToHQMVsduPAa4Vh6xp2U0evy4t8SWp8imEsylIk= github.com/PaesslerAG/jsonpath v0.1.1/go.mod h1:lVboNxFGal/VwW6d9JzIy56bUsYAP6tH/x80vjnCseY= +github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk= github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= @@ -50,6 +54,7 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o= github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -64,6 +69,7 @@ github.com/bugsnag/bugsnag-go v1.5.0/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqR github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE= github.com/carolynvs/datetime-printer v0.2.0/go.mod h1:p9W8ZUhmQUOVD5kiDuGXwRG65/nTkZWlLylY7s+Qw2k= github.com/carolynvs/go-plugin v1.0.1-acceptstdin/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= +github.com/cbroglie/mustache v1.0.1 h1:ivMg8MguXq/rrz2eu3tw6g3b16+PQhoTn6EZAhst2mw= github.com/cbroglie/mustache v1.0.1/go.mod h1:R/RUa+SobQ14qkP4jtx5Vke5sDytONDQXNLPY/PO69g= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4= @@ -75,6 +81,7 @@ github.com/cloudflare/cfssl v1.4.1/go.mod h1:KManx/OJPb5QY+y0+o/898AMcM128sF0bUR github.com/cloudflare/go-metrics v0.0.0-20151117154305-6a9aea36fb41/go.mod h1:eaZPlJWD+G9wseg1BuRXlHnjntPMrywMsyxf+LTOdP4= github.com/cloudflare/redoctober v0.0.0-20171127175943-746a508df14c/go.mod h1:6Se34jNoqrd8bTxrmJB2Bg2aoZ2CdSXonils9NsiNgo= github.com/cnabio/cnab-go v0.8.2-beta1/go.mod h1:5c4uOP6ZppR4nUGtCMAElscRiYEUi44vNQwtSAvISXk= +github.com/cnabio/cnab-go v0.9.0-beta1/go.mod h1:5c4uOP6ZppR4nUGtCMAElscRiYEUi44vNQwtSAvISXk= github.com/containerd/cgroups v0.0.0-20200108155730-918ed86e29cc/go.mod h1:6KyBUkSDshoWUZPkqlFXQzOMWNtlcJ1stduPAd2MRes= github.com/containerd/containerd v1.2.7/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= github.com/containerd/containerd v1.3.0/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= @@ -275,7 +282,9 @@ github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WT github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mmcdole/gofeed v1.0.0-beta2 h1:CjQ0ADhAwNSb08zknAkGOEYqr8zfZKfrzgk9BxpWP2E= github.com/mmcdole/gofeed v1.0.0-beta2/go.mod h1:/BF9JneEL2/flujm8XHoxUcghdTV6vvb3xx/vKyChFU= +github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf h1:sWGE2v+hO0Nd4yFU/S/mDBM5plIU8v/Qhfz41hkDIAI= github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf/go.mod h1:pasqhqstspkosTneA62Nc+2p9SOBBYAPbnmRRWPQ0V8= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= diff --git a/pkg/helm/action.go b/pkg/helm/action.go index e92ae5d..f10cbef 100644 --- a/pkg/helm/action.go +++ b/pkg/helm/action.go @@ -4,10 +4,27 @@ import ( "get.porter.sh/porter/pkg/exec/builder" ) +var _ builder.BuildableAction = Action{} var _ builder.ExecutableAction = Action{} type Action struct { - Steps []ExecuteSteps // using UnmarshalYAML so that we don't need a custom type per action + Name string + Steps []ExecuteStep // using UnmarshalYAML so that we don't need a custom type per action +} + +// MakeSteps builds a slice of Steps for data to be unmarshaled into. +func (a Action) MakeSteps() interface{} { + return &[]ExecuteStep{} +} + +// MarshalYAML converts the action back to a YAML representation +// install: +// exec: +// ... +// helm: +// ... +func (a Action) MarshalYAML() (interface{}, error) { + return map[string]interface{}{a.Name: a.Steps}, nil } // UnmarshalYAML takes any yaml in this form @@ -15,15 +32,18 @@ type Action struct { // - helm: ... // and puts the steps into the Action.Steps field func (a *Action) UnmarshalYAML(unmarshal func(interface{}) error) error { - var steps []ExecuteSteps - results, err := builder.UnmarshalAction(unmarshal, &steps) + results, err := builder.UnmarshalAction(unmarshal, a) if err != nil { return err } - for _, result := range results { - step := result.(*[]ExecuteSteps) - a.Steps = append(a.Steps, *step...) + for actionName, action := range results { + a.Name = actionName + for _, result := range action { + step := result.(*[]ExecuteStep) + a.Steps = append(a.Steps, *step...) + } + break // There is only 1 action } return nil } @@ -39,11 +59,11 @@ func (a Action) GetSteps() []builder.ExecutableStep { var _ builder.ExecutableStep = ExecuteStep{} -type ExecuteSteps struct { - ExecuteStep `yaml:"helm"` +type ExecuteStep struct { + ExecuteInstruction `yaml:"helm"` } -type ExecuteStep struct { +type ExecuteInstruction struct { Step `yaml:",inline"` Namespace string `yaml:"namespace,omitempty"` Arguments []string `yaml:"arguments,omitempty"` diff --git a/pkg/helm/execute_test.go b/pkg/helm/execute_test.go index 33f7a8b..5126716 100644 --- a/pkg/helm/execute_test.go +++ b/pkg/helm/execute_test.go @@ -47,9 +47,9 @@ func TestMixin_Execute(t *testing.T) { os.Setenv(test.ExpectedCommandEnv, "helm status mysql -o yaml") executeAction := Action{ - Steps: []ExecuteSteps{ + Steps: []ExecuteStep{ { - ExecuteStep: ExecuteStep{ + ExecuteInstruction: ExecuteInstruction{ Arguments: []string{ "status", "mysql", diff --git a/pkg/helm/version.go b/pkg/helm/version.go index 96e99fe..ada813e 100644 --- a/pkg/helm/version.go +++ b/pkg/helm/version.go @@ -3,13 +3,14 @@ package helm import ( "get.porter.sh/mixin/helm/pkg" "get.porter.sh/porter/pkg/mixin" + "get.porter.sh/porter/pkg/pkgmgmt" "get.porter.sh/porter/pkg/porter/version" ) func (m *Mixin) PrintVersion(opts version.Options) error { metadata := mixin.Metadata{ Name: "helm", - VersionInfo: mixin.VersionInfo{ + VersionInfo: pkgmgmt.VersionInfo{ Version: pkg.Version, Commit: pkg.Commit, Author: "Porter Authors",