-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd09ee9
commit 65727a4
Showing
21 changed files
with
323 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package translate | ||
|
||
import ( | ||
"errors" | ||
"github.com/paloaltonetworks/pan-os-codegen/pkg/naming" | ||
"strings" | ||
) | ||
|
||
func AsEntryXpath(location, xpath string) (string, error) { | ||
if !strings.Contains(xpath, "$") || !strings.Contains(xpath, "}") { | ||
return "", errors.New("$ followed by } should exists in xpath'") | ||
} | ||
xpath = strings.TrimSpace(strings.Split(strings.Split(xpath, "$")[1], "}")[0]) | ||
xpath = naming.CamelCase("", xpath, "", true) | ||
return "util.AsEntryXpath([]string{o." + location + "." + xpath + "}),", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package translate | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestAsEntryXpath(t *testing.T) { | ||
// given | ||
|
||
// when | ||
asEntryXpath, _ := AsEntryXpath("DeviceGroup", "{{ Entry $panorama_device }}") | ||
|
||
// then | ||
assert.Equal(t, "util.AsEntryXpath([]string{o.DeviceGroup.PanoramaDevice}),", asEntryXpath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package translate | ||
|
||
import ( | ||
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties" | ||
) | ||
|
||
func LocationType(location *properties.Location, pointer bool) string { | ||
prefix := "" | ||
if pointer { | ||
prefix = "*" | ||
} | ||
if location.Vars != nil { | ||
return prefix + location.Name.CamelCase + "Location" | ||
} else { | ||
return "bool" | ||
} | ||
} | ||
|
||
func OmitEmpty(location *properties.Location) string { | ||
if location.Vars != nil { | ||
return ",omitempty" | ||
} else { | ||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package translate | ||
|
||
import ( | ||
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const sampleSpec = `name: 'Address' | ||
terraform_provider_suffix: 'address' | ||
go_sdk_path: | ||
- 'objects' | ||
- 'address' | ||
xpath_suffix: | ||
- 'address' | ||
locations: | ||
'shared': | ||
description: 'Located in shared.' | ||
device: | ||
panorama: true | ||
ngfw: true | ||
xpath: ['config', 'shared'] | ||
'device_group': | ||
description: 'Located in a specific device group.' | ||
device: | ||
panorama: true | ||
xpath: | ||
- 'config' | ||
- 'devices' | ||
- '{{ Entry $panorama_device }}' | ||
- 'device-group' | ||
- '{{ Entry $device_group }}' | ||
vars: | ||
'panorama_device': | ||
description: 'The panorama device.' | ||
default: 'localhost.localdomain' | ||
'device_group': | ||
description: 'The device group.' | ||
required: true | ||
validation: | ||
not_values: | ||
'shared': 'The device group cannot be "shared". Use the "shared" path instead.' | ||
entry: | ||
name: | ||
description: 'The name of the address object.' | ||
length: | ||
min: 1 | ||
max: 63 | ||
version: '10.1.0' | ||
` | ||
|
||
func TestLocationType(t *testing.T) { | ||
// given | ||
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec)) | ||
locationKeys := []string{"device_group", "shared"} | ||
locations := yamlParsedData.Locations | ||
var locationTypes []string | ||
|
||
// when | ||
for _, locationKey := range locationKeys { | ||
locationTypes = append(locationTypes, LocationType(locations[locationKey], true)) | ||
} | ||
|
||
// then | ||
assert.NotEmpty(t, locationTypes) | ||
assert.Contains(t, locationTypes, "*DeviceGroupLocation") | ||
assert.Contains(t, locationTypes, "bool") | ||
} | ||
|
||
func TestOmitEmpty(t *testing.T) { | ||
// given | ||
yamlParsedData, _ := properties.ParseSpec([]byte(sampleSpec)) | ||
locationKeys := []string{"device_group", "shared"} | ||
locations := yamlParsedData.Locations | ||
var omitEmptyLocations []string | ||
|
||
// when | ||
for _, locationKey := range locationKeys { | ||
omitEmptyLocations = append(omitEmptyLocations, OmitEmpty(locations[locationKey])) | ||
} | ||
|
||
// then | ||
assert.NotEmpty(t, omitEmptyLocations) | ||
assert.Contains(t, omitEmptyLocations, ",omitempty") | ||
assert.Contains(t, omitEmptyLocations, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.