Skip to content

Commit

Permalink
updating location functionality for address objects
Browse files Browse the repository at this point in the history
  • Loading branch information
shinmog committed Feb 23, 2024
1 parent c6c9011 commit 2b93408
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions objects/address/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,52 @@ import (
)

type Location struct {
Shared bool
Vsys *VsysLocation
DeviceGroup *DeviceGroupLocation
FromPanorama bool
Shared bool `json:"shared"`
Vsys *VsysLocation `json:"vsys,omitempty"`
DeviceGroup *DeviceGroupLocation `json:"device_group,omitempty"`
FromPanorama bool `json:"from_panorama"`
}

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

if o.Shared {
count++
}

if o.Vsys != nil {
if o.Vsys.Name == "" {
return fmt.Errorf("vsys.name is unspecified")
}
if o.Vsys.NgfwDevice == "" {
return fmt.Errorf("vsys.ngfw_device is unspecified")
}
count++
}

if o.DeviceGroup != nil {
if o.DeviceGroup.Name == "" {
return fmt.Errorf("device_group.name is unspecified")
}
if o.DeviceGroup.PanoramaDevice == "" {
return fmt.Errorf("device_group.panorama_device is unspecified")
}
count++
}

if o.FromPanorama {
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) Xpath(vn version.Number, name string) ([]string, error) {
Expand Down Expand Up @@ -65,11 +107,11 @@ func (o Location) Xpath(vn version.Number, name string) ([]string, error) {
}

type VsysLocation struct {
NgfwDevice string
Name string
NgfwDevice string `json:"ngfw_device"`
Name string `json:"name"`
}

type DeviceGroupLocation struct {
PanoramaDevice string
Name string
PanoramaDevice string `json:"panorama_device"`
Name string `json:"name"`
}

0 comments on commit 2b93408

Please sign in to comment.