Skip to content

Commit

Permalink
auto-genereated rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
migara committed Sep 9, 2024
1 parent 216d850 commit 59f8ddd
Show file tree
Hide file tree
Showing 89 changed files with 18,552 additions and 2,139 deletions.
2,552 changes: 848 additions & 1,704 deletions client.go

Large diffs are not rendered by default.

158 changes: 158 additions & 0 deletions device/services/dns/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package dns

import (
"encoding/xml"

"github.com/PaloAltoNetworks/pango/generic"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
)

type Config struct {
DnsSetting *DnsSetting
FqdnRefreshTime *int64

Misc map[string][]generic.Xml
}
type DnsSetting struct {
Servers *DnsSettingServers
}
type DnsSettingServers struct {
Primary *string
Secondary *string
}
type configXmlContainer struct {
XMLName xml.Name `xml:"result"`
Answer []configXml `xml:"system"`
}
type configXml struct {
XMLName xml.Name `xml:"system"`
DnsSetting *DnsSettingXml `xml:"dns-setting,omitempty"`
FqdnRefreshTime *int64 `xml:"fqdn-refresh-time,omitempty"`

Misc []generic.Xml `xml:",any"`
}
type DnsSettingXml struct {
Servers *DnsSettingServersXml `xml:"servers,omitempty"`

Misc []generic.Xml `xml:",any"`
}
type DnsSettingServersXml struct {
Primary *string `xml:"primary,omitempty"`
Secondary *string `xml:"secondary,omitempty"`

Misc []generic.Xml `xml:",any"`
}

func Versioning(vn version.Number) (Specifier, Normalizer, error) {
return specifyConfig, &configXmlContainer{}, nil
}
func specifyConfig(o *Config) (any, error) {
config := configXml{}
var nestedDnsSetting *DnsSettingXml
if o.DnsSetting != nil {
nestedDnsSetting = &DnsSettingXml{}
if _, ok := o.Misc["DnsSetting"]; ok {
nestedDnsSetting.Misc = o.Misc["DnsSetting"]
}
if o.DnsSetting.Servers != nil {
nestedDnsSetting.Servers = &DnsSettingServersXml{}
if _, ok := o.Misc["DnsSettingServers"]; ok {
nestedDnsSetting.Servers.Misc = o.Misc["DnsSettingServers"]
}
if o.DnsSetting.Servers.Primary != nil {
nestedDnsSetting.Servers.Primary = o.DnsSetting.Servers.Primary
}
if o.DnsSetting.Servers.Secondary != nil {
nestedDnsSetting.Servers.Secondary = o.DnsSetting.Servers.Secondary
}
}
}
config.DnsSetting = nestedDnsSetting

config.FqdnRefreshTime = o.FqdnRefreshTime

config.Misc = o.Misc["Config"]

return config, nil
}
func (c *configXmlContainer) Normalize() ([]*Config, error) {
configList := make([]*Config, 0, len(c.Answer))
for _, o := range c.Answer {
config := &Config{
Misc: make(map[string][]generic.Xml),
}
var nestedDnsSetting *DnsSetting
if o.DnsSetting != nil {
nestedDnsSetting = &DnsSetting{}
if o.DnsSetting.Misc != nil {
config.Misc["DnsSetting"] = o.DnsSetting.Misc
}
if o.DnsSetting.Servers != nil {
nestedDnsSetting.Servers = &DnsSettingServers{}
if o.DnsSetting.Servers.Misc != nil {
config.Misc["DnsSettingServers"] = o.DnsSetting.Servers.Misc
}
if o.DnsSetting.Servers.Primary != nil {
nestedDnsSetting.Servers.Primary = o.DnsSetting.Servers.Primary
}
if o.DnsSetting.Servers.Secondary != nil {
nestedDnsSetting.Servers.Secondary = o.DnsSetting.Servers.Secondary
}
}
}
config.DnsSetting = nestedDnsSetting

config.FqdnRefreshTime = o.FqdnRefreshTime

config.Misc["Config"] = o.Misc

configList = append(configList, config)
}

return configList, nil
}

func SpecMatches(a, b *Config) bool {
if a == nil && b != nil || a != nil && b == nil {
return false
} else if a == nil && b == nil {
return true
}

// Don't compare Name.
if !matchDnsSetting(a.DnsSetting, b.DnsSetting) {
return false
}
if !util.Ints64Match(a.FqdnRefreshTime, b.FqdnRefreshTime) {
return false
}

return true
}

func matchDnsSettingServers(a *DnsSettingServers, b *DnsSettingServers) bool {
if a == nil && b != nil || a != nil && b == nil {
return false
} else if a == nil && b == nil {
return true
}
if !util.StringsMatch(a.Primary, b.Primary) {
return false
}
if !util.StringsMatch(a.Secondary, b.Secondary) {
return false
}
return true
}
func matchDnsSetting(a *DnsSetting, b *DnsSetting) bool {
if a == nil && b != nil || a != nil && b == nil {
return false
} else if a == nil && b == nil {
return true
}
if !matchDnsSettingServers(a.Servers, b.Servers) {
return false
}
return true
}
7 changes: 7 additions & 0 deletions device/services/dns/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dns

type Specifier func(*Config) (any, error)

type Normalizer interface {
Normalize() ([]*Config, error)
}
180 changes: 180 additions & 0 deletions device/services/dns/location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package dns

import (
"fmt"

"github.com/PaloAltoNetworks/pango/errors"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
)

type ImportLocation interface {
XpathForLocation(version.Number, util.ILocation) ([]string, error)
MarshalPangoXML([]string) (string, error)
UnmarshalPangoXML([]byte) ([]string, error)
}

type Location struct {
System *SystemLocation `json:"system,omitempty"`
Template *TemplateLocation `json:"template,omitempty"`
TemplateStack *TemplateStackLocation `json:"template_stack,omitempty"`
}

type SystemLocation struct {
NgfwDevice string `json:"ngfw_device"`
}

type TemplateLocation struct {
NgfwDevice string `json:"ngfw_device"`
PanoramaDevice string `json:"panorama_device"`
Template string `json:"template"`
}

type TemplateStackLocation struct {
NgfwDevice string `json:"ngfw_device"`
PanoramaDevice string `json:"panorama_device"`
TemplateStack string `json:"template_stack"`
}

func NewSystemLocation() *Location {
return &Location{System: &SystemLocation{
NgfwDevice: "localhost.localdomain",
},
}
}
func NewTemplateLocation() *Location {
return &Location{Template: &TemplateLocation{
NgfwDevice: "localhost.localdomain",
PanoramaDevice: "localhost.localdomain",
Template: "",
},
}
}
func NewTemplateStackLocation() *Location {
return &Location{TemplateStack: &TemplateStackLocation{
NgfwDevice: "localhost.localdomain",
PanoramaDevice: "localhost.localdomain",
TemplateStack: "",
},
}
}

func (o Location) IsValid() error {
count := 0

switch {
case o.System != nil:
if o.System.NgfwDevice == "" {
return fmt.Errorf("NgfwDevice is unspecified")
}
count++
case o.Template != nil:
if o.Template.NgfwDevice == "" {
return fmt.Errorf("NgfwDevice is unspecified")
}
if o.Template.PanoramaDevice == "" {
return fmt.Errorf("PanoramaDevice is unspecified")
}
if o.Template.Template == "" {
return fmt.Errorf("Template is unspecified")
}
count++
case o.TemplateStack != nil:
if o.TemplateStack.NgfwDevice == "" {
return fmt.Errorf("NgfwDevice is unspecified")
}
if o.TemplateStack.PanoramaDevice == "" {
return fmt.Errorf("PanoramaDevice is unspecified")
}
if o.TemplateStack.TemplateStack == "" {
return fmt.Errorf("TemplateStack is unspecified")
}
count++
}

if count == 0 {
return fmt.Errorf("no path specified")
}

if count > 1 {
return fmt.Errorf("multiple paths specified: only one should be specified")
}

return nil
}

func (o Location) XpathPrefix(vn version.Number) ([]string, error) {

var ans []string

switch {
case o.System != nil:
if o.System.NgfwDevice == "" {
return nil, fmt.Errorf("NgfwDevice is unspecified")
}
ans = []string{
"config",
"devices",
util.AsEntryXpath([]string{o.System.NgfwDevice}),
"deviceconfig",
"system",
}
case o.Template != nil:
if o.Template.NgfwDevice == "" {
return nil, fmt.Errorf("NgfwDevice is unspecified")
}
if o.Template.PanoramaDevice == "" {
return nil, fmt.Errorf("PanoramaDevice is unspecified")
}
if o.Template.Template == "" {
return nil, fmt.Errorf("Template is unspecified")
}
ans = []string{
"config",
"devices",
util.AsEntryXpath([]string{o.Template.PanoramaDevice}),
"template",
util.AsEntryXpath([]string{o.Template.Template}),
"config",
"devices",
util.AsEntryXpath([]string{o.Template.NgfwDevice}),
"deviceconfig",
"system",
}
case o.TemplateStack != nil:
if o.TemplateStack.NgfwDevice == "" {
return nil, fmt.Errorf("NgfwDevice is unspecified")
}
if o.TemplateStack.PanoramaDevice == "" {
return nil, fmt.Errorf("PanoramaDevice is unspecified")
}
if o.TemplateStack.TemplateStack == "" {
return nil, fmt.Errorf("TemplateStack is unspecified")
}
ans = []string{
"config",
"devices",
util.AsEntryXpath([]string{o.TemplateStack.PanoramaDevice}),
"template-stack",
util.AsEntryXpath([]string{o.TemplateStack.TemplateStack}),
"config",
"devices",
util.AsEntryXpath([]string{o.TemplateStack.NgfwDevice}),
"deviceconfig",
"system",
}
default:
return nil, errors.NoLocationSpecifiedError
}

return ans, nil
}
func (o Location) Xpath(vn version.Number) ([]string, error) {

ans, err := o.XpathPrefix(vn)
if err != nil {
return nil, err
}

return ans, nil
}
Loading

0 comments on commit 59f8ddd

Please sign in to comment.