Skip to content

Commit

Permalink
Add conditional_attribute support to profile parcels
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy committed Jul 24, 2024
1 parent b35a25e commit d8e9ec6
Show file tree
Hide file tree
Showing 36 changed files with 5,478 additions and 2,631 deletions.
6 changes: 3 additions & 3 deletions gen/definitions/profile_parcels/system_remote_access.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ attributes:
- model_name: anyConnectProfileDownloadStatus
tf_name: any_connect_eap_profile_download_status
conditional_attribute:
name: anyConnectEapAuth
name: any_connect_eap_authentication_type
value: device
example: INITIALIZED
- model_name: anyConnectProfileFileName
tf_name: any_connect_eap_profile_file_name
conditional_attribute:
name: anyConnectEapAuth
name: any_connect_eap_authentication_type
value: device
example: "<form-data>"
- model_name: ipv4PoolSize
Expand All @@ -42,7 +42,7 @@ attributes:
tf_name: psk_authentication_pre_shared_key
data_path: [pskAuth]
conditional_attribute:
name: pskSelection
name: psk_authentication_type
value: group
example: Cisco123
- model_name: radiusGroupName
Expand Down
4 changes: 4 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ func parseProfileParcelAttribute(attr *YamlConfigAttribute, model gjson.Result,
attr.TfName = SnakeCase(attr.ModelName)
}

if attr.ConditionalAttribute.Name != "" {
attr.ConditionalAttribute.Name = SnakeCase(attr.ConditionalAttribute.Name)
}

if r.Get("type").String() == "object" || !r.Get("type").Exists() {
noGlobal := false

Expand Down
24 changes: 24 additions & 0 deletions gen/templates/profile_parcels/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,23 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
path := "data."
{{- range .Attributes}}
{{- if .Value}}
// if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if and (or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)) (not .Reference)}}
{{if .Variable}}
if !data.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "variable")
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", data.{{toGoName .TfName}}Variable.ValueString())
}
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if data.{{toGoName .TfName}}.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && data.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
}
} else {{else}}if !data.{{toGoName .TfName}}.IsNull(){{end}} {
body, _ = sjson.Set(body, path+"{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -187,16 +194,22 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
itemBody := ""
{{- range .Attributes}}
{{- if .Value}}
if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)}}
{{if .Variable}}
if !item.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "variable")
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", item.{{toGoName .TfName}}Variable.ValueString())
}
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if item.{{toGoName .TfName}}.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && item.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
}
} else {{else}}if !item.{{toGoName .TfName}}.IsNull(){{end}} {
itemBody, _ = sjson.Set(itemBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -213,16 +226,22 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
itemChildBody := ""
{{- range .Attributes}}
{{- if .Value}}
if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)}}
{{if .Variable}}
if !childItem.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "variable")
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", childItem.{{toGoName .TfName}}Variable.ValueString())
}
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if childItem.{{toGoName .TfName}}.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && childItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
}
} else {{else}}if !childItem.{{toGoName .TfName}}.IsNull(){{end}} {
itemChildBody, _ = sjson.Set(itemChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "global")
{{- if isListSet .}}
Expand All @@ -239,14 +258,19 @@ func (data {{camelCase .Name}}) toBody(ctx context.Context) string {
itemChildChildBody := ""
{{- range .Attributes}}
{{- if .Value}}
if true{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.Value}}{{if eq .Type "String"}}"{{end}})
}
{{- else if or (eq .Type "String") (eq .Type "Int64") (eq .Type "Float64") (eq .Type "Bool") (isListSet .)}}
{{if .Variable}}
if !childChildItem.{{toGoName .TfName}}Variable.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "variable")
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", childChildItem.{{toGoName .TfName}}Variable.ValueString())
}
} else {{end}}{{if and .DefaultValuePresent (not .ExcludeNull)}}if childChildItem.{{toGoName .TfName}}.IsNull() {
if true{{if ne .ConditionalAttribute.Name ""}} && childChildItem.{{toGoName .ConditionalAttribute.Name}}.ValueString() == "{{.ConditionalAttribute.Value}}" {{end}} {
itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.optionType", "default")
{{if or .DefaultValue .DefaultValueEmptyString}}itemChildChildBody, _ = sjson.Set(itemChildChildBody, "{{range .DataPath}}{{.}}.{{end}}{{.ModelName}}.value", {{if eq .Type "String"}}"{{end}}{{.DefaultValue}}{{if eq .Type "String"}}"{{end}}){{end}}
} else {{else}}if !childChildItem.{{toGoName .TfName}}.IsNull(){{end}} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func (data ApplicationPriorityQoSPolicy) toBody(ctx context.Context) string {
path := "data."

if !data.TargetInterfaceVariable.IsNull() {
body, _ = sjson.Set(body, path+"target.interfaces.optionType", "variable")
body, _ = sjson.Set(body, path+"target.interfaces.value", data.TargetInterfaceVariable.ValueString())
if true {
body, _ = sjson.Set(body, path+"target.interfaces.optionType", "variable")
body, _ = sjson.Set(body, path+"target.interfaces.value", data.TargetInterfaceVariable.ValueString())
}
} else if !data.TargetInterface.IsNull() {
body, _ = sjson.Set(body, path+"target.interfaces.optionType", "global")
var values []string
Expand Down
Loading

0 comments on commit d8e9ec6

Please sign in to comment.