From 5061bcf3930b7a529e18ee4bc3d08f4f66645afe Mon Sep 17 00:00:00 2001 From: "Miskiewicz, Piotr" Date: Wed, 16 Jan 2019 09:01:24 +0100 Subject: [PATCH] Enhance plan schemas --- pkg/schemas/enabled_schema.go | 24 ++++++++ pkg/schemas/location_schema.go | 54 +++++++++--------- pkg/schemas/redundancy_schema.go | 20 +++++++ pkg/service/schema.go | 33 +++++++++++ pkg/service/schema_test.go | 17 ++++++ pkg/services/cosmosdb/commons_utils_test.go | 15 +++++ pkg/services/cosmosdb/cosmos-utils.go | 63 +++++++++++---------- pkg/services/cosmosdb/plan_schemas.go | 33 ++++++----- pkg/services/mysql/catalog.go | 7 ++- pkg/services/mysql/common_provision.go | 6 +- pkg/services/mysql/plan_schemas.go | 16 +++--- pkg/services/postgresql/catalog.go | 11 ++-- pkg/services/postgresql/common_provision.go | 6 +- pkg/services/postgresql/plan_schemas.go | 16 +++--- pkg/services/rediscache/plan_schemas.go | 1 + pkg/services/servicebus/plan_schemas.go | 12 ++-- pkg/services/storage/plan_schemas.go | 20 +++---- pkg/services/storage/utils.go | 3 +- 18 files changed, 238 insertions(+), 119 deletions(-) create mode 100644 pkg/schemas/enabled_schema.go create mode 100644 pkg/schemas/redundancy_schema.go create mode 100644 pkg/services/cosmosdb/commons_utils_test.go diff --git a/pkg/schemas/enabled_schema.go b/pkg/schemas/enabled_schema.go new file mode 100644 index 000000000..960aacc02 --- /dev/null +++ b/pkg/schemas/enabled_schema.go @@ -0,0 +1,24 @@ +package schemas + +import "github.com/Azure/open-service-broker-azure/pkg/service" + +const ( + // EnabledParamString defines "enabled" value + EnabledParamString = "enabled" + // DisabledParamString defines "enabled" value + DisabledParamString = "disabled" +) + +// EnabledDisabledValues returns "enabled" and "disabled" EnumValues +func EnabledDisabledValues() []service.EnumValue { + return []service.EnumValue{ + { + Value: EnabledParamString, + Title: "Enabled", + }, + { + Value: DisabledParamString, + Title: "Disabled", + }, + } +} diff --git a/pkg/schemas/location_schema.go b/pkg/schemas/location_schema.go index 87ec996d4..5842c2dab 100644 --- a/pkg/schemas/location_schema.go +++ b/pkg/schemas/location_schema.go @@ -9,33 +9,33 @@ func GetLocationSchema() *service.StringPropertySchema { Title: "Location", Description: "The Azure region in which to provision" + " applicable resources.", - AllowedValues: []string{ - "australiaeast", - "australiasoutheast", - "brazilsouth", - "canadacentral", - "canadaeast", - "centralindia", - "centralus", - "eastasia", - "eastus", - "eastus2", - "japaneast", - "japanwest", - "koreacentral", - "koreasouth", - "northcentralus", - "northeurope", - "southcentralus", - "southeastasia", - "southindia", - "uksouth", - "ukwest", - "westcentralus", - "westeurope", - "westindia", - "westus", - "westus2", + OneOf: []service.EnumValue{ + {Value: "australiaeast", Title: "Australia East"}, + {Value: "australiasoutheast", Title: "Australia Southeast"}, + {Value: "brazilsouth", Title: "Brazil South"}, + {Value: "canadacentral", Title: "Canada Central"}, + {Value: "canadaeast", Title: "Canada East"}, + {Value: "centralindia", Title: "Central India"}, + {Value: "centralus", Title: "Central US"}, + {Value: "eastasia", Title: "East Asia"}, + {Value: "eastus", Title: "East US"}, + {Value: "eastus2", Title: "East US 2"}, + {Value: "japaneast", Title: "Japan East"}, + {Value: "japanwest", Title: "Japan West"}, + {Value: "koreacentral", Title: "Korea Central"}, + {Value: "koreasouth", Title: "Korea South"}, + {Value: "northcentralus", Title: "North Central US"}, + {Value: "northeurope", Title: "North Europe"}, + {Value: "southcentralus", Title: "South Central US"}, + {Value: "southeastasia", Title: "Southeast Asia"}, + {Value: "southindia", Title: "South India"}, + {Value: "uksouth", Title: "UK South"}, + {Value: "ukwest", Title: "UK West"}, + {Value: "westcentralus", Title: "West Central US"}, + {Value: "westeurope", Title: "West Europe"}, + {Value: "westindia", Title: "West India"}, + {Value: "westus", Title: "West US"}, + {Value: "westus2", Title: "West US 2"}, }, } } diff --git a/pkg/schemas/redundancy_schema.go b/pkg/schemas/redundancy_schema.go new file mode 100644 index 000000000..d018f911c --- /dev/null +++ b/pkg/schemas/redundancy_schema.go @@ -0,0 +1,20 @@ +package schemas + +import "github.com/Azure/open-service-broker-azure/pkg/service" + +// LocalRedundancy provides an EnumValue slice with "local" value. +func LocalRedundancy() []service.EnumValue { + return []service.EnumValue{{ + Value: "local", + Title: "Local", + }} +} + +// LocalAndGeoRedundancy provides an EnumValue slice with +// "local" and "geo" value. +func LocalAndGeoRedundancy() []service.EnumValue { + return []service.EnumValue{ + {Value: "local", Title: "Local"}, + {Value: "geo", Title: "Geo"}, + } +} diff --git a/pkg/service/schema.go b/pkg/service/schema.go index d6a61fb72..06b28d48a 100644 --- a/pkg/service/schema.go +++ b/pkg/service/schema.go @@ -112,6 +112,7 @@ type StringPropertySchema struct { AllowedPattern string `json:"pattern,omitempty"` // nolint: lll CustomPropertyValidator CustomStringPropertyValidator `json:"-"` DefaultValue string `json:"default,omitempty"` // nolint: lll + OneOf []EnumValue `json:"oneOf,omitempty"` // nolint: lll } // MarshalJSON provides functionality to marshal a StringPropertySchema to JSON @@ -163,6 +164,18 @@ func (s StringPropertySchema) validate( return NewValidationError(context, "field value is invalid") } } + if len(s.OneOf) > 0 { + var found bool + for _, allowedValue := range s.OneOf { + if val == allowedValue.Value { + found = true + break + } + } + if !found { + return NewValidationError(context, "field value is invalid") + } + } if s.AllowedPattern != "" { pattern := regexp.MustCompile(s.AllowedPattern) if !pattern.MatchString(val) { @@ -175,6 +188,26 @@ func (s StringPropertySchema) validate( return nil } +// EnumValue represents an enum item in the oneOf JSON schema collection +type EnumValue struct { + Value string + Title string +} + +// MarshalJSON provides functionality to marshal an EnumValue to JSON +// according to JSON schema definition. +func (v EnumValue) MarshalJSON() ([]byte, error) { + return json.Marshal( + struct { + Enum []string `json:"enum"` + Title string `json:"title"` + }{ + Title: v.Title, + Enum: []string{v.Value}, + }, + ) +} + // CustomIntPropertyValidator is a function type that describes the signature // for functions that provide custom validation logic for integer properties. type CustomIntPropertyValidator func(context string, value int64) error diff --git a/pkg/service/schema_test.go b/pkg/service/schema_test.go index d28f990a4..80ef1783f 100644 --- a/pkg/service/schema_test.go +++ b/pkg/service/schema_test.go @@ -100,6 +100,23 @@ func TestValidateInputParametersSchema(t *testing.T) { assert.Nil(t, err) } +func TestValidateInputParameterSchemaWithOneOfField(t *testing.T) { + ips := InputParametersSchema{ + PropertySchemas: map[string]PropertySchema{ + "foo": StringPropertySchema{ + OneOf: []EnumValue{{Value: "bar", Title: ""}, {Value: "bat", Title: ""}}, + }, + }, + } + + assert.NotNil(t, ips.Validate(map[string]interface{}{ + "foo": "wrong", + })) + assert.Nil(t, ips.Validate(map[string]interface{}{ + "foo": "bar", + })) +} + func TestStringPropertySchemaToJSON(t *testing.T) { fooSps := StringPropertySchema{ Title: "bar", diff --git a/pkg/services/cosmosdb/commons_utils_test.go b/pkg/services/cosmosdb/commons_utils_test.go new file mode 100644 index 000000000..26ab475b3 --- /dev/null +++ b/pkg/services/cosmosdb/commons_utils_test.go @@ -0,0 +1,15 @@ +package cosmosdb + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestValidateReadLocations(t *testing.T) { + assert.NotNil(t, validateReadLocations("", []string{"ukwest", "no-existing"})) + assert.NotNil(t, validateReadLocations("", []string{"ukwest", "ukwest"})) + + assert.Nil(t, validateReadLocations("", []string{"ukwest", "eastasia"})) + assert.Nil(t, validateReadLocations("", []string{})) +} diff --git a/pkg/services/cosmosdb/cosmos-utils.go b/pkg/services/cosmosdb/cosmos-utils.go index 351a9d07c..4eb32aee0 100644 --- a/pkg/services/cosmosdb/cosmos-utils.go +++ b/pkg/services/cosmosdb/cosmos-utils.go @@ -250,10 +250,14 @@ func validateReadLocations( context string, regions []string, ) error { + allowedLocations := make(map[string]bool) + for _, item := range allowedReadLocations() { + allowedLocations[item.Value] = true + } occurred := make(map[string]bool) for i := range regions { region := regions[i] - if !allowedReadLocations[region] { + if !allowedLocations[region] { return service.NewValidationError( fmt.Sprintf("%s.readRegions", context), fmt.Sprintf("given read region %s is not allowed", region), @@ -274,34 +278,35 @@ func validateReadLocations( } // Allowed CosmosDB read locations, it is different from Azure regions. -// We use a map here to record all allowed regions. -var allowedReadLocations = map[string]bool{ - "westus2": true, - "westus": true, - "southcentralus": true, - "centralus": true, - "northcentralus": true, - "canadacentral": true, - "eastus": true, - "eastus2": true, - "canadaeast": true, - "brazilsouth": true, - "northeurope": true, - "ukwest": true, - "uksouth": true, - "francecentral": true, - "westeurope": true, - "westindia": true, - "centralindia": true, - "southindia": true, - "southeastasia": true, - "eastasia": true, - "koreacentral": true, - "koreasouth": true, - "japaneast": true, - "japanwest": true, - "australiasoutheast": true, - "australiaeast": true, +func allowedReadLocations() []service.EnumValue { + return []service.EnumValue{ + {Value: "westus2", Title: "West US 2"}, + {Value: "westus", Title: "West US"}, + {Value: "southcentralus", Title: "South Central US"}, + {Value: "centralus", Title: "Central US"}, + {Value: "northcentralus", Title: "North Central US"}, + {Value: "canadacentral", Title: "Canada Central"}, + {Value: "eastus", Title: "East US"}, + {Value: "eastus2", Title: "East US 2"}, + {Value: "canadaeast", Title: "Canada East"}, + {Value: "brazilsouth", Title: "Brazil South"}, + {Value: "northeurope", Title: "North Europe"}, + {Value: "ukwest", Title: "UK West"}, + {Value: "uksouth", Title: "UK South"}, + {Value: "francecentral", Title: "France Central"}, + {Value: "westeurope", Title: "West Europe"}, + {Value: "westindia", Title: "West India"}, + {Value: "centralindia", Title: "Central India"}, + {Value: "southindia", Title: "South India"}, + {Value: "southeastasia", Title: "Southeast Asia"}, + {Value: "eastasia", Title: "East Asia"}, + {Value: "koreacentral", Title: "Korea Central"}, + {Value: "koreasouth", Title: "Korea South"}, + {Value: "japaneast", Title: "Japan East"}, + {Value: "japanwest", Title: "Japan West"}, + {Value: "australiasoutheast", Title: "Australia Southeast"}, + {Value: "australiaeast", Title: "Australia East"}, + } } func (c *cosmosAccountManager) buildGoTemplateParamsCore( diff --git a/pkg/services/cosmosdb/plan_schemas.go b/pkg/services/cosmosdb/plan_schemas.go index ed14968cc..4cf237f5a 100644 --- a/pkg/services/cosmosdb/plan_schemas.go +++ b/pkg/services/cosmosdb/plan_schemas.go @@ -28,14 +28,17 @@ func generateUpdatingParamsSchema() service.InputParametersSchema { " will be synchronized across these regions.", DefaultValue: []interface{}{}, CustomPropertyValidator: readLocationsValidator, + ItemsSchema: &service.StringPropertySchema{ + OneOf: allowedReadLocations(), + }, }, "autoFailoverEnabled": &service.StringPropertySchema{ Title: "Auto failover enabled", Description: "Specifies if you want Cosmos DB to perform" + " automatic failover of the write region to one of" + " the read regions in the rare event of a data center outage.", - DefaultValue: "disabled", - AllowedValues: []string{"enabled", "disabled"}, + DefaultValue: "disabled", + OneOf: schemas.EnabledDisabledValues(), }, "ipFilters": &service.ObjectPropertySchema{ Title: "IP filters", @@ -45,16 +48,16 @@ func generateUpdatingParamsSchema() service.InputParametersSchema { Title: "Allow access from Azure", Description: "Specifies if Azure Services should be able to access" + " the CosmosDB account.", - AllowedValues: []string{"enabled", "disabled"}, - DefaultValue: "enabled", + OneOf: schemas.EnabledDisabledValues(), + DefaultValue: schemas.EnabledParamString, }, "allowAccessFromPortal": &service.StringPropertySchema{ Title: "Allow access From Portal", Description: "Specifies if the Azure Portal should be able to" + " access the CosmosDB account. If `allowAccessFromAzure` is" + " set to enabled, this value is ignored.", - AllowedValues: []string{"enabled", "disabled"}, - DefaultValue: "enabled", + OneOf: schemas.EnabledDisabledValues(), + DefaultValue: schemas.EnabledParamString, }, "allowedIPRanges": &service.ArrayPropertySchema{ Title: "Allowed IP ranges", @@ -67,7 +70,7 @@ func generateUpdatingParamsSchema() service.InputParametersSchema { }, }, DefaultValue: map[string]interface{}{ - "allowAccessFromAzure": "enabled", + "allowAccessFromAzure": schemas.EnabledParamString, }, }, "consistencyPolicy": &service.ObjectPropertySchema{ @@ -81,12 +84,12 @@ func generateUpdatingParamsSchema() service.InputParametersSchema { Title: "Default consistency level", Description: "The default consistency level and" + " configuration settings of the Cosmos DB account.", - AllowedValues: []string{ - "Eventual", - "Session", - "BoundedStaleness", - "Strong", - "ConsistentPrefix", + OneOf: []service.EnumValue{ + {Value: "Eventual", Title: "Eventual"}, + {Value: "Session", Title: "Session"}, + {Value: "BoundedStaleness", Title: "Bounded staleness"}, + {Value: "Strong", Title: "Strong"}, + {Value: "ConsistentPrefix", Title: "Consistent prefix"}, }, }, "boundedStaleness": &service.ObjectPropertySchema{ @@ -136,8 +139,8 @@ func generateProvisioningParamsSchema() service.InputParametersSchema { Title: "Multiple write regions enabled", Description: "Specifies if you want the account to write " + "in multiple regions.", - AllowedValues: []string{"enabled", "disabled"}, - DefaultValue: "disabled", + OneOf: schemas.EnabledDisabledValues(), + DefaultValue: schemas.DisabledParamString, }, } sharedSchema := generateUpdatingParamsSchema() diff --git a/pkg/services/mysql/catalog.go b/pkg/services/mysql/catalog.go index eaa125155..51f3b7d37 100644 --- a/pkg/services/mysql/catalog.go +++ b/pkg/services/mysql/catalog.go @@ -1,6 +1,7 @@ package mysql import ( + "github.com/Azure/open-service-broker-azure/pkg/schemas" "github.com/Azure/open-service-broker-azure/pkg/service" ) @@ -13,7 +14,7 @@ func createBasicPlan( allowedCores: []int64{1, 2}, defaultCores: 1, maxStorage: 1024, - allowedBackupRedundancy: []string{"local"}, + allowedBackupRedundancy: schemas.LocalRedundancy(), } return service.PlanProperties{ @@ -49,7 +50,7 @@ func createGPPlan( allowedCores: []int64{2, 4, 8, 16, 32}, defaultCores: 2, maxStorage: 2048, - allowedBackupRedundancy: []string{"local", "geo"}, + allowedBackupRedundancy: schemas.LocalAndGeoRedundancy(), } extendedPlanData := map[string]interface{}{ "tierDetails": td, @@ -90,7 +91,7 @@ func createMemoryOptimizedPlan( allowedCores: []int64{2, 4, 8, 16}, defaultCores: 2, maxStorage: 2048, - allowedBackupRedundancy: []string{"local", "geo"}, + allowedBackupRedundancy: schemas.LocalAndGeoRedundancy(), } extendedPlanData := map[string]interface{}{ "tierDetails": td, diff --git a/pkg/services/mysql/common_provision.go b/pkg/services/mysql/common_provision.go index 27da41fc5..3171a3c37 100644 --- a/pkg/services/mysql/common_provision.go +++ b/pkg/services/mysql/common_provision.go @@ -11,10 +11,8 @@ import ( ) const ( - enabledParamString = "enabled" - disabledParamString = "disabled" - enabledARMString = "Enabled" - disabledARMString = "Disabled" + enabledARMString = "Enabled" + disabledARMString = "Disabled" ) func buildGoTemplateParameters( diff --git a/pkg/services/mysql/plan_schemas.go b/pkg/services/mysql/plan_schemas.go index c9c8210de..2e61a5629 100644 --- a/pkg/services/mysql/plan_schemas.go +++ b/pkg/services/mysql/plan_schemas.go @@ -16,7 +16,7 @@ type tierDetails struct { allowedCores []int64 defaultCores int64 maxStorage int64 - allowedBackupRedundancy []string + allowedBackupRedundancy []service.EnumValue } func (t *tierDetails) getSku(pp service.ProvisioningParameters) string { @@ -39,10 +39,10 @@ func generateProvisioningParamsSchema( ips.RequiredProperties = append(ips.RequiredProperties, "resourceGroup") ips.PropertySchemas["resourceGroup"] = schemas.GetResourceGroupSchema() ips.PropertySchemas["backupRedundancy"] = &service.StringPropertySchema{ - Title: "Backup redundancy", - Description: "Specifies the backup redundancy", - AllowedValues: td.allowedBackupRedundancy, - DefaultValue: "local", + Title: "Backup redundancy", + Description: "Specifies the backup redundancy", + OneOf: td.allowedBackupRedundancy, + DefaultValue: "local", } ips.PropertySchemas["tags"] = &service.ObjectPropertySchema{ Title: "Tags", @@ -83,8 +83,8 @@ func generateUpdatingParamsSchema( Title: "SSL enforcement", Description: "Specifies whether the server requires the use of TLS" + " when connecting. Left unspecified, SSL will be enforced", - AllowedValues: []string{enabledParamString, disabledParamString}, - DefaultValue: enabledParamString, + OneOf: schemas.EnabledDisabledValues(), + DefaultValue: schemas.EnabledParamString, }, "firewallRules": &service.ArrayPropertySchema{ Title: "Firewall rules", @@ -133,7 +133,7 @@ func isGeoRedundentBackup(pp service.ProvisioningParameters) bool { } func isSSLRequired(pp service.ProvisioningParameters) bool { - return pp.GetString("sslEnforcement") != disabledParamString + return pp.GetString("sslEnforcement") != schemas.DisabledParamString } func ipValidator(context, value string) error { diff --git a/pkg/services/postgresql/catalog.go b/pkg/services/postgresql/catalog.go index 3bbc32d46..ed1a0bbf6 100644 --- a/pkg/services/postgresql/catalog.go +++ b/pkg/services/postgresql/catalog.go @@ -1,6 +1,9 @@ package postgresql -import "github.com/Azure/open-service-broker-azure/pkg/service" +import ( + "github.com/Azure/open-service-broker-azure/pkg/schemas" + "github.com/Azure/open-service-broker-azure/pkg/service" +) func createBasicPlan( planID string, @@ -13,7 +16,7 @@ func createBasicPlan( allowedCores: []int64{1, 2}, defaultCores: 1, maxStorage: 1024, - allowedBackupRedundancy: []string{"local"}, + allowedBackupRedundancy: schemas.LocalRedundancy(), } return service.PlanProperties{ @@ -54,7 +57,7 @@ func createGPPlan( allowedCores: []int64{2, 4, 8, 16, 32}, defaultCores: 2, maxStorage: 2048, - allowedBackupRedundancy: []string{"local", "geo"}, + allowedBackupRedundancy: schemas.LocalAndGeoRedundancy(), } extendedPlanData := map[string]interface{}{ @@ -101,7 +104,7 @@ func createMemoryOptimizedPlan( allowedCores: []int64{2, 4, 8, 16}, defaultCores: 2, maxStorage: 2048, - allowedBackupRedundancy: []string{"local", "geo"}, + allowedBackupRedundancy: schemas.LocalAndGeoRedundancy(), } extendedPlanData := map[string]interface{}{ diff --git a/pkg/services/postgresql/common_provision.go b/pkg/services/postgresql/common_provision.go index 19f21d0bd..69f2d0d39 100644 --- a/pkg/services/postgresql/common_provision.go +++ b/pkg/services/postgresql/common_provision.go @@ -11,10 +11,8 @@ import ( ) const ( - enabledParamString = "enabled" - disabledParamString = "disabled" - enabledARMString = "Enabled" - disabledARMString = "Disabled" + enabledARMString = "Enabled" + disabledARMString = "Disabled" ) func getAvailableServerName( diff --git a/pkg/services/postgresql/plan_schemas.go b/pkg/services/postgresql/plan_schemas.go index a3e519c43..6cd3e89d4 100644 --- a/pkg/services/postgresql/plan_schemas.go +++ b/pkg/services/postgresql/plan_schemas.go @@ -16,7 +16,7 @@ type tierDetails struct { allowedCores []int64 defaultCores int64 maxStorage int64 - allowedBackupRedundancy []string + allowedBackupRedundancy []service.EnumValue } func (t *tierDetails) getSku(pp service.ProvisioningParameters) string { @@ -40,10 +40,10 @@ func generateProvisioningParamsSchema( ips.RequiredProperties = append(ips.RequiredProperties, "resourceGroup") ips.PropertySchemas["resourceGroup"] = schemas.GetResourceGroupSchema() ips.PropertySchemas["backupRedundancy"] = &service.StringPropertySchema{ - Title: "Backup redundancy", - Description: "Specifies the backup redundancy", - AllowedValues: td.allowedBackupRedundancy, - DefaultValue: "local", + Title: "Backup redundancy", + Description: "Specifies the backup redundancy", + OneOf: td.allowedBackupRedundancy, + DefaultValue: "local", } ips.PropertySchemas["tags"] = &service.ObjectPropertySchema{ Title: "Tags", @@ -87,8 +87,8 @@ func generateUpdatingParamsSchema( Title: "SSL enforcement", Description: "Specifies whether the server requires the use of TLS" + " when connecting. Left unspecified, SSL will be enforced", - AllowedValues: []string{enabledParamString, disabledParamString}, - DefaultValue: enabledParamString, + OneOf: schemas.EnabledDisabledValues(), + DefaultValue: schemas.DisabledParamString, }, "firewallRules": &service.ArrayPropertySchema{ Title: "Firewall rules", @@ -137,7 +137,7 @@ func isGeoRedundentBackup(pp service.ProvisioningParameters) bool { } func isSSLRequired(pp service.ProvisioningParameters) bool { - return pp.GetString("sslEnforcement") != disabledParamString + return pp.GetString("sslEnforcement") != schemas.DisabledParamString } func ipValidator(context, value string) error { diff --git a/pkg/services/rediscache/plan_schemas.go b/pkg/services/rediscache/plan_schemas.go index 23643f1e2..563f080c3 100644 --- a/pkg/services/rediscache/plan_schemas.go +++ b/pkg/services/rediscache/plan_schemas.go @@ -25,6 +25,7 @@ func (pd planDetail) getProvisioningParamsSchema() service.InputParametersSchema Title: "Enable non-SSL port", Description: "Specifies whether the non-ssl Redis server port (6379) is enabled.", AllowedValues: []string{"enabled", "disabled"}, + OneOf: schemas.EnabledDisabledValues(), DefaultValue: "disabled", }, "skuCapacity": &service.IntPropertySchema{ diff --git a/pkg/services/servicebus/plan_schemas.go b/pkg/services/servicebus/plan_schemas.go index 0e3abfe9c..5234f2dde 100644 --- a/pkg/services/servicebus/plan_schemas.go +++ b/pkg/services/servicebus/plan_schemas.go @@ -78,11 +78,13 @@ func generateTopicBindingParamsSchema() service.InputParametersSchema { return service.InputParametersSchema{ PropertySchemas: map[string]service.PropertySchema{ "subscriptionNeeded": &service.StringPropertySchema{ - Title: "Subscription Needed", - Description: "Specifies whether to create a subscription in the topic." + - " Valid values are [\"yes\", \"no\"]. ", - AllowedValues: []string{"yes", "no"}, - DefaultValue: "yes", + Title: "Subscription Needed", + Description: "Specifies whether to create a subscription in the topic.", + OneOf: []service.EnumValue{ + {Value: "yes", Title: "Yes"}, + {Value: "no", Title: "No"}, + }, + DefaultValue: "yes", }, }, } diff --git a/pkg/services/storage/plan_schemas.go b/pkg/services/storage/plan_schemas.go index ffdec0fbf..a619e7a98 100644 --- a/pkg/services/storage/plan_schemas.go +++ b/pkg/services/storage/plan_schemas.go @@ -7,10 +7,8 @@ import ( ) const ( - enabled = "enabled" - disabled = "disabled" - hot = "Hot" - cool = "Cool" + hot = "Hot" + cool = "Cool" ) // nolint: lll @@ -30,10 +28,10 @@ func generateProvisioningParamsSchema(serviceName string) service.InputParameter "resourceGroup": schemas.GetResourceGroupSchema(), "location": schemas.GetLocationSchema(), "enableNonHttpsTraffic": &service.StringPropertySchema{ - Title: "Enable non-https traffic", - Description: "Specify whether non-https traffic is enabled", - DefaultValue: disabled, - AllowedValues: []string{enabled, disabled}, + Title: "Enable non-https traffic", + Description: "Specify whether non-https traffic is enabled", + DefaultValue: schemas.DisabledParamString, + OneOf: schemas.EnabledDisabledValues(), }, "tags": &service.ObjectPropertySchema{ Title: "Tags", @@ -80,9 +78,9 @@ func generateUpdatingParamsSchema(serviceName string) service.InputParametersSch ips := service.InputParametersSchema{ PropertySchemas: map[string]service.PropertySchema{ "enableNonHttpsTraffic": &service.StringPropertySchema{ - Title: "Enable non-https traffic", - Description: "Specify whether non-https traffic is enabled", - AllowedValues: []string{enabled, disabled}, + Title: "Enable non-https traffic", + Description: "Specify whether non-https traffic is enabled", + OneOf: schemas.EnabledDisabledValues(), }, "tags": &service.ObjectPropertySchema{ Title: "Tags", diff --git a/pkg/services/storage/utils.go b/pkg/services/storage/utils.go index 7691b0c37..bc9ec37a7 100644 --- a/pkg/services/storage/utils.go +++ b/pkg/services/storage/utils.go @@ -2,6 +2,7 @@ package storage import ( "github.com/Azure/azure-sdk-for-go/storage" + "github.com/Azure/open-service-broker-azure/pkg/schemas" "github.com/Azure/open-service-broker-azure/pkg/service" ) @@ -16,7 +17,7 @@ func buildGoTemplate( goTemplateParams := map[string]interface{}{ "name": dt.StorageAccountName, "location": location, - "supportHttpsTrafficOnly": nonHTTPSEnabled == disabled, + "supportHttpsTrafficOnly": nonHTTPSEnabled == schemas.DisabledParamString, "accountType": parameter.GetString("accountType"), }