Skip to content

fix: Fix some issues related to merging previous PRs #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,27 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam
})
}

var specHashing *SpecParamHashing
if schemaSpec.Hashing != nil {
specHashing = &SpecParamHashing{
Type: schemaSpec.Hashing.Type,
}
}
var terraformProviderConfig *SpecParamTerraformProviderConfig
if schemaSpec.CodegenOverrides != nil {
terraformProviderConfig = &SpecParamTerraformProviderConfig{
Computed: schemaSpec.CodegenOverrides.Terraform.Computed,
}
}
specParameter := &SpecParam{
Description: schemaSpec.Description,
Type: specType,
Default: defaultVal,
Required: schemaSpec.Required,
Profiles: profiles,
Spec: innerSpec,
Description: schemaSpec.Description,
Type: specType,
Default: defaultVal,
Required: schemaSpec.Required,
TerraformProviderConfig: terraformProviderConfig,
Hashing: specHashing,
Profiles: profiles,
Spec: innerSpec,
}

for _, v := range schemaSpec.Validators {
Expand Down
5 changes: 5 additions & 0 deletions pkg/schema/parameter/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Parameter struct {
Description string `yaml:"description"`
Type string `yaml:"type"`
CodegenOverrides *CodegenOverrides `yaml:"codegen_overrides"`
Hashing *HashingSpec `yaml:"hashing"`
Required bool `yaml:"required"`
Profiles []profile.Profile `yaml:"profiles"`
Validators []validator.Validator `yaml:"validators"`
Expand All @@ -49,6 +50,10 @@ type CodegenOverrides struct {
Terraform *CodegenOverridesTerraform `yaml:"terraform"`
}

type HashingSpec struct {
Type string `yaml:"type"`
}

// EnumSpec describes a parameter of type enum
//
// Values is a list of EnumSpecValue, where each one consisting of the PAN-OS Value
Expand Down
17 changes: 2 additions & 15 deletions pkg/translate/terraform_provider/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,22 +776,11 @@ func createSchemaSpecForParameter(typ schemaType, structPrefix string, packageNa
LowerCamelCase: naming.CamelCase("", "name", "", false),
}

var computed, optional bool
if param.TerraformProviderConfig != nil {
computed = param.TerraformProviderConfig.Computed
optional = !computed
} else if param.Default != "" {
computed = true
optional = true
}

attributes = append(attributes, attributeCtx{
Package: packageName,
Name: name,
SchemaType: "StringAttribute",
Required: true,
Computed: computed,
Optional: optional,
})
}

Expand Down Expand Up @@ -870,12 +859,10 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
}
}

var optional, computed bool
var computed bool
if param.TerraformProviderConfig != nil {
computed = param.TerraformProviderConfig.Computed
optional = !computed
} else if param.Default != "" {
optional = true
computed = true
}

Expand All @@ -886,7 +873,7 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
ElementType: elementType,
Description: param.Description,
Required: param.Required,
Optional: optional,
Optional: !param.Required,
Sensitive: param.Sensitive,
Default: defaultValue,
Computed: computed,
Expand Down
16 changes: 10 additions & 6 deletions specs/device/ntp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ spec:
- xpath: ["key-id"]
variants:
- name: md5
type: string
type: object
profiles:
- xpath: ["algorithm", "md5"]
spec:
Expand All @@ -149,7 +149,7 @@ spec:
profiles:
- xpath: ["authentication-key"]
- name: sha1
type: string
type: object
profiles:
- xpath: ["algorithm", "sha1"]
spec:
Expand Down Expand Up @@ -217,14 +217,16 @@ spec:
- xpath: ["key-id"]
variants:
- name: md5
type: string
type: object
profiles:
- xpath: ["algorithm/md5"]
- xpath: ["algorithm", "md5"]
spec:
params:
- name: authentication_key
type: string
description: "Symmetric Key MD5 String"
hashing:
type: solo
validators:
- type: length
spec:
Expand All @@ -233,14 +235,16 @@ spec:
profiles:
- xpath: ["authentication-key"]
- name: sha1
type: string
type: object
profiles:
- xpath: ["algorithm/sha1"]
- xpath: ["algorithm", "sha1"]
spec:
params:
- name: authentication_key
type: string
description: "Symmetric Key SHA1 Hexadecimal"
hashing:
type: solo
validators:
- type: length
spec:
Expand Down
Loading