forked from PaloAltoNetworks/pango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticonf.go
78 lines (63 loc) · 1.57 KB
/
multiconf.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
package pango
import (
"encoding/xml"
"fmt"
"strings"
"github.com/PaloAltoNetworks/pango/util"
)
type MultiConfigure struct {
XMLName xml.Name `xml:"multi-configure-request"`
Reqs []MultiConfigureRequest
}
func (m *MultiConfigure) IncrementalIds() {
for i := range m.Reqs {
if m.Reqs[i].Id == "" {
m.Reqs[i].Id = fmt.Sprintf("%d", i+1)
}
}
}
type MultiConfigureRequest struct {
XMLName xml.Name
Id string `xml:"id,attr,omitempty"`
Xpath string `xml:"xpath,attr"`
Data interface{}
}
type MultiConfigureResponse struct {
XMLName xml.Name `xml:"response"`
Status string `xml:"status,attr"`
Code int `xml:"code,attr"`
Results []MultiConfigResponseElement `xml:"response"`
}
func (m *MultiConfigureResponse) Ok() bool {
return m.Status == "success"
}
func (m *MultiConfigureResponse) Error() string {
if len(m.Results) == 0 {
return ""
}
r := m.Results[len(m.Results)-1]
if r.Ok() {
return ""
}
return r.Message()
}
type MultiConfigResponseElement struct {
XMLName xml.Name `xml:"response"`
Status string `xml:"status,attr"`
Code int `xml:"code,attr"`
Id string `xml:"id,attr,omitempty"`
Msg McreMsg `xml:"msg"`
}
type McreMsg struct {
Line *util.CdataText `xml:"line"`
Message string `xml:",chardata"`
}
func (m *MultiConfigResponseElement) Ok() bool {
return m.Status == "success"
}
func (m *MultiConfigResponseElement) Message() string {
if m.Msg.Line != nil {
return strings.TrimSpace(m.Msg.Line.Text)
}
return m.Msg.Message
}