Skip to content

Commit 295b616

Browse files
committed
feat(codegen): Rewrite interface import logic to support importing only a subset of variants
1 parent 8c1badb commit 295b616

113 files changed

Lines changed: 2250 additions & 1213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/pango/example/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,9 @@ func checkEthernetLayer3Static(c *pango.Client, ctx context.Context) {
292292
location = ethernet.NewNgfwLocation()
293293
}
294294

295-
var importLocation []ethernet.ImportLocation
296295
api := ethernet.NewService(c)
297296

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

332-
var importLocation []ethernet.ImportLocation
333331
api := ethernet.NewService(c)
334332

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

358-
var importLocation []ethernet.ImportLocation
359356
api := ethernet.NewService(c)
360357

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

573-
var importLocation []ethernet.ImportLocation
574570
api := ethernet.NewService(c)
575571

576572
interfacesToDelete := []string{"ethernet1/2", "ethernet1/3"}
577573
for _, iface := range interfacesToDelete {
578-
err = api.Delete(ctx, *ethernetLocation, importLocation, iface)
574+
err = api.Delete(ctx, *ethernetLocation, iface)
579575
if err != nil {
580576
log.Printf("Failed to delete ethernet: %s", err)
581577
return

assets/terraform/internal/manager/entry_import.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ import (
1010
"github.com/PaloAltoNetworks/pango/xmlapi"
1111
)
1212

13-
type SDKImportableEntryService[E EntryObject, L EntryLocation, IL ImportLocation] interface {
13+
type SDKImportableEntryService[E EntryObject, L EntryLocation] interface {
1414
CreateWithXpath(context.Context, string, E) error
1515
ReadWithXpath(context.Context, string, string) (E, error)
1616
List(context.Context, L, string, string, string) ([]E, error)
1717
UpdateWithXpath(context.Context, string, E, string) error
18-
Delete(context.Context, L, []IL, ...string) error
19-
ImportToLocations(context.Context, L, []IL, string) error
20-
UnimportFromLocations(context.Context, L, []IL, []string) error
18+
Delete(context.Context, L, string, ...string) error
19+
ImportToLocation(context.Context, L, string, string) error
20+
UnimportFromLocation(context.Context, L, string, string) error
2121
}
2222

23-
type ImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLocation, IS SDKImportableEntryService[E, L, IL]] struct {
23+
type ImportableEntryObjectManager[E EntryObject, L EntryLocation, IS SDKImportableEntryService[E, L]] struct {
2424
batchSize int
2525
service IS
2626
client SDKClient
2727
specifier func(E) (any, error)
2828
matcher func(E, E) bool
2929
}
3030

31-
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] {
32-
return &ImportableEntryObjectManager[E, L, IL, IS]{
31+
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] {
32+
return &ImportableEntryObjectManager[E, L, IS]{
3333
batchSize: batchSize,
3434
service: service,
3535
client: client,
@@ -38,11 +38,11 @@ func NewImportableEntryObjectManager[E EntryObject, L EntryLocation, IL ImportLo
3838
}
3939
}
4040

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

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

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

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

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

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

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

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

130-
func (o *ImportableEntryObjectManager[E, L, IL, IS]) UnimportFromLocations(ctx context.Context, location L, importLocs []IL, entry string) error {
131-
return o.service.UnimportFromLocations(ctx, location, importLocs, []string{entry})
130+
func (o *ImportableEntryObjectManager[E, L, IS]) UnimportFromLocation(ctx context.Context, location L, vsys string, entry string) error {
131+
return o.service.UnimportFromLocation(ctx, location, vsys, entry)
132132
}

assets/terraform/internal/manager/manager.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"net/http"
88
"net/url"
99

10-
"github.com/PaloAltoNetworks/pango/util"
1110
"github.com/PaloAltoNetworks/pango/version"
1211
"github.com/PaloAltoNetworks/pango/xmlapi"
1312
)
@@ -57,9 +56,3 @@ type SDKClient interface {
5756
ChunkedMultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]xmlapi.ChunkedMultiConfigResponse, error)
5857
MultiConfig(context.Context, *xmlapi.MultiConfig, bool, url.Values) ([]byte, *http.Response, *xmlapi.MultiConfigResponse, error)
5958
}
60-
61-
type ImportLocation interface {
62-
XpathForLocation(version.Number, util.ILocation) ([]string, error)
63-
MarshalPangoXML([]string) (string, error)
64-
UnmarshalPangoXML([]byte) ([]string, error)
65-
}

0 commit comments

Comments
 (0)