Skip to content

Commit be0676d

Browse files
committed
Fix some issues related to merging previous PRs
1 parent a3c11e5 commit be0676d

File tree

4 files changed

+37
-27
lines changed

4 files changed

+37
-27
lines changed

pkg/properties/normalized.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,27 @@ func schemaParameterToSpecParameter(schemaSpec *parameter.Parameter) (*SpecParam
346346
})
347347
}
348348

349+
var specHashing *SpecParamHashing
350+
if schemaSpec.Hashing != nil {
351+
specHashing = &SpecParamHashing{
352+
Type: schemaSpec.Hashing.Type,
353+
}
354+
}
355+
var terraformProviderConfig *SpecParamTerraformProviderConfig
356+
if schemaSpec.CodegenOverrides != nil {
357+
terraformProviderConfig = &SpecParamTerraformProviderConfig{
358+
Computed: schemaSpec.CodegenOverrides.Terraform.Computed,
359+
}
360+
}
349361
specParameter := &SpecParam{
350-
Description: schemaSpec.Description,
351-
Type: specType,
352-
Default: defaultVal,
353-
Required: schemaSpec.Required,
354-
Profiles: profiles,
355-
Spec: innerSpec,
362+
Description: schemaSpec.Description,
363+
Type: specType,
364+
Default: defaultVal,
365+
Required: schemaSpec.Required,
366+
TerraformProviderConfig: terraformProviderConfig,
367+
Hashing: specHashing,
368+
Profiles: profiles,
369+
Spec: innerSpec,
356370
}
357371

358372
for _, v := range schemaSpec.Validators {

pkg/schema/parameter/parameter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Parameter struct {
2323
Description string `yaml:"description"`
2424
Type string `yaml:"type"`
2525
CodegenOverrides *CodegenOverrides `yaml:"codegen_overrides"`
26+
Hashing *HashingSpec `yaml:"hashing"`
2627
Required bool `yaml:"required"`
2728
Profiles []profile.Profile `yaml:"profiles"`
2829
Validators []validator.Validator `yaml:"validators"`
@@ -49,6 +50,10 @@ type CodegenOverrides struct {
4950
Terraform *CodegenOverridesTerraform `yaml:"terraform"`
5051
}
5152

53+
type HashingSpec struct {
54+
Type string `yaml:"type"`
55+
}
56+
5257
// EnumSpec describes a parameter of type enum
5358
//
5459
// Values is a list of EnumSpecValue, where each one consisting of the PAN-OS Value

pkg/translate/terraform_provider/funcs.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -776,22 +776,11 @@ func createSchemaSpecForParameter(typ schemaType, structPrefix string, packageNa
776776
LowerCamelCase: naming.CamelCase("", "name", "", false),
777777
}
778778

779-
var computed, optional bool
780-
if param.TerraformProviderConfig != nil {
781-
computed = param.TerraformProviderConfig.Computed
782-
optional = !computed
783-
} else if param.Default != "" {
784-
computed = true
785-
optional = true
786-
}
787-
788779
attributes = append(attributes, attributeCtx{
789780
Package: packageName,
790781
Name: name,
791782
SchemaType: "StringAttribute",
792783
Required: true,
793-
Computed: computed,
794-
Optional: optional,
795784
})
796785
}
797786

@@ -870,12 +859,10 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
870859
}
871860
}
872861

873-
var optional, computed bool
862+
var computed bool
874863
if param.TerraformProviderConfig != nil {
875864
computed = param.TerraformProviderConfig.Computed
876-
optional = !computed
877865
} else if param.Default != "" {
878-
optional = true
879866
computed = true
880867
}
881868

@@ -886,7 +873,7 @@ func createSchemaAttributeForParameter(typ schemaType, packageName string, param
886873
ElementType: elementType,
887874
Description: param.Description,
888875
Required: param.Required,
889-
Optional: optional,
876+
Optional: !param.Required,
890877
Sensitive: param.Sensitive,
891878
Default: defaultValue,
892879
Computed: computed,

specs/device/ntp.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ spec:
128128
- xpath: ["key-id"]
129129
variants:
130130
- name: md5
131-
type: string
131+
type: object
132132
profiles:
133133
- xpath: ["algorithm", "md5"]
134134
spec:
@@ -149,7 +149,7 @@ spec:
149149
profiles:
150150
- xpath: ["authentication-key"]
151151
- name: sha1
152-
type: string
152+
type: object
153153
profiles:
154154
- xpath: ["algorithm", "sha1"]
155155
spec:
@@ -217,14 +217,16 @@ spec:
217217
- xpath: ["key-id"]
218218
variants:
219219
- name: md5
220-
type: string
220+
type: object
221221
profiles:
222-
- xpath: ["algorithm/md5"]
222+
- xpath: ["algorithm", "md5"]
223223
spec:
224224
params:
225225
- name: authentication_key
226226
type: string
227227
description: "Symmetric Key MD5 String"
228+
hashing:
229+
type: solo
228230
validators:
229231
- type: length
230232
spec:
@@ -233,14 +235,16 @@ spec:
233235
profiles:
234236
- xpath: ["authentication-key"]
235237
- name: sha1
236-
type: string
238+
type: object
237239
profiles:
238-
- xpath: ["algorithm/sha1"]
240+
- xpath: ["algorithm", "sha1"]
239241
spec:
240242
params:
241243
- name: authentication_key
242244
type: string
243245
description: "Symmetric Key SHA1 Hexadecimal"
246+
hashing:
247+
type: solo
244248
validators:
245249
- type: length
246250
spec:

0 commit comments

Comments
 (0)