-
Notifications
You must be signed in to change notification settings - Fork 18
/
types.go
713 lines (587 loc) · 17.2 KB
/
types.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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
// +-------------------------------------------------------------------------
// | Copyright (C) 2016 Yunify, Inc.
// +-------------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0 (the "License");
// | you may not use this work except in compliance with the License.
// | You may obtain a copy of the License in the LICENSE file, or at:
// |
// | http://www.apache.org/licenses/LICENSE-2.0
// |
// | Unless required by applicable law or agreed to in writing, software
// | distributed under the License is distributed on an "AS IS" BASIS,
// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// | See the License for the specific language governing permissions and
// | limitations under the License.
// +-------------------------------------------------------------------------
package service
import (
"fmt"
"time"
"github.com/yunify/qingstor-sdk-go/v3/request/errors"
)
// Properties presents the service properties.
type Properties struct {
// Bucket name
BucketName *string `json:"bucket-name" name:"bucket-name"` // Required
// Object key
ObjectKey *string `json:"object-key" name:"object-key"` // Required
// QingCloud Zone ID
Zone *string `json:"zone" name:"zone"`
}
// AbortIncompleteMultipartUploadType presents AbortIncompleteMultipartUpload.
type AbortIncompleteMultipartUploadType struct {
// days after initiation
DaysAfterInitiation *int `json:"days_after_initiation" name:"days_after_initiation"` // Required
}
// Validate validates the AbortIncompleteMultipartUpload.
func (v *AbortIncompleteMultipartUploadType) Validate() error {
if v.DaysAfterInitiation == nil {
return errors.ParameterRequiredError{
ParameterName: "DaysAfterInitiation",
ParentName: "AbortIncompleteMultipartUpload",
}
}
return nil
}
// ACLType presents ACL.
type ACLType struct {
Grantee *GranteeType `json:"grantee" name:"grantee"` // Required
// Permission for this grantee
// Permission's available values: READ, WRITE, FULL_CONTROL
Permission *string `json:"permission" name:"permission"` // Required
}
// Validate validates the ACL.
func (v *ACLType) Validate() error {
if v.Grantee != nil {
if err := v.Grantee.Validate(); err != nil {
return err
}
}
if v.Grantee == nil {
return errors.ParameterRequiredError{
ParameterName: "Grantee",
ParentName: "ACL",
}
}
if v.Permission == nil {
return errors.ParameterRequiredError{
ParameterName: "Permission",
ParentName: "ACL",
}
}
if v.Permission != nil {
permissionValidValues := []string{"READ", "WRITE", "FULL_CONTROL"}
permissionParameterValue := fmt.Sprint(*v.Permission)
permissionIsValid := false
for _, value := range permissionValidValues {
if value == permissionParameterValue {
permissionIsValid = true
}
}
if !permissionIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Permission",
ParameterValue: permissionParameterValue,
AllowedValues: permissionValidValues,
}
}
}
return nil
}
// BucketType presents Bucket.
type BucketType struct {
// Created time of the bucket
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// QingCloud Zone ID
Location *string `json:"location,omitempty" name:"location"`
// Bucket name
Name *string `json:"name,omitempty" name:"name"`
// URL to access the bucket
URL *string `json:"url,omitempty" name:"url"`
}
// Validate validates the Bucket.
func (v *BucketType) Validate() error {
return nil
}
// CloudfuncArgsType presents CloudfuncArgs.
type CloudfuncArgsType struct {
Action *string `json:"action" name:"action"` // Required
KeyPrefix *string `json:"key_prefix,omitempty" name:"key_prefix" default:"gen"`
KeySeprate *string `json:"key_seprate,omitempty" name:"key_seprate" default:"_"`
SaveBucket *string `json:"save_bucket,omitempty" name:"save_bucket"`
}
// Validate validates the CloudfuncArgs.
func (v *CloudfuncArgsType) Validate() error {
if v.Action == nil {
return errors.ParameterRequiredError{
ParameterName: "Action",
ParentName: "CloudfuncArgs",
}
}
return nil
}
// ConditionType presents Condition.
type ConditionType struct {
IPAddress *IPAddressType `json:"ip_address,omitempty" name:"ip_address"`
IsNull *IsNullType `json:"is_null,omitempty" name:"is_null"`
NotIPAddress *NotIPAddressType `json:"not_ip_address,omitempty" name:"not_ip_address"`
StringLike *StringLikeType `json:"string_like,omitempty" name:"string_like"`
StringNotLike *StringNotLikeType `json:"string_not_like,omitempty" name:"string_not_like"`
}
// Validate validates the Condition.
func (v *ConditionType) Validate() error {
if v.IPAddress != nil {
if err := v.IPAddress.Validate(); err != nil {
return err
}
}
if v.IsNull != nil {
if err := v.IsNull.Validate(); err != nil {
return err
}
}
if v.NotIPAddress != nil {
if err := v.NotIPAddress.Validate(); err != nil {
return err
}
}
if v.StringLike != nil {
if err := v.StringLike.Validate(); err != nil {
return err
}
}
if v.StringNotLike != nil {
if err := v.StringNotLike.Validate(); err != nil {
return err
}
}
return nil
}
// CORSRuleType presents CORSRule.
type CORSRuleType struct {
// Allowed headers
AllowedHeaders []*string `json:"allowed_headers,omitempty" name:"allowed_headers"`
// Allowed methods
AllowedMethods []*string `json:"allowed_methods" name:"allowed_methods"` // Required
// Allowed origin
AllowedOrigin *string `json:"allowed_origin" name:"allowed_origin"` // Required
// Expose headers
ExposeHeaders []*string `json:"expose_headers,omitempty" name:"expose_headers"`
// Max age seconds
MaxAgeSeconds *int `json:"max_age_seconds,omitempty" name:"max_age_seconds"`
}
// Validate validates the CORSRule.
func (v *CORSRuleType) Validate() error {
if len(v.AllowedMethods) == 0 {
return errors.ParameterRequiredError{
ParameterName: "AllowedMethods",
ParentName: "CORSRule",
}
}
if v.AllowedOrigin == nil {
return errors.ParameterRequiredError{
ParameterName: "AllowedOrigin",
ParentName: "CORSRule",
}
}
return nil
}
// ExpirationType presents Expiration.
type ExpirationType struct {
// days
Days *int `json:"days,omitempty" name:"days"`
}
// Validate validates the Expiration.
func (v *ExpirationType) Validate() error {
return nil
}
// FilterType presents Filter.
type FilterType struct {
// Prefix matching
Prefix *string `json:"prefix" name:"prefix"` // Required
}
// Validate validates the Filter.
func (v *FilterType) Validate() error {
if v.Prefix == nil {
return errors.ParameterRequiredError{
ParameterName: "Prefix",
ParentName: "Filter",
}
}
return nil
}
// GranteeType presents Grantee.
type GranteeType struct {
// Grantee user ID
ID *string `json:"id,omitempty" name:"id"`
// Grantee group name
Name *string `json:"name,omitempty" name:"name"`
// Grantee type
// Type's available values: user, group
Type *string `json:"type" name:"type"` // Required
}
// Validate validates the Grantee.
func (v *GranteeType) Validate() error {
if v.Type == nil {
return errors.ParameterRequiredError{
ParameterName: "Type",
ParentName: "Grantee",
}
}
if v.Type != nil {
typeValidValues := []string{"user", "group"}
typeParameterValue := fmt.Sprint(*v.Type)
typeIsValid := false
for _, value := range typeValidValues {
if value == typeParameterValue {
typeIsValid = true
}
}
if !typeIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Type",
ParameterValue: typeParameterValue,
AllowedValues: typeValidValues,
}
}
}
return nil
}
// IPAddressType presents IPAddress.
type IPAddressType struct {
// Source IP
SourceIP []*string `json:"source_ip,omitempty" name:"source_ip"`
}
// Validate validates the IPAddress.
func (v *IPAddressType) Validate() error {
return nil
}
// IsNullType presents IsNull.
type IsNullType struct {
// Refer url
Referer *bool `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the IsNull.
func (v *IsNullType) Validate() error {
return nil
}
// KeyType presents Key.
type KeyType struct {
// Object created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// Whether this key is encrypted
Encrypted *bool `json:"encrypted,omitempty" name:"encrypted"`
// MD5sum of the object
Etag *string `json:"etag,omitempty" name:"etag"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// MIME type of the object
MimeType *string `json:"mime_type,omitempty" name:"mime_type"`
// Last modified time in unix time format
Modified *int `json:"modified,omitempty" name:"modified"`
// Object content size
Size *int64 `json:"size,omitempty" name:"size"`
// Object storage class
StorageClass *string `json:"storage_class,omitempty" name:"storage_class"`
}
// Validate validates the Key.
func (v *KeyType) Validate() error {
return nil
}
// KeyDeleteErrorType presents KeyDeleteError.
type KeyDeleteErrorType struct {
// Error code
Code *string `json:"code,omitempty" name:"code"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// Error message
Message *string `json:"message,omitempty" name:"message"`
}
// Validate validates the KeyDeleteError.
func (v *KeyDeleteErrorType) Validate() error {
return nil
}
// NotIPAddressType presents NotIPAddress.
type NotIPAddressType struct {
// Source IP
SourceIP []*string `json:"source_ip,omitempty" name:"source_ip"`
}
// Validate validates the NotIPAddress.
func (v *NotIPAddressType) Validate() error {
return nil
}
// NotificationType presents Notification.
type NotificationType struct {
// Event processing service
// Cloudfunc's available values: tupu-porn, notifier, image
Cloudfunc *string `json:"cloudfunc" name:"cloudfunc"` // Required
CloudfuncArgs *CloudfuncArgsType `json:"cloudfunc_args,omitempty" name:"cloudfunc_args"`
// event types
EventTypes []*string `json:"event_types" name:"event_types"` // Required
// notification id
ID *string `json:"id" name:"id"` // Required
// notify url
NotifyURL *string `json:"notify_url,omitempty" name:"notify_url"`
// Object name matching rule
ObjectFilters []*string `json:"object_filters,omitempty" name:"object_filters"`
}
// Validate validates the Notification.
func (v *NotificationType) Validate() error {
if v.Cloudfunc == nil {
return errors.ParameterRequiredError{
ParameterName: "Cloudfunc",
ParentName: "Notification",
}
}
if v.Cloudfunc != nil {
cloudfuncValidValues := []string{"tupu-porn", "notifier", "image"}
cloudfuncParameterValue := fmt.Sprint(*v.Cloudfunc)
cloudfuncIsValid := false
for _, value := range cloudfuncValidValues {
if value == cloudfuncParameterValue {
cloudfuncIsValid = true
}
}
if !cloudfuncIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Cloudfunc",
ParameterValue: cloudfuncParameterValue,
AllowedValues: cloudfuncValidValues,
}
}
}
if v.CloudfuncArgs != nil {
if err := v.CloudfuncArgs.Validate(); err != nil {
return err
}
}
if len(v.EventTypes) == 0 {
return errors.ParameterRequiredError{
ParameterName: "EventTypes",
ParentName: "Notification",
}
}
if v.ID == nil {
return errors.ParameterRequiredError{
ParameterName: "ID",
ParentName: "Notification",
}
}
return nil
}
// ObjectPartType presents ObjectPart.
type ObjectPartType struct {
// Object part created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// MD5sum of the object part
Etag *string `json:"etag,omitempty" name:"etag"`
// Object part number
PartNumber *int `json:"part_number" name:"part_number" default:"0"` // Required
// Object part size
Size *int64 `json:"size,omitempty" name:"size"`
}
// Validate validates the ObjectPart.
func (v *ObjectPartType) Validate() error {
if v.PartNumber == nil {
return errors.ParameterRequiredError{
ParameterName: "PartNumber",
ParentName: "ObjectPart",
}
}
return nil
}
// OwnerType presents Owner.
type OwnerType struct {
// User ID
ID *string `json:"id,omitempty" name:"id"`
// Username
Name *string `json:"name,omitempty" name:"name"`
}
// Validate validates the Owner.
func (v *OwnerType) Validate() error {
return nil
}
// RuleType presents Rule.
type RuleType struct {
AbortIncompleteMultipartUpload *AbortIncompleteMultipartUploadType `json:"abort_incomplete_multipart_upload,omitempty" name:"abort_incomplete_multipart_upload"`
Expiration *ExpirationType `json:"expiration,omitempty" name:"expiration"`
Filter *FilterType `json:"filter" name:"filter"` // Required
// rule id
ID *string `json:"id" name:"id"` // Required
// rule status
// Status's available values: enabled, disabled
Status *string `json:"status" name:"status"` // Required
Transition *TransitionType `json:"transition,omitempty" name:"transition"`
}
// Validate validates the Rule.
func (v *RuleType) Validate() error {
if v.AbortIncompleteMultipartUpload != nil {
if err := v.AbortIncompleteMultipartUpload.Validate(); err != nil {
return err
}
}
if v.Expiration != nil {
if err := v.Expiration.Validate(); err != nil {
return err
}
}
if v.Filter != nil {
if err := v.Filter.Validate(); err != nil {
return err
}
}
if v.Filter == nil {
return errors.ParameterRequiredError{
ParameterName: "Filter",
ParentName: "Rule",
}
}
if v.ID == nil {
return errors.ParameterRequiredError{
ParameterName: "ID",
ParentName: "Rule",
}
}
if v.Status == nil {
return errors.ParameterRequiredError{
ParameterName: "Status",
ParentName: "Rule",
}
}
if v.Status != nil {
statusValidValues := []string{"enabled", "disabled"}
statusParameterValue := fmt.Sprint(*v.Status)
statusIsValid := false
for _, value := range statusValidValues {
if value == statusParameterValue {
statusIsValid = true
}
}
if !statusIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Status",
ParameterValue: statusParameterValue,
AllowedValues: statusValidValues,
}
}
}
if v.Transition != nil {
if err := v.Transition.Validate(); err != nil {
return err
}
}
return nil
}
// StatementType presents Statement.
type StatementType struct {
// QingStor API methods
Action []*string `json:"action" name:"action"` // Required
Condition *ConditionType `json:"condition,omitempty" name:"condition"`
// Statement effect
// Effect's available values: allow, deny
Effect *string `json:"effect" name:"effect"` // Required
// Bucket policy id, must be unique
ID *string `json:"id" name:"id"` // Required
// The resources to apply bucket policy
Resource []*string `json:"resource,omitempty" name:"resource"`
// The user to apply bucket policy
User []*string `json:"user" name:"user"` // Required
}
// Validate validates the Statement.
func (v *StatementType) Validate() error {
if len(v.Action) == 0 {
return errors.ParameterRequiredError{
ParameterName: "Action",
ParentName: "Statement",
}
}
if v.Condition != nil {
if err := v.Condition.Validate(); err != nil {
return err
}
}
if v.Effect == nil {
return errors.ParameterRequiredError{
ParameterName: "Effect",
ParentName: "Statement",
}
}
if v.Effect != nil {
effectValidValues := []string{"allow", "deny"}
effectParameterValue := fmt.Sprint(*v.Effect)
effectIsValid := false
for _, value := range effectValidValues {
if value == effectParameterValue {
effectIsValid = true
}
}
if !effectIsValid {
return errors.ParameterValueNotAllowedError{
ParameterName: "Effect",
ParameterValue: effectParameterValue,
AllowedValues: effectValidValues,
}
}
}
if v.ID == nil {
return errors.ParameterRequiredError{
ParameterName: "ID",
ParentName: "Statement",
}
}
if len(v.User) == 0 {
return errors.ParameterRequiredError{
ParameterName: "User",
ParentName: "Statement",
}
}
return nil
}
// StringLikeType presents StringLike.
type StringLikeType struct {
// Refer url
Referer []*string `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the StringLike.
func (v *StringLikeType) Validate() error {
return nil
}
// StringNotLikeType presents StringNotLike.
type StringNotLikeType struct {
// Refer url
Referer []*string `json:"Referer,omitempty" name:"Referer"`
}
// Validate validates the StringNotLike.
func (v *StringNotLikeType) Validate() error {
return nil
}
// TransitionType presents Transition.
type TransitionType struct {
// days
Days *int `json:"days,omitempty" name:"days"`
// storage class
StorageClass *int `json:"storage_class" name:"storage_class"` // Required
}
// Validate validates the Transition.
func (v *TransitionType) Validate() error {
if v.StorageClass == nil {
return errors.ParameterRequiredError{
ParameterName: "StorageClass",
ParentName: "Transition",
}
}
return nil
}
// UploadsType presents Uploads.
type UploadsType struct {
// Object part created time
Created *time.Time `json:"created,omitempty" name:"created" format:"ISO 8601"`
// Object key
Key *string `json:"key,omitempty" name:"key"`
// Object upload id
UploadID *string `json:"upload_id,omitempty" name:"upload_id"`
}
// Validate validates the Uploads.
func (v *UploadsType) Validate() error {
return nil
}