From e00e2c855614fac6ff9209f4fb029cf033194635 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 12:51:14 +0200 Subject: [PATCH 1/6] added platform validation to mtad generation --- cmd/gen.go | 7 ++++--- cmd/module.go | 4 ++-- internal/artifacts/mtad.go | 31 +++++++++++++++++++++++++++---- internal/artifacts/mtad_test.go | 16 ++++++++++++++++ 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/cmd/gen.go b/cmd/gen.go index 0edaad36e..f4b6a4893 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -32,7 +32,8 @@ func init() { "the path to the MTA project; the current path is default") mtadCmd.Flags().StringVarP(&mtadCmdTrg, "target", "t", "", "the path to the MBT results folder; the current path is default") - mtadCmd.Flags().StringVarP(&mtadCmdPlatform, "platform", "p", "", "Provide MTA platform ") + mtadCmd.Flags().StringVarP(&mtadCmdPlatform, "platform", "p", "cf", + "the deployment platform; supported plaforms: cf (default), xsa, neo") // set flags of meta command metaCmd.Flags().StringVarP(&metaCmdSrc, "source", "s", "", @@ -41,8 +42,8 @@ func init() { "the path to the MBT results folder; the current path is default") metaCmd.Flags().StringVarP(&metaCmdDesc, "desc", "d", "", "the MTA descriptor; supported values: dev (development descriptor, default value) and dep (deployment descriptor)") - metaCmd.Flags().StringVarP(&metaCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + metaCmd.Flags().StringVarP(&metaCmdPlatform, "platform", "p", "cf", + "the deployment platform; supported plaforms: cf (default), xsa, neo") // set flags of mtar command mtarCmd.Flags().StringVarP(&mtarCmdSrc, "source", "s", "", diff --git a/cmd/module.go b/cmd/module.go index 2ee823612..077edb70b 100644 --- a/cmd/module.go +++ b/cmd/module.go @@ -34,7 +34,7 @@ func init() { packModuleCmd.Flags().StringVarP(&packCmdModule, "module", "m", "", "the name of the module") packModuleCmd.Flags().StringVarP(&packCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + "the deployment platform; supported plaforms: cf, xsa, neo") // set flags of command build Module buildModuleCmd.Flags().StringVarP(&buildCmdSrc, "source", "s", "", @@ -46,7 +46,7 @@ func init() { buildModuleCmd.Flags().StringVarP(&buildCmdModule, "module", "m", "", "the name of the module") buildModuleCmd.Flags().StringVarP(&buildCmdPlatform, "platform", "p", "", - "the deployment platform; supported plaforms: cf, xsa") + "the deployment platform; supported plaforms: cf, xsa, neo") } // buildModuleCmd - Build module diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 151a26261..83d01e574 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -13,6 +13,7 @@ import ( "github.com/SAP/cloud-mta/mta" "path/filepath" + "fmt" ) type mtadLoc struct { @@ -43,33 +44,55 @@ func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, er return errors.Wrap(err, "generation of the MTAD file failed when initializing the location") } + // validate platform + err = validatePlatform(platform) + if err != nil { + return err + } + + // get mta object mtaStr, err := loc.ParseFile() if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when parsing the "%v" file`, loc.GetMtaYamlFilename()) } + // get extension object if defined mtaExt, err := loc.ParseExtFile(platform) if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when parsing the "%v" file`, loc.GetMtaExtYamlPath(platform)) } + // merge mta and extension objects mta.Merge(mtaStr, mtaExt) + // init mtad object from the extended mta adaptMtadForDeployment(mtaStr, platform) return genMtad(mtaStr, &mtadLoc{target}, false, platform, yaml.Marshal) } +func validatePlatform(platform string) error { + if platform != "xsa" && platform != "cf" && platform != "neo" { + return fmt.Errorf("the %s deployment platform is not supported; supported values: cf, xsa, neo", platform) + } + return nil +} + // genMtad generates an mtad.yaml file from a mta.yaml file and a platform configuration file. func genMtad(mtaStr *mta.MTA, ep dir.ITargetArtifacts, deploymentDesc bool, platform string, marshal func(interface{}) (out []byte, err error)) error { // Create META-INF folder under the mtar folder metaPath := ep.GetMetaPath() - err := dir.CreateDirIfNotExist(metaPath) - if err != nil { - logs.Logger.Infof(`the "%v" folder already exists`, metaPath) + + // if meta folder provided, mtad will be saved in this folder, so we create it if not exists + if metaPath != "" { + err := dir.CreateDirIfNotExist(metaPath) + if err != nil { + logs.Logger.Infof(`the "%v" folder already exists`, metaPath) + } } if !deploymentDesc { - err = ConvertTypes(*mtaStr, platform) + // convert modules types according to platform + err := ConvertTypes(*mtaStr, platform) if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when converting types according to the "%v" platform`, diff --git a/internal/artifacts/mtad_test.go b/internal/artifacts/mtad_test.go index 6b5c099bf..5c77b5215 100644 --- a/internal/artifacts/mtad_test.go +++ b/internal/artifacts/mtad_test.go @@ -34,6 +34,11 @@ var _ = Describe("Mtad", func() { return "", errors.New("err") })).Should(HaveOccurred()) }) + It("Fails on platform validation", func() { + Ω(ExecuteGenMtad(getTestPath("mta"), getTestPath("resultMtad"), "ab", func() (string, error) { + return "", errors.New("err") + })).Should(HaveOccurred()) + }) It("Fails on wrong source path - parse fails", func() { Ω(ExecuteGenMtad(getTestPath("mtax"), getTestPath("resultMtad"), "cf", os.Getwd)).Should(HaveOccurred()) }) @@ -116,3 +121,14 @@ var _ = Describe("adaptMtadForDeployment", func() { Ω(mta.Parameters["hcp-deployer-version"]).ShouldNot(BeNil()) }) }) + +var _ = Describe("mtadLoc", func() { + It("GetManifestPath", func() { + loc := mtadLoc{"anyPath"} + Ω(loc.GetManifestPath()).Should(Equal("")) + }) + It("GetMtarDir", func() { + loc := mtadLoc{"anyPath"} + Ω(loc.GetMtarDir()).Should(Equal("")) + }) +}) From 8dce4c0bf89c50d520bfeddbaca31d64f3eef686 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 12:58:54 +0200 Subject: [PATCH 2/6] platform validation moved to support meta generation too --- internal/artifacts/meta.go | 1 + internal/artifacts/mtad.go | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/artifacts/meta.go b/internal/artifacts/meta.go index a056c9c7d..3723f95d7 100644 --- a/internal/artifacts/meta.go +++ b/internal/artifacts/meta.go @@ -53,6 +53,7 @@ func generateMeta(parser dir.IMtaParser, ep dir.ITargetArtifacts, targetPathGett // GenMetaInfo generates a MANIFEST.MF file and updates the build artifacts paths for deployment purposes. func GenMetaInfo(ep dir.ITargetArtifacts, targetPathGetter dir.ITargetPath, deploymentDesc bool, platform string, mtaStr *mta.MTA, modules []string, onlyModules bool) (rerr error) { + err := genMtad(mtaStr, ep, deploymentDesc, platform, yaml.Marshal) if err != nil { return errors.Wrap(err, "generation of metadata failed when generating the MTAD file") diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 83d01e574..243b0b7e1 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -44,12 +44,6 @@ func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, er return errors.Wrap(err, "generation of the MTAD file failed when initializing the location") } - // validate platform - err = validatePlatform(platform) - if err != nil { - return err - } - // get mta object mtaStr, err := loc.ParseFile() if err != nil { @@ -80,6 +74,13 @@ func validatePlatform(platform string) error { // genMtad generates an mtad.yaml file from a mta.yaml file and a platform configuration file. func genMtad(mtaStr *mta.MTA, ep dir.ITargetArtifacts, deploymentDesc bool, platform string, marshal func(interface{}) (out []byte, err error)) error { + + // validate platform + err := validatePlatform(platform) + if err != nil { + return err + } + // Create META-INF folder under the mtar folder metaPath := ep.GetMetaPath() From 15feb084c7533c60a5d68545913683f576a7c670 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 13:01:15 +0200 Subject: [PATCH 3/6] fix lint --- internal/artifacts/mtad.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 243b0b7e1..a82b8f343 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -44,7 +44,7 @@ func ExecuteGenMtad(source, target, platform string, wdGetter func() (string, er return errors.Wrap(err, "generation of the MTAD file failed when initializing the location") } - // get mta object + // get mta object mtaStr, err := loc.ParseFile() if err != nil { return errors.Wrapf(err, `generation of the MTAD file failed when parsing the "%v" file`, loc.GetMtaYamlFilename()) From b3825fee6d3a2010e73ede2e0a3213b816dc9e94 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 13:06:47 +0200 Subject: [PATCH 4/6] fix lint --- internal/artifacts/mtad.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index a82b8f343..e01c81644 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -2,18 +2,18 @@ package artifacts import ( "io/ioutil" + "fmt" "os" + "path/filepath" "github.com/pkg/errors" "gopkg.in/yaml.v2" + "github.com/SAP/cloud-mta/mta" + "github.com/SAP/cloud-mta-build-tool/internal/buildops" "github.com/SAP/cloud-mta-build-tool/internal/fs" "github.com/SAP/cloud-mta-build-tool/internal/logs" - - "github.com/SAP/cloud-mta/mta" - "path/filepath" - "fmt" ) type mtadLoc struct { From 5c5668690d1b95eca61f4fb66bfaea3617ffbb61 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 13:10:29 +0200 Subject: [PATCH 5/6] fix lint... --- internal/artifacts/mtad.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index e01c81644..6ee291759 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -1,13 +1,13 @@ package artifacts import ( + "gopkg.in/yaml.v2" "io/ioutil" "fmt" "os" "path/filepath" "github.com/pkg/errors" - "gopkg.in/yaml.v2" "github.com/SAP/cloud-mta/mta" From a151497b286aa3bad6a35718f73e2f5593339e42 Mon Sep 17 00:00:00 2001 From: Volkov Date: Thu, 21 Feb 2019 13:13:48 +0200 Subject: [PATCH 6/6] fix lint! --- internal/artifacts/mtad.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/artifacts/mtad.go b/internal/artifacts/mtad.go index 6ee291759..b3574655b 100644 --- a/internal/artifacts/mtad.go +++ b/internal/artifacts/mtad.go @@ -1,9 +1,9 @@ package artifacts import ( + "fmt" "gopkg.in/yaml.v2" "io/ioutil" - "fmt" "os" "path/filepath"