forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firewallrule.go
82 lines (73 loc) · 3.02 KB
/
firewallrule.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
package profitbricks
import (
"net/http"
)
//FirewallRule object
type FirewallRule struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Properties FirewallruleProperties `json:"properties,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//FirewallruleProperties object
type FirewallruleProperties struct {
Name string `json:"name"`
Protocol string `json:"protocol,omitempty"`
SourceMac *string `json:"sourceMac"`
SourceIP *string `json:"sourceIp"`
TargetIP *string `json:"targetIp"`
IcmpCode *int `json:"icmpCode"`
IcmpType *int `json:"icmpType"`
PortRangeStart *int `json:"portRangeStart"`
PortRangeEnd *int `json:"portRangeEnd"`
}
//FirewallRules object
type FirewallRules struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []FirewallRule `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
//ListFirewallRules lists all firewall rules
func (c *Client) ListFirewallRules(dcID string, serverID string, nicID string) (*FirewallRules, error) {
url := firewallRulesPath(dcID, serverID, nicID)
ret := &FirewallRules{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//GetFirewallRule gets a firewall rule
func (c *Client) GetFirewallRule(dcID string, serverID string, nicID string, fwID string) (*FirewallRule, error) {
url := firewallRulePath(dcID, serverID, nicID, fwID)
ret := &FirewallRule{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//CreateFirewallRule creates a firewall rule
func (c *Client) CreateFirewallRule(dcID string, serverID string, nicID string, fw FirewallRule) (*FirewallRule, error) {
url := firewallRulesPath(dcID, serverID, nicID)
ret := &FirewallRule{}
err := c.Post(url, fw, ret, http.StatusAccepted)
return ret, err
}
// UpdateFirewallRule updates a firewall rule.
// You need to pass all wanted properties, not just those you want to change.
func (c *Client) UpdateFirewallRule(dcID string, serverID string, nicID string, fwID string, obj FirewallruleProperties) (*FirewallRule, error) {
url := firewallRulePath(dcID, serverID, nicID, fwID)
ret := &FirewallRule{}
err := c.Patch(url, obj, ret, http.StatusAccepted)
return ret, err
}
//DeleteFirewallRule deletes a firewall rule
func (c *Client) DeleteFirewallRule(dcID string, serverID string, nicID string, fwID string) (*http.Header, error) {
url := firewallRulePath(dcID, serverID, nicID, fwID)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}