Repository navigation
Expand file tree
/
Copy pathadminorganizationprojectserviceaccountapikey.go
More file actions
105 lines (95 loc) · 4.47 KB
/
Copy pathadminorganizationprojectserviceaccountapikey.go
File metadata and controls
105 lines (95 loc) · 4.47 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
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"net/http"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/param"
"github.com/openai/openai-go/v3/packages/respjson"
"github.com/openai/openai-go/v3/shared/constant"
)
// AdminOrganizationProjectServiceAccountAPIKeyService 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 [NewAdminOrganizationProjectServiceAccountAPIKeyService] method instead.
type AdminOrganizationProjectServiceAccountAPIKeyService struct {
Options []option.RequestOption
}
// NewAdminOrganizationProjectServiceAccountAPIKeyService 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 NewAdminOrganizationProjectServiceAccountAPIKeyService(opts ...option.RequestOption) (r AdminOrganizationProjectServiceAccountAPIKeyService) {
r = AdminOrganizationProjectServiceAccountAPIKeyService{}
r.Options = requestconfig.InheritedOptions(opts...)
return
}
// Creates an API key for a service account in the project.
func (r *AdminOrganizationProjectServiceAccountAPIKeyService) New(ctx context.Context, projectID string, serviceAccountID string, body AdminOrganizationProjectServiceAccountAPIKeyNewParams, opts ...option.RequestOption) (res *AdminOrganizationProjectServiceAccountAPIKeyNewResponse, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
if serviceAccountID == "" {
err = errors.New("missing required service_account_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/service_accounts/%s/api_keys", projectID, serviceAccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
type AdminOrganizationProjectServiceAccountAPIKeyNewResponse struct {
// The identifier of the API key.
ID string `json:"id" api:"required"`
// The Unix timestamp (in seconds) when the API key was created.
CreatedAt int64 `json:"created_at" api:"required" format:"unixtime"`
// The name of the API key.
Name string `json:"name" api:"required"`
// The object type, which is always `organization.project.service_account.api_key`
Object constant.OrganizationProjectServiceAccountAPIKey `json:"object" default:"organization.project.service_account.api_key"`
// The unredacted API key value.
Value string `json:"value" api:"required"`
// The Unix timestamp (in seconds) when the API key expires, or null if it does not
// expire.
ExpiresAt int64 `json:"expires_at" api:"nullable" format:"unixtime"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Name respjson.Field
Object respjson.Field
Value respjson.Field
ExpiresAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AdminOrganizationProjectServiceAccountAPIKeyNewResponse) RawJSON() string { return r.JSON.raw }
func (r *AdminOrganizationProjectServiceAccountAPIKeyNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationProjectServiceAccountAPIKeyNewParams struct {
// Number of seconds until the API key expires.
ExpiresInSeconds param.Opt[int64] `json:"expires_in_seconds,omitzero"`
// API key name.
Name param.Opt[string] `json:"name,omitzero"`
// API key scopes.
Scopes []string `json:"scopes,omitzero"`
paramObj
}
func (r AdminOrganizationProjectServiceAccountAPIKeyNewParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectServiceAccountAPIKeyNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectServiceAccountAPIKeyNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}