-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasset.go
148 lines (127 loc) · 4.94 KB
/
asset.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package nvidiacloudfunctions
import (
"context"
"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"
)
// AssetService 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 [NewAssetService] method instead.
type AssetService struct {
Options []option.RequestOption
}
// NewAssetService 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 NewAssetService(opts ...option.RequestOption) (r *AssetService) {
r = &AssetService{}
r.Options = opts
return
}
// Creates a unique id representing an asset and a pre-signed URL to upload the
// asset artifact to AWS S3 bucket for the NVIDIA Cloud Account. Requires either a
// bearer token or an api-key with 'invoke_function' scope in the HTTP
// Authorization header.
func (r *AssetService) New(ctx context.Context, body AssetNewParams, opts ...option.RequestOption) (res *CreateAssetResponse, err error) {
opts = append(r.Options[:], opts...)
path := "v2/nvcf/assets"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// List assets owned by the current NVIDIA Cloud Account. Requires either a bearer
// token or an api-key with invoke_function scope in the HTTP Authorization header.
func (r *AssetService) List(ctx context.Context, opts ...option.RequestOption) (res *ListAssetsResponse, err error) {
opts = append(r.Options[:], opts...)
path := "v2/nvcf/assets"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Response body containing asset-id and the corresponding pre-signed URL to upload
// an asset of specified content-type to AWS S3 bucket.
type CreateAssetResponse struct {
// Unique id of the asset to be uploaded to AWS S3 bucket
AssetID string `json:"assetId" format:"uuid"`
// Content type of the asset such image/png, image/jpeg, etc.
ContentType string `json:"contentType"`
// Asset description to be used when uploading the asset
Description string `json:"description"`
// Pre-signed upload URL to upload asset
UploadURL string `json:"uploadUrl" format:"url"`
JSON createAssetResponseJSON `json:"-"`
}
// createAssetResponseJSON contains the JSON metadata for the struct
// [CreateAssetResponse]
type createAssetResponseJSON struct {
AssetID apijson.Field
ContentType apijson.Field
Description apijson.Field
UploadURL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *CreateAssetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r createAssetResponseJSON) RawJSON() string {
return r.raw
}
// Response body containing list of assets of the current nca id
type ListAssetsResponse struct {
// List of assets uploaded for the nca id
Assets []ListAssetsResponseAsset `json:"assets"`
JSON listAssetsResponseJSON `json:"-"`
}
// listAssetsResponseJSON contains the JSON metadata for the struct
// [ListAssetsResponse]
type listAssetsResponseJSON struct {
Assets apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ListAssetsResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r listAssetsResponseJSON) RawJSON() string {
return r.raw
}
// Data Transfer Object(DTO) representing an asset
type ListAssetsResponseAsset struct {
// Asset id
AssetID string `json:"assetId" format:"uuid"`
// Content-type specified when creating the asset
ContentType string `json:"contentType"`
// Description specified when creating the asset
Description string `json:"description"`
JSON listAssetsResponseAssetJSON `json:"-"`
}
// listAssetsResponseAssetJSON contains the JSON metadata for the struct
// [ListAssetsResponseAsset]
type listAssetsResponseAssetJSON struct {
AssetID apijson.Field
ContentType apijson.Field
Description apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ListAssetsResponseAsset) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r listAssetsResponseAssetJSON) RawJSON() string {
return r.raw
}
type AssetNewParams struct {
// Content type of the asset such image/png, image/jpeg, etc.
ContentType param.Field[string] `json:"contentType,required"`
// Asset description
Description param.Field[string] `json:"description,required"`
}
func (r AssetNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}