/
pano.go
96 lines (83 loc) · 2.31 KB
/
pano.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
95
96
package filetype
import (
"regexp"
"github.com/PaloAltoNetworks/pango/namespace"
"github.com/PaloAltoNetworks/pango/util"
)
// Panorama is the client.Predefined.TdbFileType namespace.
type Panorama struct {
ns *namespace.Standard
}
// GetList performs GET to retrieve a list of all objects.
func (c *Panorama) GetList() ([]string, error) {
ans := c.container()
return c.ns.Listing(util.Get, c.pather(), ans)
}
// ShowList performs SHOW to retrieve a list of all objects.
func (c *Panorama) ShowList() ([]string, error) {
ans := c.container()
return c.ns.Listing(util.Show, c.pather(), ans)
}
// Get performs GET to retrieve information for the given object.
func (c *Panorama) Get(name string) (Entry, error) {
ans := c.container()
err := c.ns.Object(util.Get, c.pather(), name, ans)
return first(ans, err)
}
// Show performs SHOW to retrieve information for the given object.
func (c *Panorama) Show(name string) (Entry, error) {
ans := c.container()
err := c.ns.Object(util.Show, c.pather(), name, ans)
return first(ans, err)
}
// GetMatches performs GET to retrieve a list of objects whose full
// name matches the given regex.
func (c *Panorama) GetMatches(expr string) ([]Entry, error) {
var err error
var re *regexp.Regexp
if expr != "" {
re, err = regexp.Compile(expr)
if err != nil {
return nil, err
}
}
ans := c.container()
err = c.ns.Objects(util.Get, c.pather(), ans)
return finder(ans, re, err)
}
// ShowMatches performs SHOW to retrieve a list of objects whose full
// name matches the given regex.
func (c *Panorama) ShowMatches(expr string) ([]Entry, error) {
var err error
var re *regexp.Regexp
if expr != "" {
re, err = regexp.Compile(expr)
if err != nil {
return nil, err
}
}
ans := c.container()
err = c.ns.Objects(util.Show, c.pather(), ans)
return finder(ans, re, err)
}
// Making this private so we can still do unit tests.
func (c *Panorama) set(e ...Entry) error {
return c.ns.Set(c.pather(), specifier(e...))
}
func (c *Panorama) pather() namespace.Pather {
return func(v []string) ([]string, error) {
return c.xpath(v)
}
}
func (c *Panorama) xpath(vals []string) ([]string, error) {
return []string{
"config",
"predefined",
"tdb",
"file-type",
util.AsEntryXpath(vals),
}, nil
}
func (c *Panorama) container() normalizer {
return container(c.ns.Client.Versioning())
}