1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 )
23
24
25
26
27
28
29 type ProtectedEnvironmentsService struct {
30 client *Client
31 }
32
33
34
35
36
37 type ProtectedEnvironment struct {
38 Name string `json:"name"`
39 DeployAccessLevels []*EnvironmentAccessDescription `json:"deploy_access_levels"`
40 RequiredApprovalCount int `json:"required_approval_count"`
41 ApprovalRules []*EnvironmentApprovalRule `json:"approval_rules"`
42 }
43
44
45
46
47
48
49 type EnvironmentAccessDescription struct {
50 ID int `json:"id"`
51 AccessLevel AccessLevelValue `json:"access_level"`
52 AccessLevelDescription string `json:"access_level_description"`
53 UserID int `json:"user_id"`
54 GroupID int `json:"group_id"`
55 GroupInheritanceType int `json:"group_inheritance_type"`
56 }
57
58
59
60
61
62
63 type EnvironmentApprovalRule struct {
64 ID int `json:"id"`
65 UserID int `json:"user_id"`
66 GroupID int `json:"group_id"`
67 AccessLevel AccessLevelValue `json:"access_level"`
68 AccessLevelDescription string `json:"access_level_description"`
69 RequiredApprovalCount int `json:"required_approvals"`
70 GroupInheritanceType int `json:"group_inheritance_type"`
71 }
72
73
74
75
76
77
78 type ListProtectedEnvironmentsOptions ListOptions
79
80
81
82
83
84
85 func (s *ProtectedEnvironmentsService) ListProtectedEnvironments(pid interface{}, opt *ListProtectedEnvironmentsOptions, options ...RequestOptionFunc) ([]*ProtectedEnvironment, *Response, error) {
86 project, err := parseID(pid)
87 if err != nil {
88 return nil, nil, err
89 }
90 u := fmt.Sprintf("projects/%s/protected_environments", PathEscape(project))
91
92 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
93 if err != nil {
94 return nil, nil, err
95 }
96
97 var pes []*ProtectedEnvironment
98 resp, err := s.client.Do(req, &pes)
99 if err != nil {
100 return nil, resp, err
101 }
102
103 return pes, resp, nil
104 }
105
106
107
108
109
110
111 func (s *ProtectedEnvironmentsService) GetProtectedEnvironment(pid interface{}, environment string, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) {
112 project, err := parseID(pid)
113 if err != nil {
114 return nil, nil, err
115 }
116 u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment))
117
118 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
119 if err != nil {
120 return nil, nil, err
121 }
122
123 pe := new(ProtectedEnvironment)
124 resp, err := s.client.Do(req, pe)
125 if err != nil {
126 return nil, resp, err
127 }
128
129 return pe, resp, nil
130 }
131
132
133
134
135
136
137 type ProtectRepositoryEnvironmentsOptions struct {
138 Name *string `url:"name,omitempty" json:"name,omitempty"`
139 DeployAccessLevels *[]*EnvironmentAccessOptions `url:"deploy_access_levels,omitempty" json:"deploy_access_levels,omitempty"`
140 RequiredApprovalCount *int `url:"required_approval_count,omitempty" json:"required_approval_count,omitempty"`
141 ApprovalRules *[]*EnvironmentApprovalRuleOptions `url:"approval_rules,omitempty" json:"approval_rules,omitempty"`
142 }
143
144
145
146
147
148
149 type EnvironmentAccessOptions struct {
150 AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
151 UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
152 GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
153 GroupInheritanceType *int `url:"group_inheritance_type,omitempty" json:"group_inheritance_type,omitempty"`
154 }
155
156
157
158
159
160
161 type EnvironmentApprovalRuleOptions struct {
162 UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
163 GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
164 AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
165 AccessLevelDescription *string `url:"access_level_description,omitempty" json:"access_level_description,omitempty"`
166 RequiredApprovalCount *int `url:"required_approvals,omitempty" json:"required_approvals,omitempty"`
167 GroupInheritanceType *int `url:"group_inheritance_type,omitempty" json:"group_inheritance_type,omitempty"`
168 }
169
170
171
172
173
174
175 func (s *ProtectedEnvironmentsService) ProtectRepositoryEnvironments(pid interface{}, opt *ProtectRepositoryEnvironmentsOptions, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) {
176 project, err := parseID(pid)
177 if err != nil {
178 return nil, nil, err
179 }
180 u := fmt.Sprintf("projects/%s/protected_environments", PathEscape(project))
181
182 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
183 if err != nil {
184 return nil, nil, err
185 }
186
187 pe := new(ProtectedEnvironment)
188 resp, err := s.client.Do(req, pe)
189 if err != nil {
190 return nil, resp, err
191 }
192
193 return pe, resp, nil
194 }
195
196
197
198
199
200
201 type UpdateProtectedEnvironmentsOptions struct {
202 Name *string `url:"name,omitempty" json:"name,omitempty"`
203 DeployAccessLevels *[]*UpdateEnvironmentAccessOptions `url:"deploy_access_levels,omitempty" json:"deploy_access_levels,omitempty"`
204 RequiredApprovalCount *int `url:"required_approval_count,omitempty" json:"required_approval_count,omitempty"`
205 ApprovalRules *[]*UpdateEnvironmentApprovalRuleOptions `url:"approval_rules,omitempty" json:"approval_rules,omitempty"`
206 }
207
208
209
210
211
212
213 type UpdateEnvironmentAccessOptions struct {
214 AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
215 ID *int `url:"id,omitempty" json:"id,omitempty"`
216 UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
217 GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
218 GroupInheritanceType *int `url:"group_inheritance_type,omitempty" json:"group_inheritance_type,omitempty"`
219 Destroy *bool `url:"_destroy,omitempty" json:"_destroy,omitempty"`
220 }
221
222
223
224
225
226
227 type UpdateEnvironmentApprovalRuleOptions struct {
228 ID *int `url:"id,omitempty" json:"id,omitempty"`
229 UserID *int `url:"user_id,omitempty" json:"user_id,omitempty"`
230 GroupID *int `url:"group_id,omitempty" json:"group_id,omitempty"`
231 AccessLevel *AccessLevelValue `url:"access_level,omitempty" json:"access_level,omitempty"`
232 AccessLevelDescription *string `url:"access_level_description,omitempty" json:"access_level_description,omitempty"`
233 RequiredApprovalCount *int `url:"required_approvals,omitempty" json:"required_approvals,omitempty"`
234 GroupInheritanceType *int `url:"group_inheritance_type,omitempty" json:"group_inheritance_type,omitempty"`
235 Destroy *bool `url:"_destroy,omitempty" json:"_destroy,omitempty"`
236 }
237
238
239
240
241
242
243 func (s *ProtectedEnvironmentsService) UpdateProtectedEnvironments(pid interface{}, environment string, opt *UpdateProtectedEnvironmentsOptions, options ...RequestOptionFunc) (*ProtectedEnvironment, *Response, error) {
244 project, err := parseID(pid)
245 if err != nil {
246 return nil, nil, err
247 }
248 u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment))
249
250 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
251 if err != nil {
252 return nil, nil, err
253 }
254
255 pe := new(ProtectedEnvironment)
256 resp, err := s.client.Do(req, pe)
257 if err != nil {
258 return nil, resp, err
259 }
260
261 return pe, resp, nil
262 }
263
264
265
266
267
268
269 func (s *ProtectedEnvironmentsService) UnprotectEnvironment(pid interface{}, environment string, options ...RequestOptionFunc) (*Response, error) {
270 project, err := parseID(pid)
271 if err != nil {
272 return nil, err
273 }
274 u := fmt.Sprintf("projects/%s/protected_environments/%s", PathEscape(project), PathEscape(environment))
275
276 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
277 if err != nil {
278 return nil, err
279 }
280
281 return s.client.Do(req, nil)
282 }
283
View as plain text