-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvcfauthorizationfunction.go
191 lines (167 loc) · 8.02 KB
/
nvcfauthorizationfunction.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package nvidiacloudfunctions
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/brevdev/nvcf-go/internal/apijson"
"github.com/brevdev/nvcf-go/internal/param"
"github.com/brevdev/nvcf-go/internal/requestconfig"
"github.com/brevdev/nvcf-go/option"
"github.com/brevdev/nvcf-go/shared"
)
// NvcfAuthorizationFunctionService contains methods and other services that help
// with interacting with the nvidia-cloud-functions 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 [NewNvcfAuthorizationFunctionService] method instead.
type NvcfAuthorizationFunctionService struct {
Options []option.RequestOption
Versions *NvcfAuthorizationFunctionVersionService
}
// NewNvcfAuthorizationFunctionService 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 NewNvcfAuthorizationFunctionService(opts ...option.RequestOption) (r *NvcfAuthorizationFunctionService) {
r = &NvcfAuthorizationFunctionService{}
r.Options = opts
r.Versions = NewNvcfAuthorizationFunctionVersionService(opts...)
return
}
// Lists NVIDIA Cloud Account IDs that are authorized to invoke any version of the
// specified function. The response includes an array showing authorized accounts
// for each version. Individual versions of a function can have their own
// authorized accounts. So, each object in the array can have different authorized
// accounts listed. Access to this functionality mandates the inclusion of a bearer
// token with the 'authorize_clients' scope in the HTTP Authorization header
func (r *NvcfAuthorizationFunctionService) List(ctx context.Context, functionID string, opts ...option.RequestOption) (res *ListAuthorizedPartiesResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/authorizations/functions/%s", functionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Deletes all the extra NVIDIA Cloud Accounts that were authorized to invoke the
// function and all its versions. If a function version has its own set of
// authorized accounts, those are not deleted. If the specified function is public,
// then Account Admin cannot perform this operation. Access to this functionality
// mandates the inclusion of a bearer token with the 'authorize_clients' scope in
// the HTTP Authorization header
func (r *NvcfAuthorizationFunctionService) Delete(ctx context.Context, functionID string, opts ...option.RequestOption) (res *shared.AuthorizedPartiesResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/authorizations/functions/%s", functionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Authorizes additional NVIDIA Cloud Accounts to invoke any version of the
// specified function. By default, a function belongs to the NVIDIA Cloud Account
// that created it, and the credentials used for function invocation must reference
// the same NVIDIA Cloud Account. Upon invocation of this endpoint, any existing
// authorized accounts will be overwritten by the newly specified authorized
// accounts. Access to this functionality mandates the inclusion of a bearer token
// with the 'authorize_clients' scope in the HTTP Authorization header
func (r *NvcfAuthorizationFunctionService) Authorize(ctx context.Context, functionID string, body NvcfAuthorizationFunctionAuthorizeParams, opts ...option.RequestOption) (res *shared.AuthorizedPartiesResponse, err error) {
opts = append(r.Options[:], opts...)
if functionID == "" {
err = errors.New("missing required functionId parameter")
return
}
path := fmt.Sprintf("v2/nvcf/authorizations/functions/%s", functionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Parties authorized to invoke function
type ListAuthorizedPartiesResponse struct {
// Functions with authorized parties and other details
Functions []ListAuthorizedPartiesResponseFunction `json:"functions,required"`
JSON listAuthorizedPartiesResponseJSON `json:"-"`
}
// listAuthorizedPartiesResponseJSON contains the JSON metadata for the struct
// [ListAuthorizedPartiesResponse]
type listAuthorizedPartiesResponseJSON struct {
Functions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ListAuthorizedPartiesResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r listAuthorizedPartiesResponseJSON) RawJSON() string {
return r.raw
}
// Data Transfer Object(DTO) representing a function with authorized accounts
type ListAuthorizedPartiesResponseFunction struct {
// Function id
ID string `json:"id,required" format:"uuid"`
// NVIDIA Cloud Account Id
NcaID string `json:"ncaId,required"`
// Authorized parties allowed to invoke the function
AuthorizedParties []ListAuthorizedPartiesResponseFunctionsAuthorizedParty `json:"authorizedParties"`
// Function version id
VersionID string `json:"versionId" format:"uuid"`
JSON listAuthorizedPartiesResponseFunctionJSON `json:"-"`
}
// listAuthorizedPartiesResponseFunctionJSON contains the JSON metadata for the
// struct [ListAuthorizedPartiesResponseFunction]
type listAuthorizedPartiesResponseFunctionJSON struct {
ID apijson.Field
NcaID apijson.Field
AuthorizedParties apijson.Field
VersionID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ListAuthorizedPartiesResponseFunction) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r listAuthorizedPartiesResponseFunctionJSON) RawJSON() string {
return r.raw
}
// Data Transfer Object(DTO) representing an authorized party.
type ListAuthorizedPartiesResponseFunctionsAuthorizedParty struct {
// NVIDIA Cloud Account authorized to invoke the function
NcaID string `json:"ncaId,required"`
// Client Id -- 'sub' claim in the JWT. This field should not be specified anymore.
ClientID string `json:"clientId"`
JSON listAuthorizedPartiesResponseFunctionsAuthorizedPartyJSON `json:"-"`
}
// listAuthorizedPartiesResponseFunctionsAuthorizedPartyJSON contains the JSON
// metadata for the struct [ListAuthorizedPartiesResponseFunctionsAuthorizedParty]
type listAuthorizedPartiesResponseFunctionsAuthorizedPartyJSON struct {
NcaID apijson.Field
ClientID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ListAuthorizedPartiesResponseFunctionsAuthorizedParty) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r listAuthorizedPartiesResponseFunctionsAuthorizedPartyJSON) RawJSON() string {
return r.raw
}
type NvcfAuthorizationFunctionAuthorizeParams struct {
// Parties authorized to invoke function
AuthorizedParties param.Field[[]NvcfAuthorizationFunctionAuthorizeParamsAuthorizedParty] `json:"authorizedParties,required"`
}
func (r NvcfAuthorizationFunctionAuthorizeParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Data Transfer Object(DTO) representing an authorized party.
type NvcfAuthorizationFunctionAuthorizeParamsAuthorizedParty struct {
// NVIDIA Cloud Account authorized to invoke the function
NcaID param.Field[string] `json:"ncaId,required"`
// Client Id -- 'sub' claim in the JWT. This field should not be specified anymore.
ClientID param.Field[string] `json:"clientId"`
}
func (r NvcfAuthorizationFunctionAuthorizeParamsAuthorizedParty) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}