Skip to content

Commit

Permalink
add validate tag for the purpose of required field (Azure#886)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rjtsdl authored Jul 7, 2017
1 parent 42c0908 commit 8a47cbd
Show file tree
Hide file tree
Showing 1,656 changed files with 1,292,457 additions and 358 deletions.
16 changes: 12 additions & 4 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import:
version: 4cdb38c072b86bf795d2c81de50784d9fdd6eb77
- package: github.com/spf13/pflag
version: e57e3eeb33f795204c1ca35f56c44f83227c6e66
- package: gopkg.in/go-playground/validator.v9
version: v9.4.0
- package: github.com/go-playground/universal-translator
version: v0.16.0
testImport:
- package: github.com/onsi/gomega
version: ^1.1.0
Expand Down
51 changes: 27 additions & 24 deletions pkg/api/v20170701/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"strings"
)

// The validate tag is used for validation
// Reference to gopkg.in/go-playground/validator.v9

// ResourcePurchasePlan defines resource plan as required by ARM
// for billing purposes.
type ResourcePurchasePlan struct {
Expand All @@ -18,7 +21,7 @@ type ResourcePurchasePlan struct {
// resource definition in a JSON template.
type ContainerService struct {
ID string `json:"id,omitempty"`
Location string `json:"location,omitempty"`
Location string `json:"location,omitempty" validate:"required"`
Name string `json:"name,omitempty"`
Plan *ResourcePurchasePlan `json:"plan,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Expand All @@ -30,10 +33,10 @@ type ContainerService struct {
// Properties represents the ACS cluster definition
type Properties struct {
ProvisioningState ProvisioningState `json:"provisioningState,omitempty"`
OrchestratorProfile *OrchestratorProfile `json:"orchestratorProfile,omitempty"`
MasterProfile *MasterProfile `json:"masterProfile,omitempty"`
AgentPoolProfiles []*AgentPoolProfile `json:"agentPoolProfiles,omitempty"`
LinuxProfile *LinuxProfile `json:"linuxProfile,omitempty"`
OrchestratorProfile *OrchestratorProfile `json:"orchestratorProfile,omitempty" validate:"required"`
MasterProfile *MasterProfile `json:"masterProfile,omitempty" validate:"required"`
AgentPoolProfiles []*AgentPoolProfile `json:"agentPoolProfiles,omitempty" validate:"dive,required"`
LinuxProfile *LinuxProfile `json:"linuxProfile,omitempty" validate:"required"`
WindowsProfile *WindowsProfile `json:"windowsProfile,omitempty"`
ServicePrincipalProfile *ServicePrincipalProfile `json:"servicePrincipalProfile,omitempty"`
CustomProfile *CustomProfile `json:"customProfile,omitempty"`
Expand All @@ -50,8 +53,8 @@ type Properties struct {
// <NAME> is the name of the secret.
// <VERSION> (optional) is the version of the secret (default: the latest version)
type ServicePrincipalProfile struct {
ClientID string `json:"clientId,omitempty"`
Secret string `json:"secret,omitempty"`
ClientID string `json:"clientId,omitempty" validate:"required"`
Secret string `json:"secret,omitempty" validate:"required"`
}

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

// LinuxProfile represents the Linux configuration passed to the cluster
type LinuxProfile struct {
AdminUsername string `json:"adminUsername"`
AdminUsername string `json:"adminUsername" validate:"required"`

SSH struct {
PublicKeys []struct {
KeyData string `json:"keyData"`
} `json:"publicKeys"`
} `json:"ssh"`
} `json:"publicKeys" validate:"required,len=1"`
} `json:"ssh" validate:"required"`
}

// WindowsProfile represents the Windows configuration passed to the cluster
type WindowsProfile struct {
AdminUsername string `json:"adminUsername,omitempty"`
AdminPassword string `json:"adminPassword,omitempty"`
AdminUsername string `json:"adminUsername,omitempty" validate:"required"`
AdminPassword string `json:"adminPassword,omitempty" validate:"required"`
}

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

// OrchestratorProfile contains Orchestrator properties
type OrchestratorProfile struct {
OrchestratorType OrchestratorType `json:"orchestratorType"`
OrchestratorType OrchestratorType `json:"orchestratorType" validate:"required"`
OrchestratorVersion OrchestratorVersion `json:"orchestratorVersion"`
}

// MasterProfile represents the definition of master cluster
type MasterProfile struct {
Count int `json:"count"`
DNSPrefix string `json:"dnsPrefix"`
VMSize string `json:"vmSize"`
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty"`
Count int `json:"count" validate:"required,eq=1|eq=3|eq=5"`
DNSPrefix string `json:"dnsPrefix" validate:"required"`
VMSize string `json:"vmSize" validate:"required"`
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty" validate:"min=0,max=1023"`
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
FirstConsecutiveStaticIP string `json:"firstConsecutiveStaticIP,omitempty"`
StorageProfile string `json:"storageProfile,omitempty"`
StorageProfile string `json:"storageProfile,omitempty" validate:"eq=StorageAccount|eq=ManagedDisks|len=0"`

// subnet is internal
subnet string
Expand All @@ -124,14 +127,14 @@ type MasterProfile struct {
// daemons that register with the master and offer resources to
// host applications in containers.
type AgentPoolProfile struct {
Name string `json:"name"`
Count int `json:"count"`
VMSize string `json:"vmSize"`
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty"`
Name string `json:"name" validate:"required"`
Count int `json:"count" validate:"required,min=1,max=100"`
VMSize string `json:"vmSize" validate:"required"`
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty" validate:"min=0,max=1023"`
DNSPrefix string `json:"dnsPrefix"`
FQDN string `json:"fqdn"`
Ports []int `json:"ports,omitempty"`
StorageProfile string `json:"storageProfile"`
Ports []int `json:"ports,omitempty" validate:"dive,min=1,max=65535"`
StorageProfile string `json:"storageProfile" validate:"eq=StorageAccount|eq=ManagedDisks|len=0"`
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
// OSType is the operating system type for agents
// Set as nullable to support backward compat because
Expand Down
Loading

0 comments on commit 8a47cbd

Please sign in to comment.