-
Notifications
You must be signed in to change notification settings - Fork 762
Expand file tree
/
Copy pathloadocument.go
More file actions
283 lines (246 loc) · 9.78 KB
/
Copy pathloadocument.go
File metadata and controls
283 lines (246 loc) · 9.78 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package addressing
import (
"bytes"
"context"
"errors"
"fmt"
"mime/multipart"
"net/http"
"slices"
"time"
"github.com/cloudflare/cloudflare-go/v7/internal/apiform"
"github.com/cloudflare/cloudflare-go/v7/internal/apijson"
"github.com/cloudflare/cloudflare-go/v7/internal/param"
"github.com/cloudflare/cloudflare-go/v7/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v7/option"
)
// LOADocumentService contains methods and other services that help with
// interacting with the cloudflare 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 [NewLOADocumentService] method instead.
type LOADocumentService struct {
Options []option.RequestOption
}
// NewLOADocumentService 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 NewLOADocumentService(opts ...option.RequestOption) (r *LOADocumentService) {
r = &LOADocumentService{}
r.Options = opts
return
}
// Submit LOA document (pdf format) under the account.
//
// Deprecated: This is API is deprecated and will be removed in a future release.
func (r *LOADocumentService) New(ctx context.Context, params LOADocumentNewParams, opts ...option.RequestOption) (res *LOADocumentNewResponse, err error) {
var env LOADocumentNewResponseEnvelope
opts = slices.Concat(r.Options, opts)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return nil, err
}
path := fmt.Sprintf("accounts/%s/addressing/loa_documents", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return nil, err
}
res = &env.Result
return res, nil
}
// Download specified LOA document under the account.
func (r *LOADocumentService) Get(ctx context.Context, loaDocumentID string, query LOADocumentGetParams, opts ...option.RequestOption) (res *http.Response, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("Accept", "application/pdf")}, opts...)
if query.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return nil, err
}
if loaDocumentID == "" {
err = errors.New("missing required loa_document_id parameter")
return nil, err
}
path := fmt.Sprintf("accounts/%s/addressing/loa_documents/%s/download", query.AccountID, loaDocumentID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
type LOADocumentNewResponse struct {
// Identifier for the uploaded LOA document.
ID string `json:"id" api:"nullable"`
// Identifier of a Cloudflare account.
AccountID string `json:"account_id"`
// Whether the LOA has been auto-generated for the prefix owner by Cloudflare.
AutoGenerated bool `json:"auto_generated"`
Created time.Time `json:"created" format:"date-time"`
// Name of LOA document. Max file size 10MB, and supported filetype is pdf.
Filename string `json:"filename"`
// File size of the uploaded LOA document.
SizeBytes int64 `json:"size_bytes"`
// Whether the LOA has been verified by Cloudflare staff.
Verified bool `json:"verified"`
// Timestamp of the moment the LOA was marked as validated.
VerifiedAt time.Time `json:"verified_at" api:"nullable" format:"date-time"`
JSON loaDocumentNewResponseJSON `json:"-"`
}
// loaDocumentNewResponseJSON contains the JSON metadata for the struct
// [LOADocumentNewResponse]
type loaDocumentNewResponseJSON struct {
ID apijson.Field
AccountID apijson.Field
AutoGenerated apijson.Field
Created apijson.Field
Filename apijson.Field
SizeBytes apijson.Field
Verified apijson.Field
VerifiedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseJSON) RawJSON() string {
return r.raw
}
type LOADocumentNewParams struct {
// Identifier of a Cloudflare account.
AccountID param.Field[string] `path:"account_id" api:"required"`
// LOA document to upload.
LOADocument param.Field[string] `json:"loa_document" api:"required"`
}
func (r LOADocumentNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}
type LOADocumentNewResponseEnvelope struct {
Errors []LOADocumentNewResponseEnvelopeErrors `json:"errors" api:"required"`
Messages []LOADocumentNewResponseEnvelopeMessages `json:"messages" api:"required"`
// Whether the API call was successful.
Success LOADocumentNewResponseEnvelopeSuccess `json:"success" api:"required"`
Result LOADocumentNewResponse `json:"result"`
JSON loaDocumentNewResponseEnvelopeJSON `json:"-"`
}
// loaDocumentNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [LOADocumentNewResponseEnvelope]
type loaDocumentNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
type LOADocumentNewResponseEnvelopeErrors struct {
Code int64 `json:"code" api:"required"`
Message string `json:"message" api:"required"`
DocumentationURL string `json:"documentation_url"`
Source LOADocumentNewResponseEnvelopeErrorsSource `json:"source"`
JSON loaDocumentNewResponseEnvelopeErrorsJSON `json:"-"`
}
// loaDocumentNewResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [LOADocumentNewResponseEnvelopeErrors]
type loaDocumentNewResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
DocumentationURL apijson.Field
Source apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseEnvelopeErrorsJSON) RawJSON() string {
return r.raw
}
type LOADocumentNewResponseEnvelopeErrorsSource struct {
Pointer string `json:"pointer"`
JSON loaDocumentNewResponseEnvelopeErrorsSourceJSON `json:"-"`
}
// loaDocumentNewResponseEnvelopeErrorsSourceJSON contains the JSON metadata for
// the struct [LOADocumentNewResponseEnvelopeErrorsSource]
type loaDocumentNewResponseEnvelopeErrorsSourceJSON struct {
Pointer apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponseEnvelopeErrorsSource) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseEnvelopeErrorsSourceJSON) RawJSON() string {
return r.raw
}
type LOADocumentNewResponseEnvelopeMessages struct {
Code int64 `json:"code" api:"required"`
Message string `json:"message" api:"required"`
DocumentationURL string `json:"documentation_url"`
Source LOADocumentNewResponseEnvelopeMessagesSource `json:"source"`
JSON loaDocumentNewResponseEnvelopeMessagesJSON `json:"-"`
}
// loaDocumentNewResponseEnvelopeMessagesJSON contains the JSON metadata for the
// struct [LOADocumentNewResponseEnvelopeMessages]
type loaDocumentNewResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
DocumentationURL apijson.Field
Source apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseEnvelopeMessagesJSON) RawJSON() string {
return r.raw
}
type LOADocumentNewResponseEnvelopeMessagesSource struct {
Pointer string `json:"pointer"`
JSON loaDocumentNewResponseEnvelopeMessagesSourceJSON `json:"-"`
}
// loaDocumentNewResponseEnvelopeMessagesSourceJSON contains the JSON metadata for
// the struct [LOADocumentNewResponseEnvelopeMessagesSource]
type loaDocumentNewResponseEnvelopeMessagesSourceJSON struct {
Pointer apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LOADocumentNewResponseEnvelopeMessagesSource) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r loaDocumentNewResponseEnvelopeMessagesSourceJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful.
type LOADocumentNewResponseEnvelopeSuccess bool
const (
LOADocumentNewResponseEnvelopeSuccessTrue LOADocumentNewResponseEnvelopeSuccess = true
)
func (r LOADocumentNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case LOADocumentNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type LOADocumentGetParams struct {
// Identifier of a Cloudflare account.
AccountID param.Field[string] `path:"account_id" api:"required"`
}