Skip to content

Commit a98a3b6

Browse files
authored
chore: Remove 'spec' prefix from pango type and func names (#115)
* chore: Remove 'spec' prefix from pango type names * fix: update tests
1 parent c7f6cb3 commit a98a3b6

File tree

9 files changed

+82
-80
lines changed

9 files changed

+82
-80
lines changed

assets/pango/example/main.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ func checkTemplate(c *pango.Client, ctx context.Context) {
8888
Name: "codegen_template",
8989
Description: util.String("This is a template created by codegen."),
9090
DefaultVsys: util.String("vsys1"),
91-
Config: &template.SpecConfig{
92-
Devices: []template.SpecConfigDevices{
91+
Config: &template.Config{
92+
Devices: []template.ConfigDevices{
9393
{
9494
Name: "localhost.localdomain",
95-
Vsys: []template.SpecConfigDevicesVsys{
95+
Vsys: []template.ConfigDevicesVsys{
9696
{
9797
Name: "vsys1",
9898
},
@@ -182,41 +182,41 @@ func checkSharedObjects(c *pango.Client, ctx context.Context) {
182182
func checkVr(c *pango.Client, ctx context.Context) {
183183
entry := virtual_router.Entry{
184184
Name: "codegen_vr",
185-
Protocol: &virtual_router.SpecProtocol{
186-
Bgp: &virtual_router.SpecProtocolBgp{
185+
Protocol: &virtual_router.Protocol{
186+
Bgp: &virtual_router.ProtocolBgp{
187187
Enable: util.Bool(false),
188188
},
189-
Ospf: &virtual_router.SpecProtocolOspf{
189+
Ospf: &virtual_router.ProtocolOspf{
190190
Enable: util.Bool(false),
191191
},
192-
Ospfv3: &virtual_router.SpecProtocolOspfv3{
192+
Ospfv3: &virtual_router.ProtocolOspfv3{
193193
Enable: util.Bool(false),
194194
},
195-
Rip: &virtual_router.SpecProtocolRip{
195+
Rip: &virtual_router.ProtocolRip{
196196
Enable: util.Bool(false),
197197
},
198198
},
199-
RoutingTable: &virtual_router.SpecRoutingTable{
200-
// Ip: &virtual_router.SpecRoutingTableIp{
201-
// StaticRoutes: []virtual_router.SpecRoutingTableIpStaticRoutes{
199+
RoutingTable: &virtual_router.RoutingTable{
200+
// Ip: &virtual_router.RoutingTableIp{
201+
// StaticRoutes: []virtual_router.RoutingTableIpStaticRoutes{
202202
// {
203203
// Name: "default",
204204
// Destination: util.String("0.0.0.0/0"),
205205
// Interface: util.String("ethernet1/2"),
206-
// NextHop: &virtual_router.SpecRoutingTableIpStaticRoutesNextHop{
206+
// NextHop: &virtual_router.RoutingTableIpStaticRoutesNextHop{
207207
// IpAddress: util.String("1.1.1.1"),
208208
// },
209209
// Metric: util.Int(64),
210210
// AdminDist: util.Int(120),
211211
// },
212212
// },
213213
// },
214-
// Ipv6: &virtual_router.SpecRoutingTableIpv6{
215-
// StaticRoutes: []virtual_router.SpecRoutingTableIpv6StaticRoutes{
214+
// Ipv6: &virtual_router.RoutingTableIpv6{
215+
// StaticRoutes: []virtual_router.RoutingTableIpv6StaticRoutes{
216216
// {
217217
// Name: "default",
218218
// Destination: util.String("0.0.0.0/0"),
219-
// NextHop: &virtual_router.SpecRoutingTableIpv6StaticRoutesNextHop{
219+
// NextHop: &virtual_router.RoutingTableIpv6StaticRoutesNextHop{
220220
// Ipv6Address: util.String("2001:0000:130F:0000:0000:09C0:876A:230D"),
221221
// },
222222
// Metric: util.Int(24),
@@ -225,18 +225,18 @@ func checkVr(c *pango.Client, ctx context.Context) {
225225
// },
226226
// },
227227
},
228-
Ecmp: &virtual_router.SpecEcmp{
228+
Ecmp: &virtual_router.Ecmp{
229229
Enable: util.Bool(true),
230230
SymmetricReturn: util.Bool(true),
231231
MaxPaths: util.Int(3),
232-
Algorithm: &virtual_router.SpecEcmpAlgorithm{
233-
// IpHash: &virtual_router.SpecEcmpAlgorithmIpHash{
232+
Algorithm: &virtual_router.EcmpAlgorithm{
233+
// IpHash: &virtual_router.EcmpAlgorithmIpHash{
234234
// HashSeed: util.Int(1234),
235235
// UsePort: util.Bool(true),
236236
// SrcOnly: util.Bool(true),
237237
// },
238-
// WeightedRoundRobin: &virtual_router.SpecEcmpAlgorithmWeightedRoundRobin{
239-
// Interfaces: []virtual_router.SpecEcmpAlgorithmWeightedRoundRobinInterfaces{
238+
// WeightedRoundRobin: &virtual_router.EcmpAlgorithmWeightedRoundRobin{
239+
// Interfaces: []virtual_router.EcmpAlgorithmWeightedRoundRobinInterfaces{
240240
// {
241241
// Name: "ethernet1/2",
242242
// Weight: util.Int(1),
@@ -249,7 +249,7 @@ func checkVr(c *pango.Client, ctx context.Context) {
249249
// },
250250
},
251251
},
252-
AdministrativeDistances: &virtual_router.SpecAdministrativeDistances{
252+
AdministrativeDistances: &virtual_router.AdministrativeDistances{
253253
OspfInt: util.Int(77),
254254
OspfExt: util.Int(88),
255255
},
@@ -275,18 +275,18 @@ func checkEthernetLayer3Static(c *pango.Client, ctx context.Context) {
275275
entry := ethernet.Entry{
276276
Name: "ethernet1/2",
277277
Comment: util.String("This is a ethernet1/2"),
278-
Layer3: &ethernet.SpecLayer3{
278+
Layer3: &ethernet.Layer3{
279279
NdpProxy: util.Bool(true),
280280
Lldp: util.Bool(true),
281-
AdjustTcpMss: &ethernet.SpecLayer3AdjustTcpMss{
281+
AdjustTcpMss: &ethernet.Layer3AdjustTcpMss{
282282
Enable: util.Bool(true),
283283
Ipv4MssAdjustment: util.Int(250),
284284
Ipv6MssAdjustment: util.Int(250),
285285
},
286286
Mtu: util.Int(1280),
287287
Ips: []string{"11.11.11.11", "22.22.22.22"},
288-
Ipv6: &ethernet.SpecLayer3Ipv6{
289-
Addresses: []ethernet.SpecLayer3Ipv6Addresses{
288+
Ipv6: &ethernet.Layer3Ipv6{
289+
Addresses: []ethernet.Layer3Ipv6Addresses{
290290
{
291291
EnableOnInterface: util.Bool(false),
292292
Name: "2001:0000:130F:0000:0000:09C0:876A:230B",
@@ -321,13 +321,13 @@ func checkEthernetLayer3Dhcp(c *pango.Client, ctx context.Context) {
321321
entry := ethernet.Entry{
322322
Name: "ethernet1/3",
323323
Comment: util.String("This is a ethernet1/3"),
324-
Layer3: &ethernet.SpecLayer3{
324+
Layer3: &ethernet.Layer3{
325325
InterfaceManagementProfile: util.String("codegen_mgmt_profile"),
326-
DhcpClient: &ethernet.SpecLayer3DhcpClient{
326+
DhcpClient: &ethernet.Layer3DhcpClient{
327327
CreateDefaultRoute: util.Bool(false),
328328
DefaultRouteMetric: util.Int(64),
329329
Enable: util.Bool(true),
330-
SendHostname: &ethernet.SpecLayer3DhcpClientSendHostname{
330+
SendHostname: &ethernet.Layer3DhcpClientSendHostname{
331331
Enable: util.Bool(true),
332332
Hostname: util.String("codegen_dhcp"),
333333
},
@@ -355,7 +355,7 @@ func checkEthernetHa(c *pango.Client, ctx context.Context) {
355355
entry := ethernet.Entry{
356356
Name: "ethernet1/10",
357357
Comment: util.String("This is a ethernet1/10"),
358-
Ha: &ethernet.SpecHa{},
358+
Ha: &ethernet.Ha{},
359359
}
360360
var location *ethernet.Location
361361
if ok, _ := c.IsPanorama(); ok {
@@ -377,16 +377,16 @@ func checkEthernetHa(c *pango.Client, ctx context.Context) {
377377
func checkLoopback(c *pango.Client, ctx context.Context) {
378378
entry := loopback.Entry{
379379
Name: "loopback.123",
380-
AdjustTcpMss: &loopback.SpecAdjustTcpMss{
380+
AdjustTcpMss: &loopback.AdjustTcpMss{
381381
Enable: util.Bool(true),
382382
Ipv4MssAdjustment: util.Int(250),
383383
Ipv6MssAdjustment: util.Int(250),
384384
},
385385
Comment: util.String("This is a loopback entry"),
386386
Mtu: util.Int(1280),
387387
Ips: []string{"1.1.1.1", "2.2.2.2"},
388-
Ipv6: &loopback.SpecIpv6{
389-
Addresses: []loopback.SpecIpv6Addresses{
388+
Ipv6: &loopback.Ipv6{
389+
Addresses: []loopback.Ipv6Addresses{
390390
{
391391
EnableOnInterface: util.Bool(false),
392392
Name: "2001:0000:130F:0000:0000:09C0:876A:130B",
@@ -420,14 +420,14 @@ func checkZone(c *pango.Client, ctx context.Context) {
420420
entry := zone.Entry{
421421
Name: "codegen_zone",
422422
EnableUserIdentification: util.Bool(true),
423-
Network: &zone.SpecNetwork{
423+
Network: &zone.Network{
424424
EnablePacketBufferProtection: util.Bool(false),
425425
Layer3: []string{},
426426
},
427-
DeviceAcl: &zone.SpecDeviceAcl{
427+
DeviceAcl: &zone.DeviceAcl{
428428
IncludeList: []string{"1.2.3.4"},
429429
},
430-
UserAcl: &zone.SpecUserAcl{
430+
UserAcl: &zone.UserAcl{
431431
ExcludeList: []string{"1.2.3.4"},
432432
},
433433
}
@@ -516,7 +516,7 @@ func checkVrZoneWithEthernet(c *pango.Client, ctx context.Context) {
516516
}
517517
log.Printf("Zone %s read\n", replyZone.Name)
518518

519-
replyZone.Network = &zone.SpecNetwork{
519+
replyZone.Network = &zone.Network{
520520
EnablePacketBufferProtection: util.Bool(false),
521521
Layer3: []string{"ethernet1/2", "ethernet1/3"},
522522
}
@@ -539,7 +539,7 @@ func checkVrZoneWithEthernet(c *pango.Client, ctx context.Context) {
539539
log.Printf("VR %s updated with %s\n", replyVr.Name, replyVr.Interfaces)
540540

541541
// DELETE INTERFACES FROM ZONE
542-
replyZone.Network = &zone.SpecNetwork{
542+
replyZone.Network = &zone.Network{
543543
EnablePacketBufferProtection: util.Bool(false),
544544
Layer3: []string{},
545545
}
@@ -878,10 +878,10 @@ func checkService(c *pango.Client, ctx context.Context) {
878878
serviceObject := service.Entry{
879879
Name: "codegen_service_test1",
880880
Description: util.String("test description"),
881-
Protocol: &service.SpecProtocol{
882-
Tcp: &service.SpecProtocolTcp{
881+
Protocol: &service.Protocol{
882+
Tcp: &service.ProtocolTcp{
883883
DestinationPort: util.Int(8642),
884-
Override: &service.SpecProtocolTcpOverride{
884+
Override: &service.ProtocolTcpOverride{
885885
HalfcloseTimeout: util.Int(124),
886886
Timeout: util.Int(125),
887887
TimewaitTimeout: util.Int(127),
@@ -1035,8 +1035,8 @@ func checkService(c *pango.Client, ctx context.Context) {
10351035
func checkNtp(c *pango.Client, ctx context.Context) {
10361036
// NTP - ADD
10371037
ntpConfig := ntp.Config{
1038-
NtpServers: &ntp.SpecNtpServers{
1039-
PrimaryNtpServer: &ntp.SpecNtpServersPrimaryNtpServer{
1038+
NtpServers: &ntp.NtpServers{
1039+
PrimaryNtpServer: &ntp.NtpServersPrimaryNtpServer{
10401040
NtpServerAddress: util.String("11.12.13.14"),
10411041
},
10421042
},
@@ -1071,8 +1071,8 @@ func checkNtp(c *pango.Client, ctx context.Context) {
10711071
func checkDns(c *pango.Client, ctx context.Context) {
10721072
// DNS - ADD
10731073
dnsConfig := dns.Config{
1074-
DnsSetting: &dns.SpecDnsSetting{
1075-
Servers: &dns.SpecDnsSettingServers{
1074+
DnsSetting: &dns.DnsSetting{
1075+
Servers: &dns.DnsSettingServers{
10761076
Primary: util.String("8.8.8.8"),
10771077
Secondary: util.String("4.4.4.4"),
10781078
},

pkg/translate/assignments.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
// in entry.tmpl/config.tmpl template. If param contains nested specs, then recursively are executed
1212
// internal functions, which are creating entry assignment.
1313
func NormalizeAssignment(objectType string, param *properties.SpecParam, version string) string {
14-
return prepareAssignment(objectType, param, "util.MemToStr", "util.EntToStr", "util.AsBool", "Spec", "", version)
14+
return prepareAssignment(objectType, param, "util.MemToStr", "util.EntToStr", "util.AsBool", "", "", version)
1515
}
1616

1717
// SpecifyEntryAssignment generates a string, which contains entry/config assignment in SpecifyEntry() function
1818
// in entry.tmpl/config.tmpl template. If param contains nested specs, then recursively are executed
1919
// internal functions, which are creating entry assignment.
2020
func SpecifyEntryAssignment(objectType string, param *properties.SpecParam, version string) string {
21-
return prepareAssignment(objectType, param, "util.StrToMem", "util.StrToEnt", "util.YesNo", "spec", "Xml", version)
21+
return prepareAssignment(objectType, param, "util.StrToMem", "util.StrToEnt", "util.YesNo", "", "Xml", version)
2222
}
2323

2424
func prepareAssignment(objectType string, param *properties.SpecParam, listFunction, entryFunction, boolFunction, prefix, suffix string, version string) string {

pkg/translate/assignments_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ func TestSpecifyEntryAssignmentForNestedObject(t *testing.T) {
7575
},
7676
},
7777
}
78-
expectedAssignmentString := `var nestedA *specAXml
78+
expectedAssignmentString := `var nestedA *AXml
7979
if o.A != nil {
80-
nestedA = &specAXml{}
80+
nestedA = &AXml{}
8181
if _, ok := o.Misc["A"]; ok {
8282
nestedA.Misc = o.Misc["A"]
8383
}
8484
if o.A.B != nil {
85-
nestedA.B = &specABXml{}
85+
nestedA.B = &ABXml{}
8686
if _, ok := o.Misc["AB"]; ok {
8787
nestedA.B.Misc = o.Misc["AB"]
8888
}
@@ -132,14 +132,14 @@ func TestNormalizeAssignmentForNestedObject(t *testing.T) {
132132
},
133133
},
134134
}
135-
expectedAssignmentString := `var nestedA *SpecA
135+
expectedAssignmentString := `var nestedA *A
136136
if o.A != nil {
137-
nestedA = &SpecA{}
137+
nestedA = &A{}
138138
if o.A.Misc != nil {
139139
entry.Misc["A"] = o.A.Misc
140140
}
141141
if o.A.B != nil {
142-
nestedA.B = &SpecAB{}
142+
nestedA.B = &AB{}
143143
if o.A.B.Misc != nil {
144144
entry.Misc["AB"] = o.A.B.Misc
145145
}

pkg/translate/funcs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package translate
22

33
import (
44
"fmt"
5+
"strings"
6+
57
"github.com/paloaltonetworks/pan-os-codegen/pkg/naming"
68
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
7-
"strings"
89
)
910

1011
// GenerateEntryXpath functions used in location.tmpl to generate XPath for location.
@@ -46,7 +47,7 @@ func specMatchFunctionName(parent []string, param *properties.SpecParam) string
4647
} else if param.Type == "int64" {
4748
return "util.Ints64Match"
4849
} else {
49-
return fmt.Sprintf("specMatch%s%s", strings.Join(parent, ""), param.Name.CamelCase)
50+
return fmt.Sprintf("match%s%s", strings.Join(parent, ""), param.Name.CamelCase)
5051
}
5152
}
5253

@@ -83,7 +84,7 @@ func defineSpecMatchesFunction(parent []string, params map[string]*properties.Sp
8384

8485
func renderSpecMatchesFunctionSignature(parent []string, builder *strings.Builder, param *properties.SpecParam) {
8586
prefix := determinePrefix(param, false)
86-
builder.WriteString(fmt.Sprintf("func specMatch%s%s(a %s%s, b %s%s) bool {",
87+
builder.WriteString(fmt.Sprintf("func match%s%s(a %s%s, b %s%s) bool {",
8788
strings.Join(parent, ""), param.Name.CamelCase,
8889
prefix, argumentTypeForSpecMatchesFunction(parent, param),
8990
prefix, argumentTypeForSpecMatchesFunction(parent, param)))
@@ -95,7 +96,7 @@ func argumentTypeForSpecMatchesFunction(parent []string, param *properties.SpecP
9596
} else if param.Type == "int" {
9697
return "int"
9798
} else {
98-
return fmt.Sprintf("Spec%s%s",
99+
return fmt.Sprintf("%s%s",
99100
strings.Join(parent, ""), param.Name.CamelCase)
100101
}
101102
}

pkg/translate/funcs_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestNestedSpecMatchesFunction(t *testing.T) {
7878
},
7979
},
8080
}
81-
expectedNestedSpec := `func specMatchAB(a *SpecAB, b *SpecAB) bool {if a == nil && b != nil || a != nil && b == nil {
81+
expectedNestedSpec := `func matchAB(a *AB, b *AB) bool {if a == nil && b != nil || a != nil && b == nil {
8282
return false
8383
} else if a == nil && b == nil {
8484
return true
@@ -88,12 +88,12 @@ if !util.StringsMatch(a.C, b.C) {
8888
}
8989
return true
9090
}
91-
func specMatchA(a *SpecA, b *SpecA) bool {if a == nil && b != nil || a != nil && b == nil {
91+
func matchA(a *A, b *A) bool {if a == nil && b != nil || a != nil && b == nil {
9292
return false
9393
} else if a == nil && b == nil {
9494
return true
9595
}
96-
if !specMatchAB(a.B, b.B) {
96+
if !matchAB(a.B, b.B) {
9797
return false
9898
}
9999
return true

0 commit comments

Comments
 (0)