/
openapi_import_source.go
646 lines (516 loc) · 18.7 KB
/
openapi_import_source.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"encoding/json"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// OpenapiImportSource ImportSource
//
// ImportSource represents the data source settings of an import task.
//
// swagger:model openapiImportSource
type OpenapiImportSource struct {
// aws assume role access
AwsAssumeRoleAccess *OpenapiImportSourceAwsAssumeRoleAccess `json:"aws_assume_role_access,omitempty"`
// aws key access
AwsKeyAccess *OpenapiImportSourceAwsKeyAccess `json:"aws_key_access,omitempty"`
// format
// Required: true
Format *OpenapiImportSourceFormat `json:"format"`
// The data source type of an import task.
//
// - `"S3"`: import data from Amazon S3
// - `"GCS"`: import data from Google Cloud Storage
// - `"LOCAL_FILE"`: import data from a local file (only available for [TiDB Serverless](https://docs.pingcap.com/tidbcloud/select-cluster-tier#tidb-serverless) clusters). Before you import from a local file, you need to first upload the file using the [Upload a local file for an import task](#tag/Import/operation/UploadLocalFile) endpoint.
//
// **Note:** Currently, if this import spec is used for a [preview](#tag/Import/operation/PreviewImportData) request, only the `LOCAL_FILE` source type is supported.
// Example: S3
// Required: true
// Enum: [S3 GCS LOCAL_FILE]
Type *string `json:"type"`
// The data source URI of an import task. The URI scheme must match the data source type. Here are the scheme of each source type:
// * `S3`: `s3://`
// * `GCS`: `gs://`
// * `LOCAL_FILE`: `file://`.
//
// **Note:** If the import source type is `LOCAL_FILE`, just provide the `upload_stub_id` of the uploaded file from the response of [Upload a local file for an import task](#tag/Import/operation/UploadLocalFile), and make it as the data source folder. For example: `file://12345/`.
//
// **Limitation**: If the import source type is `LOCAL_FILE`, only the `CSV` source format type is supported.
// Example: s3://example-bucket/example-source-data/
// Required: true
URI *string `json:"uri"`
}
// Validate validates this openapi import source
func (m *OpenapiImportSource) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAwsAssumeRoleAccess(formats); err != nil {
res = append(res, err)
}
if err := m.validateAwsKeyAccess(formats); err != nil {
res = append(res, err)
}
if err := m.validateFormat(formats); err != nil {
res = append(res, err)
}
if err := m.validateType(formats); err != nil {
res = append(res, err)
}
if err := m.validateURI(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSource) validateAwsAssumeRoleAccess(formats strfmt.Registry) error {
if swag.IsZero(m.AwsAssumeRoleAccess) { // not required
return nil
}
if m.AwsAssumeRoleAccess != nil {
if err := m.AwsAssumeRoleAccess.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("aws_assume_role_access")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("aws_assume_role_access")
}
return err
}
}
return nil
}
func (m *OpenapiImportSource) validateAwsKeyAccess(formats strfmt.Registry) error {
if swag.IsZero(m.AwsKeyAccess) { // not required
return nil
}
if m.AwsKeyAccess != nil {
if err := m.AwsKeyAccess.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("aws_key_access")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("aws_key_access")
}
return err
}
}
return nil
}
func (m *OpenapiImportSource) validateFormat(formats strfmt.Registry) error {
if err := validate.Required("format", "body", m.Format); err != nil {
return err
}
if m.Format != nil {
if err := m.Format.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("format")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("format")
}
return err
}
}
return nil
}
var openapiImportSourceTypeTypePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["S3","GCS","LOCAL_FILE"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
openapiImportSourceTypeTypePropEnum = append(openapiImportSourceTypeTypePropEnum, v)
}
}
const (
// OpenapiImportSourceTypeS3 captures enum value "S3"
OpenapiImportSourceTypeS3 string = "S3"
// OpenapiImportSourceTypeGCS captures enum value "GCS"
OpenapiImportSourceTypeGCS string = "GCS"
// OpenapiImportSourceTypeLOCALFILE captures enum value "LOCAL_FILE"
OpenapiImportSourceTypeLOCALFILE string = "LOCAL_FILE"
)
// prop value enum
func (m *OpenapiImportSource) validateTypeEnum(path, location string, value string) error {
if err := validate.EnumCase(path, location, value, openapiImportSourceTypeTypePropEnum, true); err != nil {
return err
}
return nil
}
func (m *OpenapiImportSource) validateType(formats strfmt.Registry) error {
if err := validate.Required("type", "body", m.Type); err != nil {
return err
}
// value enum
if err := m.validateTypeEnum("type", "body", *m.Type); err != nil {
return err
}
return nil
}
func (m *OpenapiImportSource) validateURI(formats strfmt.Registry) error {
if err := validate.Required("uri", "body", m.URI); err != nil {
return err
}
return nil
}
// ContextValidate validate this openapi import source based on the context it is used
func (m *OpenapiImportSource) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateAwsAssumeRoleAccess(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateAwsKeyAccess(ctx, formats); err != nil {
res = append(res, err)
}
if err := m.contextValidateFormat(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSource) contextValidateAwsAssumeRoleAccess(ctx context.Context, formats strfmt.Registry) error {
if m.AwsAssumeRoleAccess != nil {
if swag.IsZero(m.AwsAssumeRoleAccess) { // not required
return nil
}
if err := m.AwsAssumeRoleAccess.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("aws_assume_role_access")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("aws_assume_role_access")
}
return err
}
}
return nil
}
func (m *OpenapiImportSource) contextValidateAwsKeyAccess(ctx context.Context, formats strfmt.Registry) error {
if m.AwsKeyAccess != nil {
if swag.IsZero(m.AwsKeyAccess) { // not required
return nil
}
if err := m.AwsKeyAccess.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("aws_key_access")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("aws_key_access")
}
return err
}
}
return nil
}
func (m *OpenapiImportSource) contextValidateFormat(ctx context.Context, formats strfmt.Registry) error {
if m.Format != nil {
if err := m.Format.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("format")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("format")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *OpenapiImportSource) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OpenapiImportSource) UnmarshalBinary(b []byte) error {
var res OpenapiImportSource
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// OpenapiImportSourceAwsAssumeRoleAccess AwsAssumeRoleAccess
//
// The settings to access the S3 data by assuming a specific AWS role. This field is only needed if you need to access S3 data by assuming an AWS role.
//
// **Note:** Provide only one of `aws_assume_role_access` and `aws_key_access`. If both `aws_assume_role_access` and `aws_key_access` are provided, an error will be reported.
//
// swagger:model OpenapiImportSourceAwsAssumeRoleAccess
type OpenapiImportSourceAwsAssumeRoleAccess struct {
// The specific AWS role ARN that needs to be assumed to access the Amazon S3 data source.
// Example: arn:aws:iam::999999999999:role/sample-role
// Required: true
AssumeRole *string `json:"assume_role"`
}
// Validate validates this openapi import source aws assume role access
func (m *OpenapiImportSourceAwsAssumeRoleAccess) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAssumeRole(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSourceAwsAssumeRoleAccess) validateAssumeRole(formats strfmt.Registry) error {
if err := validate.Required("aws_assume_role_access"+"."+"assume_role", "body", m.AssumeRole); err != nil {
return err
}
return nil
}
// ContextValidate validates this openapi import source aws assume role access based on context it is used
func (m *OpenapiImportSourceAwsAssumeRoleAccess) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *OpenapiImportSourceAwsAssumeRoleAccess) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OpenapiImportSourceAwsAssumeRoleAccess) UnmarshalBinary(b []byte) error {
var res OpenapiImportSourceAwsAssumeRoleAccess
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// OpenapiImportSourceAwsKeyAccess AwsKeyAccess
//
// The settings to access the S3 data with an access key. This field is only needed if you want to access the S3 data with an access key.
//
// **Note:** Provide only one of `aws_assume_role_access` and `aws_key_access`. If both `aws_assume_role_access` and `aws_key_access` are provided, an error will be reported.
//
// swagger:model OpenapiImportSourceAwsKeyAccess
type OpenapiImportSourceAwsKeyAccess struct {
// The access key ID of the account to access the data. This information will be redacted when it is retrieved to obtain the import task information.
// Example: YOUR_ACCESS_KEY_ID
// Required: true
AccessKeyID *string `json:"access_key_id"`
// The secret access key for the account to access the data. This information will be redacted when it is retrieved to obtain the import task information.
// Example: YOUR_SECRET_ACCESS_KEY
// Required: true
SecretAccessKey *string `json:"secret_access_key"`
}
// Validate validates this openapi import source aws key access
func (m *OpenapiImportSourceAwsKeyAccess) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateAccessKeyID(formats); err != nil {
res = append(res, err)
}
if err := m.validateSecretAccessKey(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSourceAwsKeyAccess) validateAccessKeyID(formats strfmt.Registry) error {
if err := validate.Required("aws_key_access"+"."+"access_key_id", "body", m.AccessKeyID); err != nil {
return err
}
return nil
}
func (m *OpenapiImportSourceAwsKeyAccess) validateSecretAccessKey(formats strfmt.Registry) error {
if err := validate.Required("aws_key_access"+"."+"secret_access_key", "body", m.SecretAccessKey); err != nil {
return err
}
return nil
}
// ContextValidate validates this openapi import source aws key access based on context it is used
func (m *OpenapiImportSourceAwsKeyAccess) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *OpenapiImportSourceAwsKeyAccess) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OpenapiImportSourceAwsKeyAccess) UnmarshalBinary(b []byte) error {
var res OpenapiImportSourceAwsKeyAccess
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// OpenapiImportSourceFormat ImportSourceFormat
//
// The format settings of the import data source.
//
// swagger:model OpenapiImportSourceFormat
type OpenapiImportSourceFormat struct {
// csv config
CsvConfig *OpenapiImportSourceFormatCsvConfig `json:"csv_config,omitempty"`
// The format type of an import source.
// Example: CSV
// Required: true
// Enum: [CSV PARQUET SQL AURORA_SNAPSHOT]
Type *string `json:"type"`
}
// Validate validates this openapi import source format
func (m *OpenapiImportSourceFormat) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCsvConfig(formats); err != nil {
res = append(res, err)
}
if err := m.validateType(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSourceFormat) validateCsvConfig(formats strfmt.Registry) error {
if swag.IsZero(m.CsvConfig) { // not required
return nil
}
if m.CsvConfig != nil {
if err := m.CsvConfig.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("format" + "." + "csv_config")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("format" + "." + "csv_config")
}
return err
}
}
return nil
}
var openapiImportSourceFormatTypeTypePropEnum []interface{}
func init() {
var res []string
if err := json.Unmarshal([]byte(`["CSV","PARQUET","SQL","AURORA_SNAPSHOT"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
openapiImportSourceFormatTypeTypePropEnum = append(openapiImportSourceFormatTypeTypePropEnum, v)
}
}
const (
// OpenapiImportSourceFormatTypeCSV captures enum value "CSV"
OpenapiImportSourceFormatTypeCSV string = "CSV"
// OpenapiImportSourceFormatTypePARQUET captures enum value "PARQUET"
OpenapiImportSourceFormatTypePARQUET string = "PARQUET"
// OpenapiImportSourceFormatTypeSQL captures enum value "SQL"
OpenapiImportSourceFormatTypeSQL string = "SQL"
// OpenapiImportSourceFormatTypeAURORASNAPSHOT captures enum value "AURORA_SNAPSHOT"
OpenapiImportSourceFormatTypeAURORASNAPSHOT string = "AURORA_SNAPSHOT"
)
// prop value enum
func (m *OpenapiImportSourceFormat) validateTypeEnum(path, location string, value string) error {
if err := validate.EnumCase(path, location, value, openapiImportSourceFormatTypeTypePropEnum, true); err != nil {
return err
}
return nil
}
func (m *OpenapiImportSourceFormat) validateType(formats strfmt.Registry) error {
if err := validate.Required("format"+"."+"type", "body", m.Type); err != nil {
return err
}
// value enum
if err := m.validateTypeEnum("format"+"."+"type", "body", *m.Type); err != nil {
return err
}
return nil
}
// ContextValidate validate this openapi import source format based on the context it is used
func (m *OpenapiImportSourceFormat) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
if err := m.contextValidateCsvConfig(ctx, formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *OpenapiImportSourceFormat) contextValidateCsvConfig(ctx context.Context, formats strfmt.Registry) error {
if m.CsvConfig != nil {
if swag.IsZero(m.CsvConfig) { // not required
return nil
}
if err := m.CsvConfig.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("format" + "." + "csv_config")
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName("format" + "." + "csv_config")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *OpenapiImportSourceFormat) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OpenapiImportSourceFormat) UnmarshalBinary(b []byte) error {
var res OpenapiImportSourceFormat
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
// OpenapiImportSourceFormatCsvConfig ImportSourceCSVConfig
//
// The CSV format settings to parse the source CSV files. This field is only needed if the source format is CSV.
//
// swagger:model OpenapiImportSourceFormatCsvConfig
type OpenapiImportSourceFormatCsvConfig struct {
// Whether a backslash (`\`) symbol followed by a character should be combined as a whole and treated as an escape sequence in a CSV field. For example, if this parameter is set to `true`, `\n` will be treated as a 'new-line' character. If it is set to `false`, `\n` will be treated as two separate characters: backslash and `n`.
//
// Currently, these are several supported escape sequences: `\0`, `\b`, `\n`, `\r`, `\t`, and `\Z`. If the parameter is set to `true`, but the backslash escape sequence is not recognized, the backslash character is ignored.
BackslashEscape *bool `json:"backslash_escape,omitempty"`
// The delimiter character used to separate fields in the CSV data.
Delimiter *string `json:"delimiter,omitempty"`
// Whether the CSV data has a header row, which is not part of the data. If it is set to `true`, the import task will use the column names in the header row to match the column names in the target table.
HasHeaderRow *bool `json:"has_header_row,omitempty"`
// The character used to quote the fields in the CSV data.
Quote *string `json:"quote,omitempty"`
}
// Validate validates this openapi import source format csv config
func (m *OpenapiImportSourceFormatCsvConfig) Validate(formats strfmt.Registry) error {
return nil
}
// ContextValidate validates this openapi import source format csv config based on context it is used
func (m *OpenapiImportSourceFormatCsvConfig) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *OpenapiImportSourceFormatCsvConfig) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *OpenapiImportSourceFormatCsvConfig) UnmarshalBinary(b []byte) error {
var res OpenapiImportSourceFormatCsvConfig
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}