Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions assets/pango/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,9 @@ func checkEthernetLayer3Static(c *pango.Client, ctx context.Context) {
location = ethernet.NewNgfwLocation()
}

var importLocation []ethernet.ImportLocation
api := ethernet.NewService(c)

reply, err := api.Create(ctx, *location, importLocation, entry)
reply, err := api.Create(ctx, *location, entry)
if err != nil {
log.Printf("Failed to create ethernet: %s", err)
return
Expand Down Expand Up @@ -329,10 +328,9 @@ func checkEthernetLayer3Dhcp(c *pango.Client, ctx context.Context) {
location = ethernet.NewNgfwLocation()
}

var importLocation []ethernet.ImportLocation
api := ethernet.NewService(c)

reply, err := api.Create(ctx, *location, importLocation, entry)
reply, err := api.Create(ctx, *location, entry)
if err != nil {
log.Printf("Failed to create ethernet: %s", err)
return
Expand All @@ -355,10 +353,9 @@ func checkEthernetHa(c *pango.Client, ctx context.Context) {
location = ethernet.NewNgfwLocation()
}

var importLocation []ethernet.ImportLocation
api := ethernet.NewService(c)

reply, err := api.Create(ctx, *location, importLocation, entry)
reply, err := api.Create(ctx, *location, entry)
if err != nil {
log.Printf("Failed to create ethernet: %s", err)
return
Expand Down Expand Up @@ -570,12 +567,11 @@ func checkVrZoneWithEthernet(c *pango.Client, ctx context.Context) {
ethernetLocation = ethernet.NewNgfwLocation()
}

var importLocation []ethernet.ImportLocation
api := ethernet.NewService(c)

interfacesToDelete := []string{"ethernet1/2", "ethernet1/3"}
for _, iface := range interfacesToDelete {
err = api.Delete(ctx, *ethernetLocation, importLocation, iface)
err = api.Delete(ctx, *ethernetLocation, iface)
if err != nil {
log.Printf("Failed to delete ethernet: %s", err)
return
Expand Down
32 changes: 16 additions & 16 deletions assets/terraform/internal/manager/entry_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/PaloAltoNetworks/pango/xmlapi"
)

type SDKImportableEntryService[E EntryObject, L EntryLocation, IL ImportLocation] interface {
type SDKImportableEntryService[E EntryObject, L EntryLocation] interface {
CreateWithXpath(context.Context, string, E) error
ReadWithXpath(context.Context, string, string) (E, error)
List(context.Context, L, string, string, string) ([]E, error)
UpdateWithXpath(context.Context, string, E, string) error
Delete(context.Context, L, []IL, ...string) error
ImportToLocations(context.Context, L, []IL, string) error
UnimportFromLocations(context.Context, L, []IL, []string) error
Delete(context.Context, L, ...string) error
ImportToLocation(context.Context, L, string, string) error
UnimportFromLocation(context.Context, L, string, string) error
}

type ImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLocation, IS SDKImportableEntryService[E, L, IL]] struct {
type ImportableEntryObjectManager[E EntryObject, L EntryLocation, IS SDKImportableEntryService[E, L]] struct {
batchSize int
service IS
client SDKClient
specifier func(E) (any, error)
matcher func(E, E) bool
}

func NewImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLocation, IS SDKImportableEntryService[E, L, IL]](client SDKClient, service IS, batchSize int, specifier func(E) (any, error), matcher func(E, E) bool) *ImportableEntryObjectManager[E, L, IL, IS] {
return &ImportableEntryObjectManager[E, L, IL, IS]{
func NewImportableEntryObjectManager[E EntryObject, L EntryLocation, IS SDKImportableEntryService[E, L]](client SDKClient, service IS, batchSize int, specifier func(E) (any, error), matcher func(E, E) bool) *ImportableEntryObjectManager[E, L, IS] {
return &ImportableEntryObjectManager[E, L, IS]{
batchSize: batchSize,
service: service,
client: client,
Expand All @@ -38,11 +38,11 @@ func NewImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLo
}
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) ReadMany(ctx context.Context, location L, entries []E) ([]E, error) {
func (o *ImportableEntryObjectManager[E, L, IS]) ReadMany(ctx context.Context, location L, entries []E) ([]E, error) {
return nil, &Error{err: ErrInternal, message: "called ReadMany on an importable singular resource"}
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Read(ctx context.Context, location L, components []string, name string) (E, error) {
func (o *ImportableEntryObjectManager[E, L, IS]) Read(ctx context.Context, location L, components []string, name string) (E, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), append(components, util.AsEntryXpath(name))...)
if err != nil {
return *new(E), err
Expand All @@ -59,7 +59,7 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) Read(ctx context.Context, l
return object, nil
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Create(ctx context.Context, location L, components []string, entry E) (E, error) {
func (o *ImportableEntryObjectManager[E, L, IS]) Create(ctx context.Context, location L, components []string, entry E) (E, error) {
name := entry.EntryName()

_, err := o.Read(ctx, location, components, name)
Expand All @@ -84,7 +84,7 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) Create(ctx context.Context,
return o.Read(ctx, location, components, name)
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Update(ctx context.Context, location L, components []string, entry E, name string) (E, error) {
func (o *ImportableEntryObjectManager[E, L, IS]) Update(ctx context.Context, location L, components []string, entry E, name string) (E, error) {
xpath, err := location.XpathWithComponents(o.client.Versioning(), append(components, util.AsEntryXpath(entry.EntryName()))...)
if err != nil {
return *new(E), &Error{err: err, message: "error during Update call"}
Expand All @@ -98,7 +98,7 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) Update(ctx context.Context,
return o.service.ReadWithXpath(ctx, util.AsXpath(xpath), "get")
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) Delete(ctx context.Context, location L, importLocations []IL, components []string, names []string) error {
func (o *ImportableEntryObjectManager[E, L, IS]) Delete(ctx context.Context, location L, components []string, names []string) error {
deletes := xmlapi.NewChunkedMultiConfig(o.batchSize, len(names))

for _, elt := range names {
Expand All @@ -123,10 +123,10 @@ func (o *ImportableEntryObjectManager[E, L, IL, IS]) Delete(ctx context.Context,
return nil
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) ImportToLocations(ctx context.Context, location L, importLocs []IL, entry string) error {
return o.service.ImportToLocations(ctx, location, importLocs, entry)
func (o *ImportableEntryObjectManager[E, L, IS]) ImportToLocation(ctx context.Context, location L, vsys string, entry string) error {
return o.service.ImportToLocation(ctx, location, vsys, entry)
}

func (o *ImportableEntryObjectManager[E, L, IL, IS]) UnimportFromLocations(ctx context.Context, location L, importLocs []IL, entry string) error {
return o.service.UnimportFromLocations(ctx, location, importLocs, []string{entry})
func (o *ImportableEntryObjectManager[E, L, IS]) UnimportFromLocation(ctx context.Context, location L, vsys string, entry string) error {
return o.service.UnimportFromLocation(ctx, location, vsys, entry)
}
7 changes: 0 additions & 7 deletions assets/terraform/internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"net/url"

"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
"github.com/PaloAltoNetworks/pango/xmlapi"
)
Expand Down Expand Up @@ -57,9 +56,3 @@ type SDKClient interface {
ChunkedMultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]xmlapi.ChunkedMultiConfigResponse, error)
MultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]byte, *http.Response, *xmlapi.MultiConfigResponse, error)
}

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