Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy authored Jul 10, 2024
1 parent 8f37062 commit 74588c0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gen/definitions/feature_templates/cisco_sig_credentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ attributes:
- model_name: organization
tf_name: zscaler_organization
exclude_ignore: true
requires_const_and_var: true
example: org1
- model_name: partner-base-uri
tf_name: zscaler_partner_base_uri
exclude_ignore: true
requires_const_and_var: true
example: abc
- model_name: username
tf_name: zscaler_username
exclude_ignore: true
requires_const_and_var: true
example: user1
- model_name: password
tf_name: zscaler_password
exclude_ignore: true
requires_const_and_var: true
example: password123
- model_name: cloud-gateway
tf_name: zscaler_cloud_name
Expand All @@ -26,14 +30,17 @@ attributes:
- model_name: partner-id
tf_name: zscaler_partner_username
exclude_ignore: true
requires_const_and_var: true
example: partner1
- model_name: partner-secret
tf_name: zscaler_partner_password
exclude_ignore: true
requires_const_and_var: true
example: password123
- model_name: partner-key
tf_name: zscaler_partner_api_key
exclude_ignore: true
requires_const_and_var: true
example: key123
- model_name: api-key
tf_name: umbrella_api_key
Expand Down
1 change: 1 addition & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ type YamlConfigAttribute struct {
QueryParam bool `yaml:"query_param"`
NoAugmentConfig bool `yaml:"no_augment_config"`
TestTags []string `yaml:"test_tags"`
RequiresConstAndVar bool `yaml:"requires_const_and_var"`
}

type YamlConfigConditionalAttribute struct {
Expand Down
1 change: 1 addition & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ attribute:
query_param: bool(required=False) # Set to true if attribute is a query parameter to be included in request url
no_augment_config: bool(required=False) # If true do not augment with model data
test_tags: list(str(), required=False) # List of test tags, attribute is only included in acceptance tests if an environment variable with one of these tags is configured
requires_const_and_var: bool(required=False) # If true will include both constant and variable values in payload

conditional_attribute:
name: str() # Reference to other attribute
Expand Down
6 changes: 6 additions & 0 deletions gen/templates/feature_templates/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipObjectType", "{{.ObjectType}}")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipVariableName", data.{{toGoName .TfName}}Variable.ValueString())
{{- if .RequiresConstAndVar }}
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipValue", data.{{toGoName .TfName}}.Value{{.Type}}())
{{end}}
} else
{{- end}} if data.{{toGoName .TfName}}.IsNull() {
{{- if and (not .Mandatory) (not .ExcludeIgnore)}}
Expand All @@ -167,6 +170,9 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipObjectType", "{{.ObjectType}}")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipType", "constant")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipValue", data.{{toGoName .TfName}}.Value{{.Type}}())
{{- if and (.RequiresConstAndVar) (.Variable) }}
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}."+"vipVariableName", data.{{toGoName .TfName}}Variable.ValueString())
{{end}}
}
{{- else if and (eq .Type "Bool") (not .NodeOnlyContainer)}}
{{if .Variable}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,60 @@ func (data CiscoSIGCredentials) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipVariableName", data.ZscalerOrganizationVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipValue", data.ZscalerOrganization.ValueString())

} else if data.ZscalerOrganization.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipValue", data.ZscalerOrganization.ValueString())
body, _ = sjson.Set(body, path+"zscaler.organization."+"vipVariableName", data.ZscalerOrganizationVariable.ValueString())

}

if !data.ZscalerPartnerBaseUriVariable.IsNull() {
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipVariableName", data.ZscalerPartnerBaseUriVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipValue", data.ZscalerPartnerBaseUri.ValueString())

} else if data.ZscalerPartnerBaseUri.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipValue", data.ZscalerPartnerBaseUri.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-base-uri."+"vipVariableName", data.ZscalerPartnerBaseUriVariable.ValueString())

}

if !data.ZscalerUsernameVariable.IsNull() {
body, _ = sjson.Set(body, path+"zscaler.username."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.username."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.username."+"vipVariableName", data.ZscalerUsernameVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.username."+"vipValue", data.ZscalerUsername.ValueString())

} else if data.ZscalerUsername.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.username."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.username."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.username."+"vipValue", data.ZscalerUsername.ValueString())
body, _ = sjson.Set(body, path+"zscaler.username."+"vipVariableName", data.ZscalerUsernameVariable.ValueString())

}

if !data.ZscalerPasswordVariable.IsNull() {
body, _ = sjson.Set(body, path+"zscaler.password."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.password."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.password."+"vipVariableName", data.ZscalerPasswordVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.password."+"vipValue", data.ZscalerPassword.ValueString())

} else if data.ZscalerPassword.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.password."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.password."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.password."+"vipValue", data.ZscalerPassword.ValueString())
body, _ = sjson.Set(body, path+"zscaler.password."+"vipVariableName", data.ZscalerPasswordVariable.ValueString())

}

if !data.ZscalerCloudNameVariable.IsNull() {
Expand All @@ -146,33 +162,45 @@ func (data CiscoSIGCredentials) toBody(ctx context.Context) string {
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipVariableName", data.ZscalerPartnerUsernameVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipValue", data.ZscalerPartnerUsername.ValueString())

} else if data.ZscalerPartnerUsername.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipValue", data.ZscalerPartnerUsername.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-id."+"vipVariableName", data.ZscalerPartnerUsernameVariable.ValueString())

}

if !data.ZscalerPartnerPasswordVariable.IsNull() {
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipVariableName", data.ZscalerPartnerPasswordVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipValue", data.ZscalerPartnerPassword.ValueString())

} else if data.ZscalerPartnerPassword.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipValue", data.ZscalerPartnerPassword.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-secret."+"vipVariableName", data.ZscalerPartnerPasswordVariable.ValueString())

}

if !data.ZscalerPartnerApiKeyVariable.IsNull() {
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipType", "variableName")
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipVariableName", data.ZscalerPartnerApiKeyVariable.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipValue", data.ZscalerPartnerApiKey.ValueString())

} else if data.ZscalerPartnerApiKey.IsNull() {
} else {
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipObjectType", "object")
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipType", "constant")
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipValue", data.ZscalerPartnerApiKey.ValueString())
body, _ = sjson.Set(body, path+"zscaler.partner-key."+"vipVariableName", data.ZscalerPartnerApiKeyVariable.ValueString())

}

if !data.UmbrellaApiKeyVariable.IsNull() {
Expand Down

0 comments on commit 74588c0

Please sign in to comment.