-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.go
executable file
·483 lines (428 loc) · 27.8 KB
/
role.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package braintrust
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"github.com/braintrustdata/braintrust-go/internal/apijson"
"github.com/braintrustdata/braintrust-go/internal/apiquery"
"github.com/braintrustdata/braintrust-go/internal/param"
"github.com/braintrustdata/braintrust-go/internal/requestconfig"
"github.com/braintrustdata/braintrust-go/option"
"github.com/braintrustdata/braintrust-go/packages/pagination"
"github.com/braintrustdata/braintrust-go/shared"
)
// RoleService contains methods and other services that help with interacting with
// the braintrust 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 [NewRoleService] method instead.
type RoleService struct {
Options []option.RequestOption
}
// NewRoleService 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 NewRoleService(opts ...option.RequestOption) (r *RoleService) {
r = &RoleService{}
r.Options = opts
return
}
// Create a new role. If there is an existing role with the same name as the one
// specified in the request, will return the existing role unmodified
func (r *RoleService) New(ctx context.Context, body RoleNewParams, opts ...option.RequestOption) (res *shared.Role, err error) {
opts = append(r.Options[:], opts...)
path := "v1/role"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get a role object by its id
func (r *RoleService) Get(ctx context.Context, roleID string, opts ...option.RequestOption) (res *shared.Role, err error) {
opts = append(r.Options[:], opts...)
if roleID == "" {
err = errors.New("missing required role_id parameter")
return
}
path := fmt.Sprintf("v1/role/%s", roleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Partially update a role object. Specify the fields to update in the payload. Any
// object-type fields will be deep-merged with existing content. Currently we do
// not support removing fields or setting them to null.
func (r *RoleService) Update(ctx context.Context, roleID string, body RoleUpdateParams, opts ...option.RequestOption) (res *shared.Role, err error) {
opts = append(r.Options[:], opts...)
if roleID == "" {
err = errors.New("missing required role_id parameter")
return
}
path := fmt.Sprintf("v1/role/%s", roleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, body, &res, opts...)
return
}
// List out all roles. The roles are sorted by creation date, with the most
// recently-created roles coming first
func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...option.RequestOption) (res *pagination.ListObjects[shared.Role], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/role"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List out all roles. The roles are sorted by creation date, with the most
// recently-created roles coming first
func (r *RoleService) ListAutoPaging(ctx context.Context, query RoleListParams, opts ...option.RequestOption) *pagination.ListObjectsAutoPager[shared.Role] {
return pagination.NewListObjectsAutoPager(r.List(ctx, query, opts...))
}
// Delete a role object by its id
func (r *RoleService) Delete(ctx context.Context, roleID string, opts ...option.RequestOption) (res *shared.Role, err error) {
opts = append(r.Options[:], opts...)
if roleID == "" {
err = errors.New("missing required role_id parameter")
return
}
path := fmt.Sprintf("v1/role/%s", roleID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Create or replace role. If there is an existing role with the same name as the
// one specified in the request, will replace the existing role with the provided
// fields
func (r *RoleService) Replace(ctx context.Context, body RoleReplaceParams, opts ...option.RequestOption) (res *shared.Role, err error) {
opts = append(r.Options[:], opts...)
path := "v1/role"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return
}
type RoleNewParams struct {
// Name of the role
Name param.Field[string] `json:"name,required"`
// Textual description of the role
Description param.Field[string] `json:"description"`
// (permission, restrict_object_type) tuples which belong to this role
MemberPermissions param.Field[[]RoleNewParamsMemberPermission] `json:"member_permissions"`
// Ids of the roles this role inherits from
//
// An inheriting role has all the permissions contained in its member roles, as
// well as all of their inherited permissions
MemberRoles param.Field[[]string] `json:"member_roles" format:"uuid"`
// For nearly all users, this parameter should be unnecessary. But in the rare case
// that your API key belongs to multiple organizations, you may specify the name of
// the organization the role belongs in.
OrgName param.Field[string] `json:"org_name"`
}
func (r RoleNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RoleNewParamsMemberPermission struct {
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
Permission param.Field[RoleNewParamsMemberPermissionsPermission] `json:"permission,required"`
// The object type that the ACL applies to
RestrictObjectType param.Field[RoleNewParamsMemberPermissionsRestrictObjectType] `json:"restrict_object_type"`
}
func (r RoleNewParamsMemberPermission) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
type RoleNewParamsMemberPermissionsPermission string
const (
RoleNewParamsMemberPermissionsPermissionCreate RoleNewParamsMemberPermissionsPermission = "create"
RoleNewParamsMemberPermissionsPermissionRead RoleNewParamsMemberPermissionsPermission = "read"
RoleNewParamsMemberPermissionsPermissionUpdate RoleNewParamsMemberPermissionsPermission = "update"
RoleNewParamsMemberPermissionsPermissionDelete RoleNewParamsMemberPermissionsPermission = "delete"
RoleNewParamsMemberPermissionsPermissionCreateACLs RoleNewParamsMemberPermissionsPermission = "create_acls"
RoleNewParamsMemberPermissionsPermissionReadACLs RoleNewParamsMemberPermissionsPermission = "read_acls"
RoleNewParamsMemberPermissionsPermissionUpdateACLs RoleNewParamsMemberPermissionsPermission = "update_acls"
RoleNewParamsMemberPermissionsPermissionDeleteACLs RoleNewParamsMemberPermissionsPermission = "delete_acls"
)
func (r RoleNewParamsMemberPermissionsPermission) IsKnown() bool {
switch r {
case RoleNewParamsMemberPermissionsPermissionCreate, RoleNewParamsMemberPermissionsPermissionRead, RoleNewParamsMemberPermissionsPermissionUpdate, RoleNewParamsMemberPermissionsPermissionDelete, RoleNewParamsMemberPermissionsPermissionCreateACLs, RoleNewParamsMemberPermissionsPermissionReadACLs, RoleNewParamsMemberPermissionsPermissionUpdateACLs, RoleNewParamsMemberPermissionsPermissionDeleteACLs:
return true
}
return false
}
// The object type that the ACL applies to
type RoleNewParamsMemberPermissionsRestrictObjectType string
const (
RoleNewParamsMemberPermissionsRestrictObjectTypeOrganization RoleNewParamsMemberPermissionsRestrictObjectType = "organization"
RoleNewParamsMemberPermissionsRestrictObjectTypeProject RoleNewParamsMemberPermissionsRestrictObjectType = "project"
RoleNewParamsMemberPermissionsRestrictObjectTypeExperiment RoleNewParamsMemberPermissionsRestrictObjectType = "experiment"
RoleNewParamsMemberPermissionsRestrictObjectTypeDataset RoleNewParamsMemberPermissionsRestrictObjectType = "dataset"
RoleNewParamsMemberPermissionsRestrictObjectTypePrompt RoleNewParamsMemberPermissionsRestrictObjectType = "prompt"
RoleNewParamsMemberPermissionsRestrictObjectTypePromptSession RoleNewParamsMemberPermissionsRestrictObjectType = "prompt_session"
RoleNewParamsMemberPermissionsRestrictObjectTypeGroup RoleNewParamsMemberPermissionsRestrictObjectType = "group"
RoleNewParamsMemberPermissionsRestrictObjectTypeRole RoleNewParamsMemberPermissionsRestrictObjectType = "role"
RoleNewParamsMemberPermissionsRestrictObjectTypeOrgMember RoleNewParamsMemberPermissionsRestrictObjectType = "org_member"
RoleNewParamsMemberPermissionsRestrictObjectTypeProjectLog RoleNewParamsMemberPermissionsRestrictObjectType = "project_log"
RoleNewParamsMemberPermissionsRestrictObjectTypeOrgProject RoleNewParamsMemberPermissionsRestrictObjectType = "org_project"
)
func (r RoleNewParamsMemberPermissionsRestrictObjectType) IsKnown() bool {
switch r {
case RoleNewParamsMemberPermissionsRestrictObjectTypeOrganization, RoleNewParamsMemberPermissionsRestrictObjectTypeProject, RoleNewParamsMemberPermissionsRestrictObjectTypeExperiment, RoleNewParamsMemberPermissionsRestrictObjectTypeDataset, RoleNewParamsMemberPermissionsRestrictObjectTypePrompt, RoleNewParamsMemberPermissionsRestrictObjectTypePromptSession, RoleNewParamsMemberPermissionsRestrictObjectTypeGroup, RoleNewParamsMemberPermissionsRestrictObjectTypeRole, RoleNewParamsMemberPermissionsRestrictObjectTypeOrgMember, RoleNewParamsMemberPermissionsRestrictObjectTypeProjectLog, RoleNewParamsMemberPermissionsRestrictObjectTypeOrgProject:
return true
}
return false
}
type RoleUpdateParams struct {
// A list of permissions to add to the role
AddMemberPermissions param.Field[[]RoleUpdateParamsAddMemberPermission] `json:"add_member_permissions"`
// A list of role IDs to add to the role's inheriting-from set
AddMemberRoles param.Field[[]string] `json:"add_member_roles" format:"uuid"`
// Textual description of the role
Description param.Field[string] `json:"description"`
// Name of the role
Name param.Field[string] `json:"name"`
// A list of permissions to remove from the role
RemoveMemberPermissions param.Field[[]RoleUpdateParamsRemoveMemberPermission] `json:"remove_member_permissions"`
// A list of role IDs to remove from the role's inheriting-from set
RemoveMemberRoles param.Field[[]string] `json:"remove_member_roles" format:"uuid"`
}
func (r RoleUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RoleUpdateParamsAddMemberPermission struct {
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
Permission param.Field[RoleUpdateParamsAddMemberPermissionsPermission] `json:"permission,required"`
// The object type that the ACL applies to
RestrictObjectType param.Field[RoleUpdateParamsAddMemberPermissionsRestrictObjectType] `json:"restrict_object_type"`
}
func (r RoleUpdateParamsAddMemberPermission) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
type RoleUpdateParamsAddMemberPermissionsPermission string
const (
RoleUpdateParamsAddMemberPermissionsPermissionCreate RoleUpdateParamsAddMemberPermissionsPermission = "create"
RoleUpdateParamsAddMemberPermissionsPermissionRead RoleUpdateParamsAddMemberPermissionsPermission = "read"
RoleUpdateParamsAddMemberPermissionsPermissionUpdate RoleUpdateParamsAddMemberPermissionsPermission = "update"
RoleUpdateParamsAddMemberPermissionsPermissionDelete RoleUpdateParamsAddMemberPermissionsPermission = "delete"
RoleUpdateParamsAddMemberPermissionsPermissionCreateACLs RoleUpdateParamsAddMemberPermissionsPermission = "create_acls"
RoleUpdateParamsAddMemberPermissionsPermissionReadACLs RoleUpdateParamsAddMemberPermissionsPermission = "read_acls"
RoleUpdateParamsAddMemberPermissionsPermissionUpdateACLs RoleUpdateParamsAddMemberPermissionsPermission = "update_acls"
RoleUpdateParamsAddMemberPermissionsPermissionDeleteACLs RoleUpdateParamsAddMemberPermissionsPermission = "delete_acls"
)
func (r RoleUpdateParamsAddMemberPermissionsPermission) IsKnown() bool {
switch r {
case RoleUpdateParamsAddMemberPermissionsPermissionCreate, RoleUpdateParamsAddMemberPermissionsPermissionRead, RoleUpdateParamsAddMemberPermissionsPermissionUpdate, RoleUpdateParamsAddMemberPermissionsPermissionDelete, RoleUpdateParamsAddMemberPermissionsPermissionCreateACLs, RoleUpdateParamsAddMemberPermissionsPermissionReadACLs, RoleUpdateParamsAddMemberPermissionsPermissionUpdateACLs, RoleUpdateParamsAddMemberPermissionsPermissionDeleteACLs:
return true
}
return false
}
// The object type that the ACL applies to
type RoleUpdateParamsAddMemberPermissionsRestrictObjectType string
const (
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrganization RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "organization"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeProject RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "project"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeExperiment RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "experiment"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeDataset RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "dataset"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypePrompt RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "prompt"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypePromptSession RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "prompt_session"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeGroup RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "group"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeRole RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "role"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrgMember RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "org_member"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeProjectLog RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "project_log"
RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrgProject RoleUpdateParamsAddMemberPermissionsRestrictObjectType = "org_project"
)
func (r RoleUpdateParamsAddMemberPermissionsRestrictObjectType) IsKnown() bool {
switch r {
case RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrganization, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeProject, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeExperiment, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeDataset, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypePrompt, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypePromptSession, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeGroup, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeRole, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrgMember, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeProjectLog, RoleUpdateParamsAddMemberPermissionsRestrictObjectTypeOrgProject:
return true
}
return false
}
type RoleUpdateParamsRemoveMemberPermission struct {
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
Permission param.Field[RoleUpdateParamsRemoveMemberPermissionsPermission] `json:"permission,required"`
// The object type that the ACL applies to
RestrictObjectType param.Field[RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType] `json:"restrict_object_type"`
}
func (r RoleUpdateParamsRemoveMemberPermission) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
type RoleUpdateParamsRemoveMemberPermissionsPermission string
const (
RoleUpdateParamsRemoveMemberPermissionsPermissionCreate RoleUpdateParamsRemoveMemberPermissionsPermission = "create"
RoleUpdateParamsRemoveMemberPermissionsPermissionRead RoleUpdateParamsRemoveMemberPermissionsPermission = "read"
RoleUpdateParamsRemoveMemberPermissionsPermissionUpdate RoleUpdateParamsRemoveMemberPermissionsPermission = "update"
RoleUpdateParamsRemoveMemberPermissionsPermissionDelete RoleUpdateParamsRemoveMemberPermissionsPermission = "delete"
RoleUpdateParamsRemoveMemberPermissionsPermissionCreateACLs RoleUpdateParamsRemoveMemberPermissionsPermission = "create_acls"
RoleUpdateParamsRemoveMemberPermissionsPermissionReadACLs RoleUpdateParamsRemoveMemberPermissionsPermission = "read_acls"
RoleUpdateParamsRemoveMemberPermissionsPermissionUpdateACLs RoleUpdateParamsRemoveMemberPermissionsPermission = "update_acls"
RoleUpdateParamsRemoveMemberPermissionsPermissionDeleteACLs RoleUpdateParamsRemoveMemberPermissionsPermission = "delete_acls"
)
func (r RoleUpdateParamsRemoveMemberPermissionsPermission) IsKnown() bool {
switch r {
case RoleUpdateParamsRemoveMemberPermissionsPermissionCreate, RoleUpdateParamsRemoveMemberPermissionsPermissionRead, RoleUpdateParamsRemoveMemberPermissionsPermissionUpdate, RoleUpdateParamsRemoveMemberPermissionsPermissionDelete, RoleUpdateParamsRemoveMemberPermissionsPermissionCreateACLs, RoleUpdateParamsRemoveMemberPermissionsPermissionReadACLs, RoleUpdateParamsRemoveMemberPermissionsPermissionUpdateACLs, RoleUpdateParamsRemoveMemberPermissionsPermissionDeleteACLs:
return true
}
return false
}
// The object type that the ACL applies to
type RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType string
const (
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrganization RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "organization"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeProject RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "project"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeExperiment RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "experiment"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeDataset RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "dataset"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypePrompt RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "prompt"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypePromptSession RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "prompt_session"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeGroup RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "group"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeRole RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "role"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrgMember RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "org_member"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeProjectLog RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "project_log"
RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrgProject RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType = "org_project"
)
func (r RoleUpdateParamsRemoveMemberPermissionsRestrictObjectType) IsKnown() bool {
switch r {
case RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrganization, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeProject, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeExperiment, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeDataset, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypePrompt, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypePromptSession, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeGroup, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeRole, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrgMember, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeProjectLog, RoleUpdateParamsRemoveMemberPermissionsRestrictObjectTypeOrgProject:
return true
}
return false
}
type RoleListParams struct {
// Pagination cursor id.
//
// For example, if the initial item in the last page you fetched had an id of
// `foo`, pass `ending_before=foo` to fetch the previous page. Note: you may only
// pass one of `starting_after` and `ending_before`
EndingBefore param.Field[string] `query:"ending_before" format:"uuid"`
// Filter search results to a particular set of object IDs. To specify a list of
// IDs, include the query param multiple times
IDs param.Field[RoleListParamsIDsUnion] `query:"ids" format:"uuid"`
// Limit the number of objects to return
Limit param.Field[int64] `query:"limit"`
// Filter search results to within a particular organization
OrgName param.Field[string] `query:"org_name"`
// Name of the role to search for
RoleName param.Field[string] `query:"role_name"`
// Pagination cursor id.
//
// For example, if the final item in the last page you fetched had an id of `foo`,
// pass `starting_after=foo` to fetch the next page. Note: you may only pass one of
// `starting_after` and `ending_before`
StartingAfter param.Field[string] `query:"starting_after" format:"uuid"`
}
// URLQuery serializes [RoleListParams]'s query parameters as `url.Values`.
func (r RoleListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Filter search results to a particular set of object IDs. To specify a list of
// IDs, include the query param multiple times
//
// Satisfied by [shared.UnionString], [RoleListParamsIDsArray].
type RoleListParamsIDsUnion interface {
ImplementsRoleListParamsIDsUnion()
}
type RoleListParamsIDsArray []string
func (r RoleListParamsIDsArray) ImplementsRoleListParamsIDsUnion() {}
type RoleReplaceParams struct {
// Name of the role
Name param.Field[string] `json:"name,required"`
// Textual description of the role
Description param.Field[string] `json:"description"`
// (permission, restrict_object_type) tuples which belong to this role
MemberPermissions param.Field[[]RoleReplaceParamsMemberPermission] `json:"member_permissions"`
// Ids of the roles this role inherits from
//
// An inheriting role has all the permissions contained in its member roles, as
// well as all of their inherited permissions
MemberRoles param.Field[[]string] `json:"member_roles" format:"uuid"`
// For nearly all users, this parameter should be unnecessary. But in the rare case
// that your API key belongs to multiple organizations, you may specify the name of
// the organization the role belongs in.
OrgName param.Field[string] `json:"org_name"`
}
func (r RoleReplaceParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type RoleReplaceParamsMemberPermission struct {
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
Permission param.Field[RoleReplaceParamsMemberPermissionsPermission] `json:"permission,required"`
// The object type that the ACL applies to
RestrictObjectType param.Field[RoleReplaceParamsMemberPermissionsRestrictObjectType] `json:"restrict_object_type"`
}
func (r RoleReplaceParamsMemberPermission) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Each permission permits a certain type of operation on an object in the system
//
// Permissions can be assigned to to objects on an individual basis, or grouped
// into roles
type RoleReplaceParamsMemberPermissionsPermission string
const (
RoleReplaceParamsMemberPermissionsPermissionCreate RoleReplaceParamsMemberPermissionsPermission = "create"
RoleReplaceParamsMemberPermissionsPermissionRead RoleReplaceParamsMemberPermissionsPermission = "read"
RoleReplaceParamsMemberPermissionsPermissionUpdate RoleReplaceParamsMemberPermissionsPermission = "update"
RoleReplaceParamsMemberPermissionsPermissionDelete RoleReplaceParamsMemberPermissionsPermission = "delete"
RoleReplaceParamsMemberPermissionsPermissionCreateACLs RoleReplaceParamsMemberPermissionsPermission = "create_acls"
RoleReplaceParamsMemberPermissionsPermissionReadACLs RoleReplaceParamsMemberPermissionsPermission = "read_acls"
RoleReplaceParamsMemberPermissionsPermissionUpdateACLs RoleReplaceParamsMemberPermissionsPermission = "update_acls"
RoleReplaceParamsMemberPermissionsPermissionDeleteACLs RoleReplaceParamsMemberPermissionsPermission = "delete_acls"
)
func (r RoleReplaceParamsMemberPermissionsPermission) IsKnown() bool {
switch r {
case RoleReplaceParamsMemberPermissionsPermissionCreate, RoleReplaceParamsMemberPermissionsPermissionRead, RoleReplaceParamsMemberPermissionsPermissionUpdate, RoleReplaceParamsMemberPermissionsPermissionDelete, RoleReplaceParamsMemberPermissionsPermissionCreateACLs, RoleReplaceParamsMemberPermissionsPermissionReadACLs, RoleReplaceParamsMemberPermissionsPermissionUpdateACLs, RoleReplaceParamsMemberPermissionsPermissionDeleteACLs:
return true
}
return false
}
// The object type that the ACL applies to
type RoleReplaceParamsMemberPermissionsRestrictObjectType string
const (
RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrganization RoleReplaceParamsMemberPermissionsRestrictObjectType = "organization"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeProject RoleReplaceParamsMemberPermissionsRestrictObjectType = "project"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeExperiment RoleReplaceParamsMemberPermissionsRestrictObjectType = "experiment"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeDataset RoleReplaceParamsMemberPermissionsRestrictObjectType = "dataset"
RoleReplaceParamsMemberPermissionsRestrictObjectTypePrompt RoleReplaceParamsMemberPermissionsRestrictObjectType = "prompt"
RoleReplaceParamsMemberPermissionsRestrictObjectTypePromptSession RoleReplaceParamsMemberPermissionsRestrictObjectType = "prompt_session"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeGroup RoleReplaceParamsMemberPermissionsRestrictObjectType = "group"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeRole RoleReplaceParamsMemberPermissionsRestrictObjectType = "role"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrgMember RoleReplaceParamsMemberPermissionsRestrictObjectType = "org_member"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeProjectLog RoleReplaceParamsMemberPermissionsRestrictObjectType = "project_log"
RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrgProject RoleReplaceParamsMemberPermissionsRestrictObjectType = "org_project"
)
func (r RoleReplaceParamsMemberPermissionsRestrictObjectType) IsKnown() bool {
switch r {
case RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrganization, RoleReplaceParamsMemberPermissionsRestrictObjectTypeProject, RoleReplaceParamsMemberPermissionsRestrictObjectTypeExperiment, RoleReplaceParamsMemberPermissionsRestrictObjectTypeDataset, RoleReplaceParamsMemberPermissionsRestrictObjectTypePrompt, RoleReplaceParamsMemberPermissionsRestrictObjectTypePromptSession, RoleReplaceParamsMemberPermissionsRestrictObjectTypeGroup, RoleReplaceParamsMemberPermissionsRestrictObjectTypeRole, RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrgMember, RoleReplaceParamsMemberPermissionsRestrictObjectTypeProjectLog, RoleReplaceParamsMemberPermissionsRestrictObjectTypeOrgProject:
return true
}
return false
}