Skip to content

Commit b870149

Browse files
committed
Change API specs schema and create JSON schema files with validations
Conflicts: specs/panorama/device-group.yaml specs/panorama/template.yaml
1 parent b6c7ce0 commit b870149

26 files changed

+3034
-2202
lines changed

pkg/schema/parameter/parameter.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import (
1919
// Spec type is any, as its unmarshalling is done in a custom
2020
// UnmarshalYAML function.
2121
type Parameter struct {
22-
Name string `yaml:"name"`
23-
Description string `yaml:"description"`
24-
Type string `yaml:"type"`
25-
Required bool `yaml:"required"`
26-
Profiles []profile.Profile `yaml:"profiles"`
27-
Validators []validator.Validator `yaml:"validators"`
28-
Spec any `yaml:"-"`
22+
Name string `yaml:"name"`
23+
Description string `yaml:"description"`
24+
Type string `yaml:"type"`
25+
CodegenOverrides *CodegenOverrides `yaml:"codegen_overrides"`
26+
Required bool `yaml:"required"`
27+
Profiles []profile.Profile `yaml:"profiles"`
28+
Validators []validator.Validator `yaml:"validators"`
29+
Spec any `yaml:"-"`
2930
}
3031

3132
// SimpleSpec describes a parameter of a simple type.
@@ -40,6 +41,14 @@ type EnumSpecValue struct {
4041
Const string `yaml:"const"`
4142
}
4243

44+
type CodegenOverridesTerraform struct {
45+
Computed bool `yaml:"computed"`
46+
}
47+
48+
type CodegenOverrides struct {
49+
Terraform *CodegenOverridesTerraform `yaml:"terraform"`
50+
}
51+
4352
// EnumSpec describes a parameter of type enum
4453
//
4554
// Values is a list of EnumSpecValue, where each one consisting of the PAN-OS Value

pkg/translate/structs_test.go

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,22 @@
11
package translate
22

33
import (
4+
"os"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
78

89
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
910
)
1011

11-
const sampleSpec = `name: 'Address'
12-
terraform_provider_config:
13-
skip_resource: false
14-
skip_datasource: false
15-
skip_datasource_listing: false
16-
suffix: address
17-
go_sdk_config:
18-
package:
19-
- 'objects'
20-
- 'address'
21-
xpath_suffix:
22-
- 'address'
23-
locations:
24-
- name: 'shared'
25-
description: 'Located in shared.'
26-
devices:
27-
- panorama
28-
- ngfw
29-
xpath:
30-
path: ['config', 'shared']
31-
- name: 'device_group'
32-
description: 'Located in a specific device group.'
33-
devices:
34-
- panorama
35-
xpath:
36-
path:
37-
- 'config'
38-
- 'devices'
39-
- '{{ Entry $panorama_device }}'
40-
- 'device-group'
41-
- '{{ Entry $device_group }}'
42-
vars:
43-
- name: 'panorama_device'
44-
description: 'The panorama device.'
45-
default: 'localhost.localdomain'
46-
- name: 'device_group'
47-
description: 'The device group.'
48-
required: true
49-
validators:
50-
- type: not-values
51-
spec:
52-
values:
53-
- value: 'shared'
54-
error: 'The device group cannot be "shared". Use the "shared" path instead.'
55-
entry:
56-
name:
57-
description: 'The name of the address object.'
58-
validators:
59-
- type: length
60-
spec:
61-
min: 1
62-
max: 63
63-
spec: {}
64-
version: '10.1.0'
65-
`
12+
const addressSpecPath = "../../specs/objects/address.yaml"
6613

6714
func TestLocationType(t *testing.T) {
15+
sampleSpec, err := os.ReadFile(addressSpecPath)
16+
assert.Nil(t, err, "failed to read address spec")
6817
// given
69-
yamlParsedData, err := properties.ParseSpec([]byte(sampleSpec))
70-
assert.Nil(t, err)
18+
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec))
19+
7120
locationKeys := []string{"device_group", "shared"}
7221
locations := yamlParsedData.Locations
7322
var locationTypes []string
@@ -112,6 +61,9 @@ func TestSpecParamType(t *testing.T) {
11261
}
11362

11463
func TestOmitEmpty(t *testing.T) {
64+
sampleSpec, err := os.ReadFile(addressSpecPath)
65+
assert.Nil(t, err, "failed to read address spec")
66+
11567
// given
11668
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec))
11769
locationKeys := []string{"device_group", "shared"}

specs/device/dns.yaml

Lines changed: 98 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,116 @@
1-
name: 'DNS'
1+
name: "DNS"
22
terraform_provider_config:
3-
suffix: 'dns'
4-
go_sdk_path:
5-
- 'device'
6-
- 'services'
7-
- 'dns'
3+
suffix: "dns"
4+
go_sdk_config:
5+
package:
6+
- "device"
7+
- "services"
8+
- "dns"
89
locations:
9-
'system':
10-
description: 'Located in a system settings.'
11-
device:
12-
panorama: true
13-
ngfw: true
10+
- name: "system"
11+
description: "Located in a system settings."
12+
devices:
13+
- panorama
14+
- ngfw
1415
xpath:
15-
- 'config'
16-
- 'devices'
17-
- '{{ Entry $ngfw_device }}'
18-
- 'deviceconfig'
19-
- 'system'
20-
vars:
21-
'ngfw_device':
22-
description: 'The NGFW device.'
23-
default: 'localhost.localdomain'
24-
'template':
25-
description: 'Located in a specific template.'
26-
device:
27-
panorama: true
16+
path:
17+
- "config"
18+
- "devices"
19+
- "$ngfw_device"
20+
- "deviceconfig"
21+
- "system"
22+
vars:
23+
- name: "ngfw_device"
24+
description: "The NGFW device."
25+
default: "localhost.localdomain"
26+
- name: "template"
27+
description: "Located in a specific template."
28+
devices:
29+
- panorama
2830
xpath:
29-
- 'config'
30-
- 'devices'
31-
- '{{ Entry $panorama_device }}'
32-
- 'template'
33-
- '{{ Entry $template }}'
34-
- 'config'
35-
- 'devices'
36-
- '{{ Entry $ngfw_device }}'
37-
- 'deviceconfig'
38-
- 'system'
39-
vars:
40-
'panorama_device':
41-
description: 'The panorama device.'
42-
default: 'localhost.localdomain'
43-
'template':
44-
description: 'The template.'
45-
required: true
46-
'ngfw_device':
47-
description: 'The NGFW device.'
48-
default: 'localhost.localdomain'
49-
'template-stack':
50-
description: 'Located in a specific template stack.'
51-
device:
52-
panorama: true
31+
path:
32+
- "config"
33+
- "devices"
34+
- "$panorama_device"
35+
- "template"
36+
- "$template"
37+
- "config"
38+
- "devices"
39+
- "$ngfw_device"
40+
- "deviceconfig"
41+
- "system"
42+
vars:
43+
- name: "panorama_device"
44+
description: "The panorama device."
45+
default: "localhost.localdomain"
46+
- name: "template"
47+
description: "The template."
48+
required: true
49+
- name: "ngfw_device"
50+
description: "The NGFW device."
51+
default: "localhost.localdomain"
52+
- name: "template-stack"
53+
description: "Located in a specific template stack."
54+
devices:
55+
- panorama
5356
xpath:
54-
- 'config'
55-
- 'devices'
56-
- '{{ Entry $panorama_device }}'
57-
- 'template-stack'
58-
- '{{ Entry $template_stack }}'
59-
- 'config'
60-
- 'devices'
61-
- '{{ Entry $ngfw_device }}'
62-
- 'deviceconfig'
63-
- 'system'
64-
vars:
65-
'panorama_device':
66-
description: 'The panorama device.'
67-
default: 'localhost.localdomain'
68-
'template_stack':
69-
description: 'The template stack.'
70-
required: true
71-
'ngfw_device':
72-
description: 'The NGFW device.'
73-
default: 'localhost.localdomain'
74-
version: '10.1.0'
57+
path:
58+
- "config"
59+
- "devices"
60+
- "$panorama_device"
61+
- "template-stack"
62+
- "$template_stack"
63+
- "config"
64+
- "devices"
65+
- "$ngfw_device"
66+
- "deviceconfig"
67+
- "system"
68+
vars:
69+
- name: "panorama_device"
70+
description: "The panorama device."
71+
default: "localhost.localdomain"
72+
- name: "template_stack"
73+
description: "The template stack."
74+
required: true
75+
- name: "ngfw_device"
76+
description: "The NGFW device."
77+
default: "localhost.localdomain"
78+
version: "10.1.0"
7579
spec:
7680
params:
77-
fqdn_refresh_time:
78-
description: 'Seconds for Periodic Timer to refresh expired FQDN object entries'
81+
- name: fqdn_refresh_time
82+
description: "Seconds for Periodic Timer to refresh expired FQDN object entries"
7983
type: int64
80-
value:
81-
min: 600
82-
max: 14399
84+
spec:
8385
default: 1800
86+
validators:
87+
- type: range
88+
spec:
89+
min: 600
90+
max: 14399
8491
profiles:
85-
-
86-
xpath: ["fqdn-refresh-time"]
87-
dns_setting:
88-
description: 'DNS settings'
92+
- xpath: ["fqdn-refresh-time"]
93+
- name: dns_setting
94+
description: "DNS settings"
95+
type: object
8996
profiles:
90-
-
91-
xpath: ["dns-setting"]
97+
- xpath: ["dns-setting"]
9298
spec:
9399
params:
94-
servers:
95-
description: 'DNS servers'
100+
- name: servers
101+
description: "DNS servers"
102+
type: object
96103
profiles:
97-
-
98-
xpath: ["servers"]
104+
- xpath: ["servers"]
99105
spec:
100106
params:
101-
primary:
102-
description: 'Primary DNS server IP address'
107+
- name: primary
108+
description: "Primary DNS server IP address"
109+
type: string
103110
profiles:
104-
- xpath: [ "primary" ]
105-
secondary:
106-
description: 'Secondary DNS server IP address'
111+
- xpath: ["primary"]
112+
- name: secondary
113+
description: "Secondary DNS server IP address"
114+
type: string
107115
profiles:
108-
- xpath: [ "secondary" ]
116+
- xpath: ["secondary"]

0 commit comments

Comments
 (0)