Skip to content

Commit b00f922

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 971ac73 commit b00f922

25 files changed

+3077
-2295
lines changed

pkg/translate/structs_test.go

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,21 @@
11
package translate
22

33
import (
4+
"os"
5+
"testing"
6+
47
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
58
"github.com/stretchr/testify/assert"
6-
"testing"
79
)
810

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

5613
func TestLocationType(t *testing.T) {
14+
sampleSpec, err := os.ReadFile(addressSpecPath)
15+
assert.Nil(t, err, "failed to read address spec")
5716
// given
5817
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec))
18+
5919
locationKeys := []string{"device_group", "shared"}
6020
locations := yamlParsedData.Locations
6121
var locationTypes []string
@@ -100,6 +60,9 @@ func TestSpecParamType(t *testing.T) {
10060
}
10161

10262
func TestOmitEmpty(t *testing.T) {
63+
sampleSpec, err := os.ReadFile(addressSpecPath)
64+
assert.Nil(t, err, "failed to read address spec")
65+
10366
// given
10467
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec))
10568
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)