Skip to content

Commit 2cd09d6

Browse files
committed
chore: Remove 'spec' prefix from pango type names
1 parent c7f6cb3 commit 2cd09d6

File tree

7 files changed

+73
-71
lines changed

7 files changed

+73
-71
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/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/structs.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ 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"
79
"github.com/paloaltonetworks/pan-os-codegen/pkg/version"
8-
"strings"
910
)
1011

1112
// LocationType function used in template location.tmpl to generate location type name.
@@ -21,7 +22,7 @@ func LocationType(location *properties.Location, pointer bool) string {
2122
}
2223
}
2324

24-
// NestedSpecs go through all params and one of (recursively) and return map of all nested specs.
25+
// NestedSpecs goes through all params and one ofs (recursively) and returns map of all nested specs.
2526
func NestedSpecs(spec *properties.Spec) (map[string]*properties.Spec, error) {
2627
nestedSpecs := make(map[string]*properties.Spec)
2728

@@ -65,7 +66,7 @@ func addNameAsParamForNestedSpec(parent []string, nestedSpecs map[string]*proper
6566
}
6667
}
6768

68-
// SpecParamType return param type (it can be nested spec) (for struct based on spec from YAML files).
69+
// SpecParamType returns param type (it can be a nested spec) for structs based on spec from YAML files.
6970
func SpecParamType(parent string, param *properties.SpecParam) string {
7071
prefix := determinePrefix(param, false)
7172

@@ -122,11 +123,11 @@ func determineListType(param *properties.SpecParam) string {
122123
}
123124

124125
func calculateNestedSpecType(parent string, param *properties.SpecParam) string {
125-
return fmt.Sprintf("Spec%s%s", parent, naming.CamelCase("", param.Name.CamelCase, "", true))
126+
return fmt.Sprintf("%s%s", parent, naming.CamelCase("", param.Name.CamelCase, "", true))
126127
}
127128

128129
func calculateNestedXmlSpecType(parent string, param *properties.SpecParam) string {
129-
return fmt.Sprintf("spec%s%sXml", parent, naming.CamelCase("", param.Name.CamelCase, "", true))
130+
return fmt.Sprintf("%s%sXml", parent, naming.CamelCase("", param.Name.CamelCase, "", true))
130131
}
131132

132133
// XmlName creates a string with xml name (e.g. `description`).

templates/sdk/config.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121
{{- range $name, $spec := nestedSpecs $.Spec }}
22-
type Spec{{$name}}{{createGoSuffixFromVersion ""}} struct {
22+
type {{$name}}{{createGoSuffixFromVersion ""}} struct {
2323
{{- range $_, $param := $spec.Params}}
2424
{{$param.Name.CamelCase}} {{specParamType $name $param}}
2525
{{- end}}
@@ -64,7 +64,7 @@
6464

6565
{{- range $version := .SupportedVersions }}
6666
{{- range $name, $spec := nestedSpecs $.Spec }}
67-
type spec{{$name}}Xml{{createGoSuffixFromVersion $version}} struct {
67+
type {{$name}}Xml{{createGoSuffixFromVersion $version}} struct {
6868
{{- range $_, $param := $spec.Params}}
6969
{{- if paramSupportedInVersion $param $version}}
7070
{{- if $param.Spec}}

0 commit comments

Comments
 (0)