-
Notifications
You must be signed in to change notification settings - Fork 7
/
firewall_object_vip.go
135 lines (116 loc) · 3.67 KB
/
firewall_object_vip.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package fmgclient
import (
"fmt"
"github.com/fortinetdev/forti-sdk-go/fortimanager/util"
)
// JSONFirewallObjectVip contains the params for creating firewall object virtual ip
type JSONFirewallObjectVip struct {
Name string `json:"name"`
Comment string `json:"comment"`
Type string `json:"type"`
ArpReply string `json:"arp-reply"`
MappedIp string `json:"mappedip"`
ExtIp string `json:"extip"`
ExtIntf string `json:"extintf"`
ConfigDefault string `json:"_if_no_default"`
MappedAddr string `json:"mapped-addr"`
}
// CreateUpdateFirewallObjectVip is for creating/updating the firewall object virtual ip
// Input:
// @params: infor needed
// @method: operation method, "add" or "update"
// @adom: adom
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) CreateUpdateFirewallObjectVip(params *JSONFirewallObjectVip, method, adom string) (err error) {
defer c.Trace("CreateUpdateFirewallObjectVip")()
p := map[string]interface{}{
"data": params,
"url": "/pm/config/adom/" + adom + "/obj/firewall/vip",
}
_, err = c.Do(method, p)
if err != nil {
err = fmt.Errorf("CreateUpdateFirewallObjectVip failed: %s", err)
return
}
return
}
// ReadFirewallObjectVip is for reading the specific firewall object virtual ip
// Input:
// @name: firewall object virtual ip name
// @adom: adom
// Output:
// @out: firewall object virtual ip infor
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) ReadFirewallObjectVip(adom, name string) (out *JSONFirewallObjectVip, err error) {
defer c.Trace("ReadFirewallObjectVip")()
p := map[string]interface{}{
"url": "/pm/config/adom/" + adom + "/obj/firewall/vip/" + name,
}
result, err := c.Do("get", p)
if err != nil {
err = fmt.Errorf("ReadFirewallObjectVip failed: %s", err)
return
}
data := (result["result"].([]interface{}))[0].(map[string]interface{})["data"].(map[string]interface{})
if data == nil {
err = fmt.Errorf("cannot get the results from the response")
return
}
out = &JSONFirewallObjectVip{}
if data["name"] != nil {
out.Name = data["name"].(string)
}
if data["type"] != nil {
out.Type = util.FirewallObjectVipType2Str(int(data["type"].(float64)))
}
if data["comment"] != nil {
out.Comment = data["comment"].(string)
}
if data["arp-reply"] != nil {
out.ArpReply = util.ControlSwitch2Str(int(data["arp-reply"].(float64)))
}
if data["mappedip"] != nil {
m := util.InterfaceArray2StrArray(data["mappedip"].([]interface{}))
out.MappedIp = m[0]
}
if data["extip"] != nil {
m := util.InterfaceArray2StrArray(data["extip"].([]interface{}))
out.ExtIp = m[0]
}
if data["extintf"] != nil {
m := util.InterfaceArray2StrArray(data["extintf"].([]interface{}))
out.ExtIntf = m[0]
}
if data["_if_no_default"] != nil {
v := util.ControlSwitch2Str(int(data["_if_no_default"].(float64)))
if v == "enable" {
out.ConfigDefault = "disable"
} else {
out.ConfigDefault = "enable"
}
}
if data["mapped-addr"] != nil {
m := util.InterfaceArray2StrArray(data["mapped-addr"].([]interface{}))
out.MappedAddr = m[0]
}
return
}
// DeleteFirewallObjectVip is for deleting the specific firewall object virtual ip
// Input:
// @adom: adom
// @name: firewall object virtual ip name
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) DeleteFirewallObjectVip(adom, name string) (err error) {
defer c.Trace("DeleteFirewallObjectVip")()
p := map[string]interface{}{
"url": "/pm/config/adom/" + adom + "/obj/firewall/vip/" + name,
}
_, err = c.Do("delete", p)
if err != nil {
err = fmt.Errorf("DeleteFirewallObjectVip failed: %s", err)
return
}
return
}