-
Notifications
You must be signed in to change notification settings - Fork 70
/
Storage.java
4067 lines (3747 loc) · 158 KB
/
Storage.java
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2015 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License 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 com.google.cloud.storage;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.api.core.InternalExtensionOnly;
import com.google.api.gax.paging.Page;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.ServiceAccountSigner.SigningException;
import com.google.cloud.FieldSelector;
import com.google.cloud.Policy;
import com.google.cloud.ReadChannel;
import com.google.cloud.Service;
import com.google.cloud.WriteChannel;
import com.google.cloud.storage.Acl.Entity;
import com.google.cloud.storage.HmacKey.HmacKeyMetadata;
import com.google.cloud.storage.PostPolicyV4.PostConditionsV4;
import com.google.cloud.storage.PostPolicyV4.PostFieldsV4;
import com.google.cloud.storage.TransportCompatibility.Transport;
import com.google.cloud.storage.UnifiedOpts.BucketListOpt;
import com.google.cloud.storage.UnifiedOpts.BucketSourceOpt;
import com.google.cloud.storage.UnifiedOpts.BucketTargetOpt;
import com.google.cloud.storage.UnifiedOpts.HmacKeyListOpt;
import com.google.cloud.storage.UnifiedOpts.HmacKeySourceOpt;
import com.google.cloud.storage.UnifiedOpts.HmacKeyTargetOpt;
import com.google.cloud.storage.UnifiedOpts.NamedField;
import com.google.cloud.storage.UnifiedOpts.ObjectListOpt;
import com.google.cloud.storage.UnifiedOpts.ObjectSourceOpt;
import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
import com.google.cloud.storage.UnifiedOpts.OptionShim;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path;
import java.security.Key;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* An interface for Google Cloud Storage.
*
* @see <a href="https://cloud.google.com/storage/docs">Google Cloud Storage</a>
*/
@InternalExtensionOnly
public interface Storage extends Service<StorageOptions>, AutoCloseable {
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
enum PredefinedAcl {
AUTHENTICATED_READ("authenticatedRead"),
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers"),
PRIVATE("private"),
PROJECT_PRIVATE("projectPrivate"),
PUBLIC_READ("publicRead"),
PUBLIC_READ_WRITE("publicReadWrite"),
BUCKET_OWNER_READ("bucketOwnerRead"),
BUCKET_OWNER_FULL_CONTROL("bucketOwnerFullControl");
private final String entry;
PredefinedAcl(String entry) {
this.entry = entry;
}
String getEntry() {
return entry;
}
}
enum BucketField implements FieldSelector, NamedField {
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ID("id", "bucket_id"),
@TransportCompatibility(Transport.HTTP)
SELF_LINK("selfLink"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
NAME("name"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
TIME_CREATED("timeCreated", "create_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
METAGENERATION("metageneration"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ACL("acl"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
DEFAULT_OBJECT_ACL("defaultObjectAcl", "default_object_acl"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
OWNER("owner"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
LABELS("labels"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
LOCATION("location"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
LOCATION_TYPE("locationType", "location_type"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
WEBSITE("website"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
VERSIONING("versioning"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CORS("cors"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
LIFECYCLE("lifecycle"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
STORAGE_CLASS("storageClass", "storage_class"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ETAG("etag"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ENCRYPTION("encryption"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
BILLING("billing"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
DEFAULT_EVENT_BASED_HOLD("defaultEventBasedHold", "default_event_based_hold"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
RETENTION_POLICY("retentionPolicy", "retention_policy"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
IAMCONFIGURATION("iamConfiguration", "iam_config"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
LOGGING("logging"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
UPDATED("updated", "update_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
RPO("rpo"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CUSTOM_PLACEMENT_CONFIG("customPlacementConfig", "custom_placement_config"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
AUTOCLASS("autoclass");
static final List<BucketField> REQUIRED_FIELDS = ImmutableList.of(NAME);
private final String selector;
private final String grpcFieldName;
BucketField(String selector) {
this(selector, selector);
}
BucketField(String selector, String grpcFieldName) {
this.selector = selector;
this.grpcFieldName = grpcFieldName;
}
@Override
public String getSelector() {
return selector;
}
@Override
public String getApiaryName() {
return selector;
}
@Override
public String getGrpcName() {
return grpcFieldName;
}
}
enum BlobField implements FieldSelector, NamedField {
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ACL("acl"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
BUCKET("bucket"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CACHE_CONTROL("cacheControl", "cache_control"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
COMPONENT_COUNT("componentCount", "component_count"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CONTENT_DISPOSITION("contentDisposition", "content_disposition"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CONTENT_ENCODING("contentEncoding", "content_encoding"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CONTENT_LANGUAGE("contentLanguage", "content_language"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CONTENT_TYPE("contentType", "content_type"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CRC32C("crc32c", "checksums.crc32c"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
ETAG("etag"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
GENERATION("generation"),
@TransportCompatibility(Transport.HTTP)
ID("id"),
/** {@code kind} is not exposed in {@link BlobInfo} or {@link Blob} no need to select it */
@Deprecated
@TransportCompatibility(Transport.HTTP)
KIND("kind"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
MD5HASH("md5Hash", "checksums.md5_hash"),
@TransportCompatibility(Transport.HTTP)
MEDIA_LINK("mediaLink"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
METADATA("metadata"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
METAGENERATION("metageneration"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
NAME("name"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
OWNER("owner"),
@TransportCompatibility(Transport.HTTP)
SELF_LINK("selfLink"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
SIZE("size"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
STORAGE_CLASS("storageClass", "storage_class"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
TIME_DELETED("timeDeleted", "delete_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
TIME_CREATED("timeCreated", "create_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
KMS_KEY_NAME("kmsKeyName", "kms_key"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
EVENT_BASED_HOLD("eventBasedHold", "event_based_hold"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
TEMPORARY_HOLD("temporaryHold", "temporary_hold"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
RETENTION_EXPIRATION_TIME("retentionExpirationTime", "retention_expire_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
UPDATED("updated", "update_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CUSTOM_TIME("customTime", "custom_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
TIME_STORAGE_CLASS_UPDATED("timeStorageClassUpdated", "update_storage_class_time"),
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
CUSTOMER_ENCRYPTION("customerEncryption", "customer_encryption");
static final List<NamedField> REQUIRED_FIELDS = ImmutableList.of(BUCKET, NAME);
private final String selector;
private final String grpcFieldName;
BlobField(String selector) {
this(selector, selector);
}
BlobField(String selector, String grpcFieldName) {
this.selector = selector;
this.grpcFieldName = grpcFieldName;
}
@Override
public String getSelector() {
return selector;
}
@Override
public String getApiaryName() {
return selector;
}
@Override
public String getGrpcName() {
return grpcFieldName;
}
}
enum UriScheme {
HTTP("http"),
HTTPS("https");
private final String scheme;
UriScheme(String scheme) {
this.scheme = scheme;
}
public String getScheme() {
return scheme;
}
}
/** Class for specifying bucket target options. */
class BucketTargetOption extends Option<BucketTargetOpt> {
private static final long serialVersionUID = 6699243191830059404L;
private BucketTargetOption(BucketTargetOpt opt) {
super(opt);
}
/** Returns an option for specifying bucket's predefined ACL configuration. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketTargetOption predefinedAcl(@NonNull PredefinedAcl acl) {
return new BucketTargetOption(UnifiedOpts.predefinedAcl(acl));
}
/** Returns an option for specifying bucket's default ACL configuration for blobs. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketTargetOption predefinedDefaultObjectAcl(@NonNull PredefinedAcl acl) {
return new BucketTargetOption(UnifiedOpts.predefinedDefaultObjectAcl(acl));
}
/**
* Returns an option for bucket's metageneration match. If this option is used the request will
* fail if metageneration does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketTargetOption metagenerationMatch() {
return new BucketTargetOption(UnifiedOpts.metagenerationMatchExtractor());
}
/**
* Returns an option for bucket's metageneration mismatch. If this option is used the request
* will fail if metageneration matches.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketTargetOption metagenerationNotMatch() {
return new BucketTargetOption(UnifiedOpts.metagenerationNotMatchExtractor());
}
/**
* Returns an option to define the billing user project. This option is required by buckets with
* `requester_pays` flag enabled to assign operation costs.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketTargetOption userProject(@NonNull String userProject) {
return new BucketTargetOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to define the projection in the API request. In some cases this option may
* be needed to be set to `noAcl` to omit ACL data from the response. The default value is
* `full`
*
* @see <a href="https://cloud.google.com/storage/docs/json_api/v1/buckets/patch">Buckets:
* patch</a>
*/
@TransportCompatibility({Transport.HTTP})
public static BucketTargetOption projection(@NonNull String projection) {
return new BucketTargetOption(UnifiedOpts.projection(projection));
}
}
/** Class for specifying bucket source options. */
class BucketSourceOption extends Option<BucketSourceOpt> {
private static final long serialVersionUID = 3808812145390746748L;
BucketSourceOption(BucketSourceOpt opt) {
super(opt);
}
/**
* Returns an option for bucket's metageneration match. If this option is used the request will
* fail if bucket's metageneration does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketSourceOption metagenerationMatch(long metageneration) {
return new BucketSourceOption(UnifiedOpts.metagenerationMatch(metageneration));
}
/**
* Returns an option for bucket's metageneration mismatch. If this option is used the request
* will fail if bucket's metageneration matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketSourceOption metagenerationNotMatch(long metageneration) {
return new BucketSourceOption(UnifiedOpts.metagenerationNotMatch(metageneration));
}
/**
* Returns an option for bucket's billing user project. This option is only used by the buckets
* with 'requester_pays' flag.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketSourceOption userProject(@NonNull String userProject) {
return new BucketSourceOption(UnifiedOpts.userProject(userProject));
}
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketSourceOption requestedPolicyVersion(long version) {
return new BucketSourceOption(UnifiedOpts.requestedPolicyVersion(version));
}
}
/** Class for specifying listHmacKeys options */
class ListHmacKeysOption extends Option<HmacKeyListOpt> {
private ListHmacKeysOption(HmacKeyListOpt opt) {
super(opt);
}
/**
* Returns an option for the Service Account whose keys to list. If this option is not used,
* keys for all accounts will be listed.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption serviceAccount(@NonNull ServiceAccount serviceAccount) {
return new ListHmacKeysOption(UnifiedOpts.serviceAccount(serviceAccount));
}
/** Returns an option for the maximum amount of HMAC keys returned per page. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption maxResults(long pageSize) {
return new ListHmacKeysOption(UnifiedOpts.pageSize(pageSize));
}
/** Returns an option to specify the page token from which to start listing HMAC keys. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption pageToken(@NonNull String pageToken) {
return new ListHmacKeysOption(UnifiedOpts.pageToken(pageToken));
}
/**
* Returns an option to specify whether to show deleted keys in the result. This option is false
* by default.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption showDeletedKeys(boolean showDeletedKeys) {
return new ListHmacKeysOption(UnifiedOpts.showDeletedKeys(showDeletedKeys));
}
/**
* Returns an option to specify the project to be billed for this request. Required for
* Requester Pays buckets.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption userProject(@NonNull String userProject) {
return new ListHmacKeysOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to specify the Project ID for this request. If not specified, defaults to
* Application Default Credentials.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static ListHmacKeysOption projectId(@NonNull String projectId) {
return new ListHmacKeysOption(UnifiedOpts.projectId(projectId));
}
}
/** Class for specifying createHmacKey options */
class CreateHmacKeyOption extends Option<HmacKeyTargetOpt> {
private CreateHmacKeyOption(HmacKeyTargetOpt opt) {
super(opt);
}
/**
* Returns an option to specify the project to be billed for this request. Required for
* Requester Pays buckets.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static CreateHmacKeyOption userProject(@NonNull String userProject) {
return new CreateHmacKeyOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to specify the Project ID for this request. If not specified, defaults to
* Application Default Credentials.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static CreateHmacKeyOption projectId(@NonNull String projectId) {
return new CreateHmacKeyOption(UnifiedOpts.projectId(projectId));
}
}
/** Class for specifying getHmacKey options */
class GetHmacKeyOption extends Option<HmacKeySourceOpt> {
private GetHmacKeyOption(HmacKeySourceOpt opt) {
super(opt);
}
/**
* Returns an option to specify the project to be billed for this request. Required for
* Requester Pays buckets.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static GetHmacKeyOption userProject(@NonNull String userProject) {
return new GetHmacKeyOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to specify the Project ID for this request. If not specified, defaults to
* Application Default Credentials.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static GetHmacKeyOption projectId(@NonNull String projectId) {
return new GetHmacKeyOption(UnifiedOpts.projectId(projectId));
}
}
/** Class for specifying deleteHmacKey options */
class DeleteHmacKeyOption extends Option<HmacKeyTargetOpt> {
private DeleteHmacKeyOption(HmacKeyTargetOpt opt) {
super(opt);
}
/**
* Returns an option to specify the project to be billed for this request. Required for
* Requester Pays buckets.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static DeleteHmacKeyOption userProject(@NonNull String userProject) {
return new DeleteHmacKeyOption(UnifiedOpts.userProject(userProject));
}
}
/** Class for specifying updateHmacKey options */
class UpdateHmacKeyOption extends Option<HmacKeyTargetOpt> {
private UpdateHmacKeyOption(HmacKeyTargetOpt opt) {
super(opt);
}
/**
* Returns an option to specify the project to be billed for this request. Required for
* Requester Pays buckets.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static UpdateHmacKeyOption userProject(@NonNull String userProject) {
return new UpdateHmacKeyOption(UnifiedOpts.userProject(userProject));
}
}
/** Class for specifying bucket get options. */
class BucketGetOption extends Option<BucketSourceOpt> {
private static final long serialVersionUID = -669900932880354035L;
BucketGetOption(BucketSourceOpt opt) {
super(opt);
}
/**
* Returns an option for bucket's metageneration match. If this option is used the request will
* fail if bucket's metageneration does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketGetOption metagenerationMatch(long metageneration) {
return new BucketGetOption(UnifiedOpts.metagenerationMatch(metageneration));
}
/**
* Returns an option for bucket's metageneration mismatch. If this option is used the request
* will fail if bucket's metageneration matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketGetOption metagenerationNotMatch(long metageneration) {
return new BucketGetOption(UnifiedOpts.metagenerationNotMatch(metageneration));
}
/**
* Returns an option for bucket's billing user project. This option is only used by the buckets
* with 'requester_pays' flag.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketGetOption userProject(@NonNull String userProject) {
return new BucketGetOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to specify the bucket's fields to be returned by the RPC call. If this
* option is not provided all bucket's fields are returned. {@code BucketGetOption.fields}) can
* be used to specify only the fields of interest. Bucket name is always returned, even if not
* specified.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BucketGetOption fields(BucketField... fields) {
requireNonNull(fields, "fields must be non null");
ImmutableSet<NamedField> set =
ImmutableSet.<NamedField>builder()
.addAll(BucketField.REQUIRED_FIELDS)
.add(fields)
.build();
return new BucketGetOption(UnifiedOpts.fields(set));
}
}
/** Class for specifying blob target options. */
class BlobTargetOption extends Option<ObjectTargetOpt> {
private static final long serialVersionUID = -5554842495450599563L;
BlobTargetOption(ObjectTargetOpt opt) {
super(opt);
}
/** Returns an option for specifying blob's predefined ACL configuration. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption predefinedAcl(@NonNull PredefinedAcl acl) {
return new BlobTargetOption(UnifiedOpts.predefinedAcl(acl));
}
/**
* Returns an option that causes an operation to succeed only if the target blob does not exist.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption doesNotExist() {
return new BlobTargetOption(UnifiedOpts.doesNotExist());
}
/**
* Returns an option for blob's data generation match. If this option is used the request will
* fail if generation does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption generationMatch() {
return new BlobTargetOption(UnifiedOpts.generationMatchExtractor());
}
/**
* Returns an option for blob's data generation match. If this option is used the request will
* fail if blob's generation does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption generationMatch(long generation) {
return new BlobTargetOption(UnifiedOpts.generationMatch(generation));
}
/**
* Returns an option for blob's data generation mismatch. If this option is used the request
* will fail if generation matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption generationNotMatch(long generation) {
return new BlobTargetOption(UnifiedOpts.generationNotMatch(generation));
}
/**
* Returns an option for blob's data generation mismatch. If this option is used the request
* will fail if generation matches.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption generationNotMatch() {
return new BlobTargetOption(UnifiedOpts.generationNotMatchExtractor());
}
/**
* Returns an option for blob's metageneration match. If this option is used the request will
* fail if metageneration does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption metagenerationMatch() {
return new BlobTargetOption(UnifiedOpts.metagenerationMatchExtractor());
}
/**
* Returns an option for blob's metageneration match. If this option is used the request will
* fail if blob's metageneration does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption metagenerationMatch(long metageneration) {
return new BlobTargetOption(UnifiedOpts.metagenerationMatch(metageneration));
}
/**
* Returns an option for blob's metageneration mismatch. If this option is used the request will
* fail if metageneration matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption metagenerationNotMatch(long metageneration) {
return new BlobTargetOption(UnifiedOpts.metagenerationNotMatch(metageneration));
}
/**
* Returns an option for blob's metageneration mismatch. If this option is used the request will
* fail if metageneration matches.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption metagenerationNotMatch() {
return new BlobTargetOption(UnifiedOpts.metagenerationNotMatchExtractor());
}
/**
* Returns an option for blob's data disabledGzipContent. If this option is used, the request
* will create a blob with disableGzipContent; at present, this is only for upload.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption disableGzipContent() {
return new BlobTargetOption(UnifiedOpts.disableGzipContent());
}
/**
* Returns an option for detecting content type. If this option is used, the content type is
* detected from the blob name if not explicitly set. This option is on the client side only, it
* does not appear in a RPC call.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption detectContentType() {
return new BlobTargetOption(UnifiedOpts.detectContentType());
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption encryptionKey(@NonNull Key key) {
return new BlobTargetOption(UnifiedOpts.encryptionKey(key));
}
/**
* Returns an option for blob's billing user project. This option is only used by the buckets
* with 'requester_pays' flag.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption userProject(@NonNull String userProject) {
return new BlobTargetOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*
* @param key the AES256 encoded in base64
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption encryptionKey(@NonNull String key) {
return new BlobTargetOption(UnifiedOpts.encryptionKey(key));
}
/** Returns an option to set a customer-managed key for server-side encryption of the blob. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobTargetOption kmsKeyName(@NonNull String kmsKeyName) {
return new BlobTargetOption(UnifiedOpts.kmsKeyName(kmsKeyName));
}
}
/** Class for specifying blob write options. */
class BlobWriteOption extends OptionShim<ObjectTargetOpt> implements Serializable {
private static final long serialVersionUID = 5536338021856320475L;
BlobWriteOption(ObjectTargetOpt opt) {
super(opt);
}
/** Returns an option for specifying blob's predefined ACL configuration. */
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption predefinedAcl(@NonNull PredefinedAcl acl) {
return new BlobWriteOption(UnifiedOpts.predefinedAcl(acl));
}
/**
* Returns an option that causes an operation to succeed only if the target blob does not exist.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption doesNotExist() {
return new BlobWriteOption(UnifiedOpts.doesNotExist());
}
/**
* Returns an option for blob's data generation match. If this option is used the request will
* fail if generation does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption generationMatch() {
return new BlobWriteOption(UnifiedOpts.generationMatchExtractor());
}
/**
* Returns an option for blob's data generation mismatch. If this option is used the request
* will fail if generation matches.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption generationNotMatch() {
return new BlobWriteOption(UnifiedOpts.generationNotMatchExtractor());
}
/**
* Returns an option for blob's metageneration match. If this option is used the request will
* fail if metageneration does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption metagenerationMatch() {
return new BlobWriteOption(UnifiedOpts.metagenerationMatchExtractor());
}
/**
* Returns an option for blob's metageneration mismatch. If this option is used the request will
* fail if metageneration matches.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption metagenerationNotMatch() {
return new BlobWriteOption(UnifiedOpts.metagenerationNotMatchExtractor());
}
/**
* Returns an option for blob's data MD5 hash match. If this option is used the request will
* fail if blobs' data MD5 hash does not match.
*
* @deprecated Please compute and use a crc32c checksum instead. {@link #crc32cMatch()}
*/
@Deprecated
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption md5Match() {
return new BlobWriteOption(UnifiedOpts.md5MatchExtractor());
}
/**
* Returns an option for blob's data CRC32C checksum match. If this option is used the request
* will fail if blobs' data CRC32C checksum does not match.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption crc32cMatch() {
return new BlobWriteOption(UnifiedOpts.crc32cMatchExtractor());
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption encryptionKey(@NonNull Key key) {
return new BlobWriteOption(UnifiedOpts.encryptionKey(key));
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*
* @param key the AES256 encoded in base64
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption encryptionKey(@NonNull String key) {
return new BlobWriteOption(UnifiedOpts.encryptionKey(key));
}
/**
* Returns an option to set a customer-managed KMS key for server-side encryption of the blob.
*
* @param kmsKeyName the KMS key resource id
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption kmsKeyName(@NonNull String kmsKeyName) {
return new BlobWriteOption(UnifiedOpts.kmsKeyName(kmsKeyName));
}
/**
* Returns an option for blob's billing user project. This option is only used by the buckets
* with 'requester_pays' flag.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption userProject(@NonNull String userProject) {
return new BlobWriteOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option that signals automatic gzip compression should not be performed en route to
* the bucket.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption disableGzipContent() {
return new BlobWriteOption(UnifiedOpts.disableGzipContent());
}
/**
* Returns an option for detecting content type. If this option is used, the content type is
* detected from the blob name if not explicitly set. This option is on the client side only, it
* does not appear in a RPC call.
*
* <p>Content type detection is based on the database presented by {@link
* URLConnection#getFileNameMap()}
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobWriteOption detectContentType() {
return new BlobWriteOption(UnifiedOpts.detectContentType());
}
}
/** Class for specifying blob source options. */
class BlobSourceOption extends Option<ObjectSourceOpt> {
private static final long serialVersionUID = -8626355836092280204L;
BlobSourceOption(ObjectSourceOpt opt) {
super(opt);
}
/**
* Returns an option for blob's data generation match. If this option is used the request will
* fail if blob's generation does not match. The generation value to compare with the actual
* blob's generation is taken from a source {@link BlobId} object. When this option is passed to
* a {@link Storage} method and {@link BlobId#getGeneration()} is {@code null} or no {@link
* BlobId} is provided an exception is thrown.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption generationMatch() {
return new BlobSourceOption(UnifiedOpts.generationMatchExtractor());
}
/**
* Returns an option for blob's data generation match. If this option is used the request will
* fail if blob's generation does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption generationMatch(long generation) {
return new BlobSourceOption(UnifiedOpts.generationMatch(generation));
}
/**
* Returns an option for blob's data generation mismatch. If this option is used the request
* will fail if blob's generation matches. The generation value to compare with the actual
* blob's generation is taken from a source {@link BlobId} object. When this option is passed to
* a {@link Storage} method and {@link BlobId#getGeneration()} is {@code null} or no {@link
* BlobId} is provided an exception is thrown.
*
* @deprecated This option is invalid, and can never result in a valid response from the server.
* use {@link #generationNotMatch(long)} instead.
*/
@Deprecated
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption generationNotMatch() {
return new BlobSourceOption(UnifiedOpts.generationNotMatchExtractor());
}
/**
* Returns an option for blob's data generation mismatch. If this option is used the request
* will fail if blob's generation matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption generationNotMatch(long generation) {
return new BlobSourceOption(UnifiedOpts.generationNotMatch(generation));
}
/**
* Returns an option for blob's metageneration match. If this option is used the request will
* fail if blob's metageneration does not match the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption metagenerationMatch(long metageneration) {
return new BlobSourceOption(UnifiedOpts.metagenerationMatch(metageneration));
}
/**
* Returns an option for blob's metageneration mismatch. If this option is used the request will
* fail if blob's metageneration matches the provided value.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption metagenerationNotMatch(long metageneration) {
return new BlobSourceOption(UnifiedOpts.metagenerationNotMatch(metageneration));
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption decryptionKey(@NonNull Key key) {
return new BlobSourceOption(UnifiedOpts.decryptionKey(key));
}
/**
* Returns an option to set a customer-supplied AES256 key for server-side encryption of the
* blob.
*
* @param key the AES256 encoded in base64
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption decryptionKey(@NonNull String key) {
return new BlobSourceOption(UnifiedOpts.decryptionKey(key));
}
/**
* Returns an option for blob's billing user project. This option is only used by the buckets
* with 'requester_pays' flag.
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption userProject(@NonNull String userProject) {
return new BlobSourceOption(UnifiedOpts.userProject(userProject));
}
/**
* Returns an option for whether the request should return the raw input stream, instead of
* automatically decompressing the content. By default, this is false for Blob.downloadTo(), but
* true for ReadChannel.read().
*/
@TransportCompatibility({Transport.HTTP, Transport.GRPC})
public static BlobSourceOption shouldReturnRawInputStream(boolean shouldReturnRawInputStream) {
return new BlobSourceOption(UnifiedOpts.returnRawInputStream(shouldReturnRawInputStream));
}
}