Skip to content

Commit

Permalink
fixup! Add NAT policy specification
Browse files Browse the repository at this point in the history
  • Loading branch information
kklimonda-cl committed Oct 7, 2024
1 parent 44f730e commit 7d82836
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ type SpecParam struct {
Name *NameVariant
Description string `json:"description" yaml:"description"`
TerraformProviderConfig *SpecParamTerraformProviderConfig `json:"terraform_provider_config" yaml:"terraform_provider_config"`
IsNil bool `json:"-" yaml:"-"`
Type string `json:"type" yaml:"type"`
Default string `json:"default" yaml:"default"`
Required bool `json:"required" yaml:"required"`
Expand Down Expand Up @@ -346,6 +347,7 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam

var defaultVal string

var paramTypeIsNil bool
var innerSpec *Spec
var itemsSpec SpecParamItems

Expand Down Expand Up @@ -408,7 +410,8 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam
case *parameter.EnumSpec:
defaultVal = spec.Default
case *parameter.NilSpec:
specType = "string"
paramTypeIsNil = true
specType = ""
case *parameter.SimpleSpec:
if typed, ok := spec.Default.(string); ok {
defaultVal = typed
Expand Down Expand Up @@ -453,6 +456,7 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam
specParameter := &SpecParam{
Description: schemaSpec.Description,
Type: specType,
IsNil: paramTypeIsNil,
Default: defaultVal,
Required: schemaSpec.Required,
Sensitive: sensitive,
Expand Down
15 changes: 13 additions & 2 deletions pkg/translate/terraform_provider/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,17 @@ func createSchemaSpecForParameter(schemaTyp schemaType, manager *imports.Manager
})
}

validatorFn := "ExactlyOneOf"
var expressions []string
for _, elt := range param.Spec.OneOf {
if elt.IsPrivateParameter() {
continue
}

if elt.IsNil {
validatorFn = "ConflictsWith"
}

expressions = append(expressions, fmt.Sprintf(`path.MatchRelative().AtParent().AtName("%s")`, elt.Name.Underscore))
}

Expand All @@ -973,7 +979,7 @@ func createSchemaSpecForParameter(schemaTyp schemaType, manager *imports.Manager
}

functions := []validatorFunctionCtx{{
Function: "ExactlyOneOf",
Function: validatorFn,
Expressions: expressions,
}}

Expand Down Expand Up @@ -1418,16 +1424,21 @@ func createSchemaSpecForNormalization(resourceTyp properties.ResourceType, schem
schemas = append(schemas, createSchemaSpecForParameter(schemaTyp, manager, structName, packageName, elt, nil)...)
}

validatorFn := "ExactlyOneOf"
var expressions []string
for _, elt := range spec.Spec.OneOf {
if elt.IsPrivateParameter() {
continue
}

if elt.IsNil {
validatorFn = "ConflictsWith"
}
expressions = append(expressions, fmt.Sprintf(`path.MatchRelative().AtParent().AtName("%s")`, elt.Name.Underscore))
}

functions := []validatorFunctionCtx{{
Function: "ExactlyOneOf",
Function: validatorFn,
Expressions: expressions,
}}

Expand Down
32 changes: 31 additions & 1 deletion specs/policies/network-address-translation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,36 @@ spec:
type: list
profiles:
- type: member
xpath: [tags]
xpath: [tag]
spec:
items:
type: string
- name: target
type: object
profiles:
- xpath: [target]
spec:
params:
- name: devices
type: list
profiles:
- type: entry
xpath: [devices]
spec:
items:
type: string
- name: tags
type: list
profiles:
- type: member
xpath: [tags]
spec:
items:
type: string
- name: negate
type: bool
profiles:
- xpath: [negate]
- name: disabled
type: bool
profiles:
Expand All @@ -372,6 +398,10 @@ spec:
spec:
max: 127
variants:
- name: none
type: nil
profiles:
- xpath: []
- name: destination-translation
type: object
profiles:
Expand Down

0 comments on commit 7d82836

Please sign in to comment.