-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunnerpolicy.go
324 lines (287 loc) · 9.41 KB
/
runnerpolicy.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package gitpod
import (
"context"
"net/http"
"net/url"
"github.com/gitpod-io/gitpod-sdk-go/internal/apijson"
"github.com/gitpod-io/gitpod-sdk-go/internal/apiquery"
"github.com/gitpod-io/gitpod-sdk-go/internal/param"
"github.com/gitpod-io/gitpod-sdk-go/internal/requestconfig"
"github.com/gitpod-io/gitpod-sdk-go/option"
"github.com/gitpod-io/gitpod-sdk-go/packages/pagination"
)
// RunnerPolicyService contains methods and other services that help with
// interacting with the gitpod API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewRunnerPolicyService] method instead.
type RunnerPolicyService struct {
Options []option.RequestOption
}
// NewRunnerPolicyService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewRunnerPolicyService(opts ...option.RequestOption) (r *RunnerPolicyService) {
r = &RunnerPolicyService{}
r.Options = opts
return
}
// Creates a new policy for a runner.
//
// Use this method to:
//
// - Set up access controls
// - Define group permissions
// - Configure role-based access
//
// ### Examples
//
// - Create admin policy:
//
// Grants admin access to a group.
//
// ```yaml
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
// groupId: "f53d2330-3795-4c5d-a1f3-453121af9c60"
// role: RUNNER_ROLE_ADMIN
// ```
func (r *RunnerPolicyService) New(ctx context.Context, body RunnerPolicyNewParams, opts ...option.RequestOption) (res *RunnerPolicyNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "gitpod.v1.RunnerService/CreateRunnerPolicy"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Updates an existing runner policy.
//
// Use this method to:
//
// - Modify access levels
// - Change group roles
// - Update permissions
//
// ### Examples
//
// - Update policy role:
//
// Changes a group's access level.
//
// ```yaml
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
// groupId: "f53d2330-3795-4c5d-a1f3-453121af9c60"
// role: RUNNER_ROLE_USER
// ```
func (r *RunnerPolicyService) Update(ctx context.Context, body RunnerPolicyUpdateParams, opts ...option.RequestOption) (res *RunnerPolicyUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
path := "gitpod.v1.RunnerService/UpdateRunnerPolicy"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Lists policies for a runner.
//
// Use this method to:
//
// - View access controls
// - Check policy configurations
// - Audit permissions
//
// ### Examples
//
// - List policies:
//
// Shows all policies for a runner.
//
// ```yaml
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
// pagination:
// pageSize: 20
// ```
func (r *RunnerPolicyService) List(ctx context.Context, params RunnerPolicyListParams, opts ...option.RequestOption) (res *pagination.PoliciesPage[RunnerPolicy], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "gitpod.v1.RunnerService/ListRunnerPolicies"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodPost, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Lists policies for a runner.
//
// Use this method to:
//
// - View access controls
// - Check policy configurations
// - Audit permissions
//
// ### Examples
//
// - List policies:
//
// Shows all policies for a runner.
//
// ```yaml
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
// pagination:
// pageSize: 20
// ```
func (r *RunnerPolicyService) ListAutoPaging(ctx context.Context, params RunnerPolicyListParams, opts ...option.RequestOption) *pagination.PoliciesPageAutoPager[RunnerPolicy] {
return pagination.NewPoliciesPageAutoPager(r.List(ctx, params, opts...))
}
// Deletes a runner policy.
//
// Use this method to:
//
// - Remove access controls
// - Revoke permissions
// - Clean up policies
//
// ### Examples
//
// - Delete policy:
//
// Removes a group's access policy.
//
// ```yaml
// runnerId: "d2c94c27-3b76-4a42-b88c-95a85e392c68"
// groupId: "f53d2330-3795-4c5d-a1f3-453121af9c60"
// ```
func (r *RunnerPolicyService) Delete(ctx context.Context, body RunnerPolicyDeleteParams, opts ...option.RequestOption) (res *RunnerPolicyDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
path := "gitpod.v1.RunnerService/DeleteRunnerPolicy"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
type RunnerPolicy struct {
GroupID string `json:"groupId" format:"uuid"`
// role is the role assigned to the group
Role RunnerRole `json:"role"`
JSON runnerPolicyJSON `json:"-"`
}
// runnerPolicyJSON contains the JSON metadata for the struct [RunnerPolicy]
type runnerPolicyJSON struct {
GroupID apijson.Field
Role apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RunnerPolicy) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r runnerPolicyJSON) RawJSON() string {
return r.raw
}
type RunnerRole string
const (
RunnerRoleUnspecified RunnerRole = "RUNNER_ROLE_UNSPECIFIED"
RunnerRoleAdmin RunnerRole = "RUNNER_ROLE_ADMIN"
RunnerRoleUser RunnerRole = "RUNNER_ROLE_USER"
)
func (r RunnerRole) IsKnown() bool {
switch r {
case RunnerRoleUnspecified, RunnerRoleAdmin, RunnerRoleUser:
return true
}
return false
}
type RunnerPolicyNewResponse struct {
Policy RunnerPolicy `json:"policy,required"`
JSON runnerPolicyNewResponseJSON `json:"-"`
}
// runnerPolicyNewResponseJSON contains the JSON metadata for the struct
// [RunnerPolicyNewResponse]
type runnerPolicyNewResponseJSON struct {
Policy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RunnerPolicyNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r runnerPolicyNewResponseJSON) RawJSON() string {
return r.raw
}
type RunnerPolicyUpdateResponse struct {
Policy RunnerPolicy `json:"policy,required"`
JSON runnerPolicyUpdateResponseJSON `json:"-"`
}
// runnerPolicyUpdateResponseJSON contains the JSON metadata for the struct
// [RunnerPolicyUpdateResponse]
type runnerPolicyUpdateResponseJSON struct {
Policy apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RunnerPolicyUpdateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r runnerPolicyUpdateResponseJSON) RawJSON() string {
return r.raw
}
type RunnerPolicyDeleteResponse = interface{}
type RunnerPolicyNewParams struct {
// group_id specifies the group_id identifier
GroupID param.Field[string] `json:"groupId" format:"uuid"`
Role param.Field[RunnerRole] `json:"role"`
// runner_id specifies the project identifier
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`
}
func (r RunnerPolicyNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RunnerPolicyUpdateParams struct {
// group_id specifies the group_id identifier
GroupID param.Field[string] `json:"groupId" format:"uuid"`
Role param.Field[RunnerRole] `json:"role"`
// runner_id specifies the project identifier
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`
}
func (r RunnerPolicyUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RunnerPolicyListParams struct {
Token param.Field[string] `query:"token"`
PageSize param.Field[int64] `query:"pageSize"`
// pagination contains the pagination options for listing project policies
Pagination param.Field[RunnerPolicyListParamsPagination] `json:"pagination"`
// runner_id specifies the project identifier
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`
}
func (r RunnerPolicyListParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// URLQuery serializes [RunnerPolicyListParams]'s query parameters as `url.Values`.
func (r RunnerPolicyListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// pagination contains the pagination options for listing project policies
type RunnerPolicyListParamsPagination struct {
// Token for the next set of results that was returned as next_token of a
// PaginationResponse
Token param.Field[string] `json:"token"`
// Page size is the maximum number of results to retrieve per page. Defaults to 25.
// Maximum 100.
PageSize param.Field[int64] `json:"pageSize"`
}
func (r RunnerPolicyListParamsPagination) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RunnerPolicyDeleteParams struct {
// group_id specifies the group_id identifier
GroupID param.Field[string] `json:"groupId" format:"uuid"`
// runner_id specifies the project identifier
RunnerID param.Field[string] `json:"runnerId" format:"uuid"`
}
func (r RunnerPolicyDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}