-
Notifications
You must be signed in to change notification settings - Fork 16
/
firewallrule.go
166 lines (142 loc) · 5.16 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package profitbricks
import (
"github.com/ionos-cloud/sdk-go/v5"
"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,omitempty"`
SourceIP *string `json:"sourceIp,omitempty"`
TargetIP *string `json:"targetIp,omitempty"`
IcmpCode *int `json:"icmpCode,omitempty"`
IcmpType *int `json:"icmpType,omitempty"`
PortRangeStart *int `json:"portRangeStart,omitempty"`
PortRangeEnd *int `json:"portRangeEnd,omitempty"`
}
//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) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.NicApi.DatacentersServersNicsFirewallrulesGet(ctx, dcID, serverID, nicID).Execute()
ret := FirewallRules{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
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) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.NicApi.DatacentersServersNicsFirewallrulesFindById(ctx, dcID, serverID, nicID, fwID).Execute()
ret := FirewallRule{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
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) {
input := ionoscloud.FirewallRule{}
if errConvert := convertToCore(&fw, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.NicApi.DatacentersServersNicsFirewallrulesPost(ctx, dcID, serverID, nicID).Firewallrule(input).Execute()
ret := FirewallRule{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
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) {
input := ionoscloud.FirewallruleProperties{}
if errConvert := convertToCore(&obj, &input); errConvert != nil {
return nil, errConvert
}
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
rsp, apiResponse, err := c.CoreSdk.NicApi.DatacentersServersNicsFirewallrulesPatch(ctx, dcID, serverID, nicID, fwID).Firewallrule(input).Execute()
ret := FirewallRule{}
if errConvert := convertToCompat(&rsp, &ret); errConvert != nil {
return nil, errConvert
}
fillInResponse(&ret, apiResponse)
return &ret, err
/*
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) {
ctx, cancel := c.GetContext()
if cancel != nil {
defer cancel()
}
_, apiResponse, err := c.CoreSdk.NicApi.DatacentersServersNicsFirewallrulesDelete(ctx, dcID, serverID, nicID, fwID).Execute()
return &apiResponse.Header, err
/*
url := firewallRulePath(dcID, serverID, nicID, fwID)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
*/
}