Skip to content

Commit

Permalink
Add allowed values for cnab actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEvansLarah committed Jan 17, 2020
1 parent 5a57283 commit a878836
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/generator/testdata/azuredeploy-simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/generator/testdata/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/generator/testdata/bundle.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"actions": {
"endjin.customAction": {
"description": "A custom action"
}
},
"credentials": {
"password": {
"description": "A secret password",
Expand Down
7 changes: 4 additions & 3 deletions pkg/template/cnab-arm-driver-template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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.",
},
Expand Down

0 comments on commit a878836

Please sign in to comment.