Repository navigation
Expand file tree
/
Copy pathadminorganizationuser.go
More file actions
300 lines (276 loc) · 12.3 KB
/
Copy pathadminorganizationuser.go
File metadata and controls
300 lines (276 loc) · 12.3 KB
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
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"net/http"
"net/url"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/apiquery"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/pagination"
"github.com/openai/openai-go/v3/packages/param"
"github.com/openai/openai-go/v3/packages/respjson"
"github.com/openai/openai-go/v3/shared/constant"
)
// AdminOrganizationUserService contains methods and other services that help with
// interacting with the openai 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 [NewAdminOrganizationUserService] method instead.
type AdminOrganizationUserService struct {
Options []option.RequestOption
Roles AdminOrganizationUserRoleService
}
// NewAdminOrganizationUserService 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 NewAdminOrganizationUserService(opts ...option.RequestOption) (r AdminOrganizationUserService) {
r = AdminOrganizationUserService{}
r.Options = requestconfig.InheritedOptions(opts...)
r.Roles = NewAdminOrganizationUserRoleService(opts...)
return
}
// Retrieves a user by their identifier.
func (r *AdminOrganizationUserService) Get(ctx context.Context, userID string, opts ...option.RequestOption) (res *OrganizationUser, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if userID == "" {
err = errors.New("missing required user_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/users/%s", userID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Modifies a user's role in the organization.
func (r *AdminOrganizationUserService) Update(ctx context.Context, userID string, body AdminOrganizationUserUpdateParams, opts ...option.RequestOption) (res *OrganizationUser, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if userID == "" {
err = errors.New("missing required user_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/users/%s", userID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Lists all of the users in the organization.
func (r *AdminOrganizationUserService) List(ctx context.Context, query AdminOrganizationUserListParams, opts ...option.RequestOption) (res *pagination.ConversationCursorPage[OrganizationUser], err error) {
var raw *http.Response
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "organization/users"
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
}
// Lists all of the users in the organization.
func (r *AdminOrganizationUserService) ListAutoPaging(ctx context.Context, query AdminOrganizationUserListParams, opts ...option.RequestOption) *pagination.ConversationCursorPageAutoPager[OrganizationUser] {
return pagination.NewConversationCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Deletes a user from the organization.
func (r *AdminOrganizationUserService) Delete(ctx context.Context, userID string, opts ...option.RequestOption) (res *AdminOrganizationUserDeleteResponse, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if userID == "" {
err = errors.New("missing required user_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/users/%s", userID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Represents an individual `user` within an organization.
type OrganizationUser struct {
// The identifier, which can be referenced in API endpoints
ID string `json:"id" api:"required"`
// The Unix timestamp (in seconds) of when the user was added.
AddedAt int64 `json:"added_at" api:"required" format:"unixtime"`
// The object type, which is always `organization.user`
Object constant.OrganizationUser `json:"object" default:"organization.user"`
// The Unix timestamp (in seconds) of the user's last API key usage.
APIKeyLastUsedAt int64 `json:"api_key_last_used_at" api:"nullable" format:"unixtime"`
// The Unix timestamp (in seconds) of when the user was created.
Created int64 `json:"created" format:"unixtime"`
// The developer persona metadata for the user.
DeveloperPersona string `json:"developer_persona" api:"nullable"`
// The email address of the user
Email string `json:"email" api:"nullable"`
// Whether this is the organization's default user.
IsDefault bool `json:"is_default"`
// Whether the user is an authorized purchaser for Scale Tier.
IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser" api:"nullable"`
// Whether the user is managed through SCIM.
IsScimManaged bool `json:"is_scim_managed"`
// Whether the user is a service account.
IsServiceAccount bool `json:"is_service_account"`
// The name of the user
Name string `json:"name" api:"nullable"`
// Projects associated with the user, if included.
Projects OrganizationUserProjects `json:"projects" api:"nullable"`
// `owner` or `reader`
Role string `json:"role" api:"nullable"`
// The technical level metadata for the user.
TechnicalLevel string `json:"technical_level" api:"nullable"`
// Nested user details.
User OrganizationUserUser `json:"user"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
AddedAt respjson.Field
Object respjson.Field
APIKeyLastUsedAt respjson.Field
Created respjson.Field
DeveloperPersona respjson.Field
Email respjson.Field
IsDefault respjson.Field
IsScaleTierAuthorizedPurchaser respjson.Field
IsScimManaged respjson.Field
IsServiceAccount respjson.Field
Name respjson.Field
Projects respjson.Field
Role respjson.Field
TechnicalLevel respjson.Field
User respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r OrganizationUser) RawJSON() string { return r.JSON.raw }
func (r *OrganizationUser) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Projects associated with the user, if included.
type OrganizationUserProjects struct {
Data []OrganizationUserProjectsData `json:"data" api:"required"`
Object constant.List `json:"object" default:"list"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Object respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r OrganizationUserProjects) RawJSON() string { return r.JSON.raw }
func (r *OrganizationUserProjects) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type OrganizationUserProjectsData struct {
ID string `json:"id" api:"nullable"`
Name string `json:"name" api:"nullable"`
Role string `json:"role" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Name respjson.Field
Role respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r OrganizationUserProjectsData) RawJSON() string { return r.JSON.raw }
func (r *OrganizationUserProjectsData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Nested user details.
type OrganizationUserUser struct {
ID string `json:"id" api:"required"`
Object constant.User `json:"object" default:"user"`
Banned bool `json:"banned" api:"nullable"`
BannedAt int64 `json:"banned_at" api:"nullable" format:"unixtime"`
Email string `json:"email" api:"nullable"`
Enabled bool `json:"enabled" api:"nullable"`
Name string `json:"name" api:"nullable"`
Picture string `json:"picture" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Object respjson.Field
Banned respjson.Field
BannedAt respjson.Field
Email respjson.Field
Enabled respjson.Field
Name respjson.Field
Picture respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r OrganizationUserUser) RawJSON() string { return r.JSON.raw }
func (r *OrganizationUserUser) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationUserDeleteResponse struct {
ID string `json:"id" api:"required"`
Deleted bool `json:"deleted" api:"required"`
Object constant.OrganizationUserDeleted `json:"object" default:"organization.user.deleted"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Deleted respjson.Field
Object respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AdminOrganizationUserDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *AdminOrganizationUserDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationUserUpdateParams struct {
// Developer persona metadata.
DeveloperPersona param.Opt[string] `json:"developer_persona,omitzero"`
// `owner` or `reader`
Role param.Opt[string] `json:"role,omitzero"`
// Role ID to assign to the user.
RoleID param.Opt[string] `json:"role_id,omitzero"`
// Technical level metadata.
TechnicalLevel param.Opt[string] `json:"technical_level,omitzero"`
paramObj
}
func (r AdminOrganizationUserUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationUserUpdateParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationUserUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationUserListParams struct {
// A cursor for use in pagination. `after` is an object ID that defines your place
// in the list. For instance, if you make a list request and receive 100 objects,
// ending with obj_foo, your subsequent call can include after=obj_foo in order to
// fetch the next page of the list.
After param.Opt[string] `query:"after,omitzero" json:"-"`
// A limit on the number of objects to be returned. Limit can range between 1 and
// 100, and the default is 20.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Filter by the email address of users.
Emails []string `query:"emails,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [AdminOrganizationUserListParams]'s query parameters as
// `url.Values`.
func (r AdminOrganizationUserListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}