Skip to content

Commit 8a47cbd

Browse files
authored
add validate tag for the purpose of required field (Azure#886)
* add validate tag for the purpose of required field * import gopkg.in/go-playground/validator.v9 * apply gopkg.in/go-playground/validator.v9 for 2017-07-01 api model * add handler for validation errors
1 parent 42c0908 commit 8a47cbd

File tree

1,656 files changed

+1292457
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,656 files changed

+1292457
-358
lines changed

glide.lock

+12-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import:
3131
version: 4cdb38c072b86bf795d2c81de50784d9fdd6eb77
3232
- package: github.com/spf13/pflag
3333
version: e57e3eeb33f795204c1ca35f56c44f83227c6e66
34+
- package: gopkg.in/go-playground/validator.v9
35+
version: v9.4.0
36+
- package: github.com/go-playground/universal-translator
37+
version: v0.16.0
3438
testImport:
3539
- package: github.com/onsi/gomega
3640
version: ^1.1.0

pkg/api/v20170701/types.go

+27-24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"strings"
66
)
77

8+
// The validate tag is used for validation
9+
// Reference to gopkg.in/go-playground/validator.v9
10+
811
// ResourcePurchasePlan defines resource plan as required by ARM
912
// for billing purposes.
1013
type ResourcePurchasePlan struct {
@@ -18,7 +21,7 @@ type ResourcePurchasePlan struct {
1821
// resource definition in a JSON template.
1922
type ContainerService struct {
2023
ID string `json:"id,omitempty"`
21-
Location string `json:"location,omitempty"`
24+
Location string `json:"location,omitempty" validate:"required"`
2225
Name string `json:"name,omitempty"`
2326
Plan *ResourcePurchasePlan `json:"plan,omitempty"`
2427
Tags map[string]string `json:"tags,omitempty"`
@@ -30,10 +33,10 @@ type ContainerService struct {
3033
// Properties represents the ACS cluster definition
3134
type Properties struct {
3235
ProvisioningState ProvisioningState `json:"provisioningState,omitempty"`
33-
OrchestratorProfile *OrchestratorProfile `json:"orchestratorProfile,omitempty"`
34-
MasterProfile *MasterProfile `json:"masterProfile,omitempty"`
35-
AgentPoolProfiles []*AgentPoolProfile `json:"agentPoolProfiles,omitempty"`
36-
LinuxProfile *LinuxProfile `json:"linuxProfile,omitempty"`
36+
OrchestratorProfile *OrchestratorProfile `json:"orchestratorProfile,omitempty" validate:"required"`
37+
MasterProfile *MasterProfile `json:"masterProfile,omitempty" validate:"required"`
38+
AgentPoolProfiles []*AgentPoolProfile `json:"agentPoolProfiles,omitempty" validate:"dive,required"`
39+
LinuxProfile *LinuxProfile `json:"linuxProfile,omitempty" validate:"required"`
3740
WindowsProfile *WindowsProfile `json:"windowsProfile,omitempty"`
3841
ServicePrincipalProfile *ServicePrincipalProfile `json:"servicePrincipalProfile,omitempty"`
3942
CustomProfile *CustomProfile `json:"customProfile,omitempty"`
@@ -50,8 +53,8 @@ type Properties struct {
5053
// <NAME> is the name of the secret.
5154
// <VERSION> (optional) is the version of the secret (default: the latest version)
5255
type ServicePrincipalProfile struct {
53-
ClientID string `json:"clientId,omitempty"`
54-
Secret string `json:"secret,omitempty"`
56+
ClientID string `json:"clientId,omitempty" validate:"required"`
57+
Secret string `json:"secret,omitempty" validate:"required"`
5558
}
5659

5760
// CustomProfile specifies custom properties that are used for
@@ -62,19 +65,19 @@ type CustomProfile struct {
6265

6366
// LinuxProfile represents the Linux configuration passed to the cluster
6467
type LinuxProfile struct {
65-
AdminUsername string `json:"adminUsername"`
68+
AdminUsername string `json:"adminUsername" validate:"required"`
6669

6770
SSH struct {
6871
PublicKeys []struct {
6972
KeyData string `json:"keyData"`
70-
} `json:"publicKeys"`
71-
} `json:"ssh"`
73+
} `json:"publicKeys" validate:"required,len=1"`
74+
} `json:"ssh" validate:"required"`
7275
}
7376

7477
// WindowsProfile represents the Windows configuration passed to the cluster
7578
type WindowsProfile struct {
76-
AdminUsername string `json:"adminUsername,omitempty"`
77-
AdminPassword string `json:"adminPassword,omitempty"`
79+
AdminUsername string `json:"adminUsername,omitempty" validate:"required"`
80+
AdminPassword string `json:"adminPassword,omitempty" validate:"required"`
7881
}
7982

8083
// ProvisioningState represents the current state of container service resource.
@@ -98,19 +101,19 @@ const (
98101

99102
// OrchestratorProfile contains Orchestrator properties
100103
type OrchestratorProfile struct {
101-
OrchestratorType OrchestratorType `json:"orchestratorType"`
104+
OrchestratorType OrchestratorType `json:"orchestratorType" validate:"required"`
102105
OrchestratorVersion OrchestratorVersion `json:"orchestratorVersion"`
103106
}
104107

105108
// MasterProfile represents the definition of master cluster
106109
type MasterProfile struct {
107-
Count int `json:"count"`
108-
DNSPrefix string `json:"dnsPrefix"`
109-
VMSize string `json:"vmSize"`
110-
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty"`
110+
Count int `json:"count" validate:"required,eq=1|eq=3|eq=5"`
111+
DNSPrefix string `json:"dnsPrefix" validate:"required"`
112+
VMSize string `json:"vmSize" validate:"required"`
113+
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty" validate:"min=0,max=1023"`
111114
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
112115
FirstConsecutiveStaticIP string `json:"firstConsecutiveStaticIP,omitempty"`
113-
StorageProfile string `json:"storageProfile,omitempty"`
116+
StorageProfile string `json:"storageProfile,omitempty" validate:"eq=StorageAccount|eq=ManagedDisks|len=0"`
114117

115118
// subnet is internal
116119
subnet string
@@ -124,14 +127,14 @@ type MasterProfile struct {
124127
// daemons that register with the master and offer resources to
125128
// host applications in containers.
126129
type AgentPoolProfile struct {
127-
Name string `json:"name"`
128-
Count int `json:"count"`
129-
VMSize string `json:"vmSize"`
130-
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty"`
130+
Name string `json:"name" validate:"required"`
131+
Count int `json:"count" validate:"required,min=1,max=100"`
132+
VMSize string `json:"vmSize" validate:"required"`
133+
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty" validate:"min=0,max=1023"`
131134
DNSPrefix string `json:"dnsPrefix"`
132135
FQDN string `json:"fqdn"`
133-
Ports []int `json:"ports,omitempty"`
134-
StorageProfile string `json:"storageProfile"`
136+
Ports []int `json:"ports,omitempty" validate:"dive,min=1,max=65535"`
137+
StorageProfile string `json:"storageProfile" validate:"eq=StorageAccount|eq=ManagedDisks|len=0"`
135138
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
136139
// OSType is the operating system type for agents
137140
// Set as nullable to support backward compat because

0 commit comments

Comments
 (0)