From a878836406d8183688a7bc890f1bb2874e1c1355 Mon Sep 17 00:00:00 2001 From: Mike Larah Date: Fri, 17 Jan 2020 17:53:28 +0000 Subject: [PATCH] Add allowed values for cnab actions --- pkg/generator/generator.go | 7 +++++++ pkg/generator/testdata/azuredeploy-simple.json | 6 ++++++ pkg/generator/testdata/azuredeploy.json | 6 ++++++ pkg/generator/testdata/bundle.json | 5 +++++ pkg/template/cnab-arm-driver-template.go | 7 ++++--- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pkg/generator/generator.go b/pkg/generator/generator.go index ff8019b..3c5ca35 100644 --- a/pkg/generator/generator.go +++ b/pkg/generator/generator.go @@ -44,10 +44,17 @@ func GenerateTemplate(options GenerateTemplateOptions) error { bundleName := bundle.Name bundleTag, err := getBundleTag(bundle) + bundleActions := make([]string, 0, len(bundle.Actions)+3) + defaultActions := []string{"install", "upgrade", "uninstall"} + bundleActions = append(bundleActions, defaultActions...) + for action := range bundle.Actions { + bundleActions = append(bundleActions, action) + } generatedTemplate := template.NewCnabArmDriverTemplate( bundleName, bundleTag, + bundleActions, template.CnabArmDriverImageName, options.Version, options.Simplify) diff --git a/pkg/generator/testdata/azuredeploy-simple.json b/pkg/generator/testdata/azuredeploy-simple.json index 5496af0..ebc566d 100644 --- a/pkg/generator/testdata/azuredeploy-simple.json +++ b/pkg/generator/testdata/azuredeploy-simple.json @@ -14,6 +14,12 @@ "cnab_action": { "type": "string", "defaultValue": "install", + "allowedValues": [ + "install", + "upgrade", + "uninstall", + "endjin.customAction" + ], "metadata": { "description": "The name of the action to be performed on the application instance." } diff --git a/pkg/generator/testdata/azuredeploy.json b/pkg/generator/testdata/azuredeploy.json index d8aa6b1..5e16b6e 100644 --- a/pkg/generator/testdata/azuredeploy.json +++ b/pkg/generator/testdata/azuredeploy.json @@ -54,6 +54,12 @@ "cnab_action": { "type": "string", "defaultValue": "install", + "allowedValues": [ + "install", + "upgrade", + "uninstall", + "endjin.customAction" + ], "metadata": { "description": "The name of the action to be performed on the application instance." } diff --git a/pkg/generator/testdata/bundle.json b/pkg/generator/testdata/bundle.json index 377f004..7cdf0df 100644 --- a/pkg/generator/testdata/bundle.json +++ b/pkg/generator/testdata/bundle.json @@ -1,4 +1,9 @@ { + "actions": { + "endjin.customAction": { + "description": "A custom action" + } + }, "credentials": { "password": { "description": "A secret password", diff --git a/pkg/template/cnab-arm-driver-template.go b/pkg/template/cnab-arm-driver-template.go index 810e2c5..3de38db 100644 --- a/pkg/template/cnab-arm-driver-template.go +++ b/pkg/template/cnab-arm-driver-template.go @@ -12,7 +12,7 @@ const ( ) // NewCnabArmDriverTemplate creates a new instance of Template for running a CNAB bundle using cnab-azure-driver -func NewCnabArmDriverTemplate(bundleName string, bundleTag string, containerImageName string, containerImageVersion string, simplify bool) Template { +func NewCnabArmDriverTemplate(bundleName string, bundleTag string, bundleActions []string, containerImageName string, containerImageVersion string, simplify bool) Template { resources := []Resource{ { @@ -141,8 +141,9 @@ func NewCnabArmDriverTemplate(bundleName string, bundleTag string, containerImag parameters := map[string]Parameter{ "cnab_action": { - Type: "string", - DefaultValue: "install", + Type: "string", + DefaultValue: bundleActions[0], + AllowedValues: bundleActions, Metadata: &Metadata{ Description: "The name of the action to be performed on the application instance.", },