/
seclist.go
194 lines (159 loc) · 4.57 KB
/
seclist.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Copyright 2017 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package api
import (
"errors"
"fmt"
"github.com/juju/go-oracle-cloud/common"
"github.com/juju/go-oracle-cloud/response"
)
// CreatesSecList a security list. After creating security
// lists, you can add instances to them by using the HTTP request,
// CreateSecAssociation (Create a Security Association).
func (c *Client) CreateSecList(
description string,
name string,
outbound_cidr_policy common.SecRuleAction,
policy common.SecRuleAction,
) (resp response.SecList, err error) {
if !c.isAuth() {
return resp, errNotAuth
}
if name == "" {
return resp, errors.New("go-oracle-cloud: Empty secure list name")
}
if err = outbound_cidr_policy.Validate(); err != nil {
return resp, err
}
if err = policy.Validate(); err != nil {
return resp, err
}
params := struct {
Description string `json:"description,omitempty"`
Name string `json:"name"`
Outbound_cidr_policy common.SecRuleAction `json:"outbound_cidr_policy"`
Policy common.SecRuleAction `json:"policy"`
}{
Description: description,
Name: name,
Outbound_cidr_policy: outbound_cidr_policy,
Policy: policy,
}
url := c.endpoints["seclist"] + "/"
if err = c.request(paramsRequest{
url: url,
body: ¶ms,
verb: "POST",
resp: &resp,
}); err != nil {
return resp, err
}
return resp, nil
}
// DeleteSecList the specified security list. No response is returned.<Paste>
func (c *Client) DeleteSecList(name string) (err error) {
if !c.isAuth() {
return errNotAuth
}
if name == "" {
return errors.New("go-oracle-cloud: Empty secure list name")
}
url := fmt.Sprintf("%s%s", c.endpoints["seclist"], name)
if err = c.request(paramsRequest{
url: url,
verb: "DELETE",
}); err != nil {
return err
}
return nil
}
// AllSecLists retrieves details of the security lists that are in the specified
// container and match the specified query criteria.
// You can filter by name
func (c *Client) AllSecLists(filter []Filter) (resp response.AllSecLists, err error) {
if !c.isAuth() {
return resp, errNotAuth
}
url := fmt.Sprintf("%s/Compute-%s/%s/",
c.endpoints["seclist"], c.identify, c.username)
if err = c.request(paramsRequest{
url: url,
verb: "GET",
resp: &resp,
filter: filter,
}); err != nil {
return resp, err
}
return resp, nil
}
// SecListDetails retrieves information about the specified security list.
func (c *Client) SecListDetails(name string) (resp response.SecList, err error) {
if !c.isAuth() {
return resp, errNotAuth
}
if name == "" {
return resp, errors.New("go-oracle-cloud: Empty secure list name")
}
url := fmt.Sprintf("%s%s", c.endpoints["seclist"], name)
if err = c.request(paramsRequest{
url: url,
verb: "GET",
resp: &resp,
}); err != nil {
return resp, err
}
return resp, nil
}
// Updates inbound policy, outbound policy, and description for
// the specified security list.
// newName could be "" if you don't want to change the name
// but it's required at leas to have a currentName
// outbound_cidr_policy is the policy for outbound traffic
// from the security list. You can specify one of the following values:
// deny: Packets are dropped. No response is sent.
// reject: Packets are dropped, but a response is sent.
// permit(default): Packets are allowed.
func (c *Client) UpdateSecList(
description string,
currentName string,
newName string,
outbound_cidr_policy common.SecRuleAction,
policy common.SecRuleAction,
) (resp response.SecList, err error) {
if !c.isAuth() {
return resp, errNotAuth
}
if currentName == "" {
return resp, errors.New("go-oracle-cloud: Empty secure list name")
}
if newName == "" {
newName = currentName
}
if err = outbound_cidr_policy.Validate(); err != nil {
return resp, err
}
if err = policy.Validate(); err != nil {
return resp, err
}
params := struct {
Policy common.SecRuleAction `json:"policy"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
Outbound_cidr_policy common.SecRuleAction `json:"outbound_cidr_policy"`
}{
Description: description,
Name: newName,
Outbound_cidr_policy: outbound_cidr_policy,
Policy: policy,
}
url := fmt.Sprintf("%s%s", c.endpoints["seclist"], currentName)
if err = c.request(paramsRequest{
url: url,
body: ¶ms,
verb: "PUT",
resp: &resp,
}); err != nil {
return resp, err
}
return resp, nil
}