-
Notifications
You must be signed in to change notification settings - Fork 7
/
firewall_object_address.go
129 lines (110 loc) · 3.57 KB
/
firewall_object_address.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
package fmgclient
import (
"fmt"
"github.com/fortinetdev/forti-sdk-go/fortimanager/util"
)
// JSONFirewallObjectAddress contains the params for creating firewall object address
type JSONFirewallObjectAddress struct {
Name string `json:"name"`
Type string `json:"type"`
Comment string `json:"comment"`
Fqdn string `json:"fqdn"`
AssociatedIntf string `json:"associated-interface"`
Subnet string `json:"subnet"`
StartIp string `json:"start-ip"`
EndIp string `json:"end-ip"`
AllowRouting string `json:"allow-routing"`
}
// CreateUpdateFirewallObjectAddress is for creating/updating the firewall object address
// 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) CreateUpdateFirewallObjectAddress(params *JSONFirewallObjectAddress, method, adom string) (err error) {
defer c.Trace("CreateUpdateFirewallObjectAddress")()
p := map[string]interface{}{
"data": params,
"url": "/pm/config/adom/" + adom + "/obj/firewall/address",
}
_, err = c.Do(method, p)
if err != nil {
err = fmt.Errorf("CreateUpdateFirewallObjectAddress failed: %s", err)
return
}
return
}
// ReadFirewallObjectAddress is for reading the specific firewall object address
// Input:
// @name: firewall object addesss name
// @adom: adom
// Output:
// @out: firewall object address infor
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) ReadFirewallObjectAddress(adom, name string) (out *JSONFirewallObjectAddress, err error) {
defer c.Trace("ReadFirewallObjectAddress")()
p := map[string]interface{}{
"url": "/pm/config/adom/" + adom + "/obj/firewall/address/" + name,
}
result, err := c.Do("get", p)
if err != nil {
err = fmt.Errorf("ReadFirewallObjectAddress 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 = &JSONFirewallObjectAddress{}
if data["name"] != nil {
out.Name = data["name"].(string)
}
if data["type"] != nil {
out.Type = util.FirewallObjectAddrType2Str(int(data["type"].(float64)))
}
if data["comment"] != nil {
out.Comment = data["comment"].(string)
}
if data["fqdn"] != nil {
out.Fqdn = data["fqdn"].(string)
}
if data["associated-interface"] != nil {
m := util.InterfaceArray2StrArray(data["associated-interface"].([]interface{}))
// only 1 item is allowed here
out.AssociatedIntf = m[0]
}
if data["subnet"] != nil {
sn := data["subnet"].([]interface{})
out.Subnet = sn[0].(string) + " " + sn[1].(string)
}
if data["start-ip"] != nil {
out.StartIp = data["start-ip"].(string)
}
if data["end-ip"] != nil {
out.EndIp = data["end-ip"].(string)
}
if data["allow-routing"] != nil {
out.AllowRouting = util.ControlSwitch2Str(int(data["allow-routing"].(float64)))
}
return
}
// DeleteFirewallObjectAddress is for deleting the specific firewall object address
// Input:
// @adom: adom
// @name: firewall object addesss name
// Output:
// @err: error details if failure, and nil if success
func (c *FmgSDKClient) DeleteFirewallObjectAddress(adom, name string) (err error) {
defer c.Trace("DeleteFirewallObjectAddress")()
p := map[string]interface{}{
"url": "/pm/config/adom/" + adom + "/obj/firewall/address/" + name,
}
_, err = c.Do("delete", p)
if err != nil {
err = fmt.Errorf("DeleteFirewallObjectAddress failed: %s", err)
return
}
return
}