/
funcs.go
94 lines (79 loc) · 1.79 KB
/
funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package radius
import (
"fmt"
"github.com/PaloAltoNetworks/pango/namespace"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/version"
)
func versioning(v version.Number) (normalizer, func(Entry) interface{}) {
if v.Gte(version.Number{8, 1, 0, ""}) {
return &container_v3{}, specify_v3
} else if v.Gte(version.Number{8, 0, 0, ""}) {
return &container_v2{}, specify_v2
} else {
return &container_v1{}, specify_v1
}
}
func specifier(e ...Entry) []namespace.Specifier {
ans := make([]namespace.Specifier, 0, len(e))
var val namespace.Specifier
for _, x := range e {
val = x
ans = append(ans, val)
}
return ans
}
func container(v version.Number) normalizer {
r, _ := versioning(v)
return r
}
func first(ans normalizer, err error) (Entry, error) {
if err != nil {
return Entry{}, err
}
return ans.Normalize()[0], nil
}
func all(ans normalizer, err error) ([]Entry, error) {
if err != nil {
return nil, err
}
return ans.Normalize(), nil
}
func toNames(e []interface{}) ([]string, error) {
ans := make([]string, len(e))
for i := range e {
switch v := e[i].(type) {
case string:
ans[i] = v
case Entry:
ans[i] = v.Name
default:
return nil, fmt.Errorf("invalid type: %s", v)
}
}
return ans, nil
}
// FirewallNamespace returns an initialized namespace.
func FirewallNamespace(client util.XapiClient) *Firewall {
return &Firewall{
ns: &namespace.Standard{
Common: namespace.Common{
Singular: singular,
Plural: plural,
Client: client,
},
},
}
}
// PanoramaNamespace returns an initialized namespace.
func PanoramaNamespace(client util.XapiClient) *Panorama {
return &Panorama{
ns: &namespace.Standard{
Common: namespace.Common{
Singular: singular,
Plural: plural,
Client: client,
},
},
}
}