google-cloud-storage 1.37.0 → 1.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/OVERVIEW.md +32 -0
- data/lib/google/cloud/storage/bucket/acl.rb +28 -26
- data/lib/google/cloud/storage/bucket.rb +37 -3
- data/lib/google/cloud/storage/project.rb +6 -4
- data/lib/google/cloud/storage/service.rb +214 -225
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a6e0506ffc44db974accb0e91b5d9efd1f9898a07b15bb286d8d9428c83ec1
|
4
|
+
data.tar.gz: f51a2efcd382bb9bc5b2c04503456eca85cdf400897995a32a3612e56839e6e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ccaa608e3aa4e9ffc214885ce11a798d622d216a18a686f80972e6f6b469b6763535871228b6eb75af7c1e1a0b918c2343f15c114f9422925da8c7ae13b5c5e
|
7
|
+
data.tar.gz: 2c7b4e5b998be2a49f10077024590d6898384da1dcc44a4e5995cf0a55419be421671fe6e78c669844c79ea1193566dbe303a34f208dd3d29ee0fba900f8b036
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,39 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.42.0 (2022-09-21)
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* send invocation_id header in all requests ([#19161](https://github.com/googleapis/google-cloud-ruby/issues/19161))
|
8
|
+
|
9
|
+
### 1.41.0 (2022-09-16)
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* add retry support for non-idempotent operations ([#19134](https://github.com/googleapis/google-cloud-ruby/issues/19134))
|
14
|
+
#### Bug Fixes
|
15
|
+
|
16
|
+
* Correct options checks in retry operations ([#19135](https://github.com/googleapis/google-cloud-ruby/issues/19135))
|
17
|
+
* Update api for bucket update ([#19110](https://github.com/googleapis/google-cloud-ruby/issues/19110))
|
18
|
+
|
19
|
+
### 1.40.0 (2022-09-13)
|
20
|
+
|
21
|
+
#### Features
|
22
|
+
|
23
|
+
* Update all patch bucket helper methods to accept preconditions ([#19117](https://github.com/googleapis/google-cloud-ruby/issues/19117))
|
24
|
+
|
25
|
+
### 1.39.0 (2022-08-24)
|
26
|
+
|
27
|
+
#### Features
|
28
|
+
|
29
|
+
* add support for conditional idempotent operations ([#18834](https://github.com/googleapis/google-cloud-ruby/issues/18834))
|
30
|
+
|
31
|
+
### 1.38.0 (2022-07-31)
|
32
|
+
|
33
|
+
#### Features
|
34
|
+
|
35
|
+
* Add support for dual region gcs buckets ([#18862](https://github.com/googleapis/google-cloud-ruby/issues/18862))
|
36
|
+
|
3
37
|
### 1.37.0 (2022-06-30)
|
4
38
|
|
5
39
|
#### Features
|
data/OVERVIEW.md
CHANGED
@@ -563,6 +563,38 @@ require "google/cloud/storage"
|
|
563
563
|
storage = Google::Cloud::Storage.new retries: 10, timeout: 120
|
564
564
|
```
|
565
565
|
|
566
|
+
The library by default retries all API requests which are always idempotent on a
|
567
|
+
"transient" error.
|
568
|
+
|
569
|
+
For API requests which are idempotent only if the some conditions are satisfied
|
570
|
+
(For ex. a file has the same "generation"), the library retries only if the
|
571
|
+
condition is specified.
|
572
|
+
|
573
|
+
Rather than using this default behaviour, you may choose to disable the retries
|
574
|
+
on your own.
|
575
|
+
|
576
|
+
You can pass `retries` as `0` to disable retries for all operations regardless
|
577
|
+
of their idempotencies.
|
578
|
+
|
579
|
+
```ruby
|
580
|
+
require "google/cloud/storage"
|
581
|
+
|
582
|
+
storage = Google::Cloud::Storage.new retries: 0
|
583
|
+
```
|
584
|
+
|
585
|
+
You can also disable retries for a particular operation by passing `retries` as
|
586
|
+
`0` in the `options` field.
|
587
|
+
|
588
|
+
```ruby
|
589
|
+
require "google/cloud/storage"
|
590
|
+
|
591
|
+
storage = Google::Cloud::Storage.new
|
592
|
+
service = storage.service
|
593
|
+
service.get_bucket bucket_name, options: {retries: 0}
|
594
|
+
```
|
595
|
+
|
596
|
+
For those API requests which are never idempotent, the library passes retries=0 by default, suppressing any retries.
|
597
|
+
|
566
598
|
See the [Storage status and error
|
567
599
|
codes](https://cloud.google.com/storage/docs/json_api/v1/status-codes)
|
568
600
|
for a list of error conditions.
|
@@ -349,8 +349,8 @@ module Google
|
|
349
349
|
#
|
350
350
|
# bucket.acl.auth!
|
351
351
|
#
|
352
|
-
def auth!
|
353
|
-
update_predefined_acl! "authenticatedRead"
|
352
|
+
def auth! if_metageneration_match: nil
|
353
|
+
update_predefined_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
|
354
354
|
end
|
355
355
|
alias authenticatedRead! auth!
|
356
356
|
alias auth_read! auth!
|
@@ -370,8 +370,8 @@ module Google
|
|
370
370
|
#
|
371
371
|
# bucket.acl.private!
|
372
372
|
#
|
373
|
-
def private!
|
374
|
-
update_predefined_acl! "private"
|
373
|
+
def private! if_metageneration_match: nil
|
374
|
+
update_predefined_acl! "private", if_metageneration_match: if_metageneration_match
|
375
375
|
end
|
376
376
|
|
377
377
|
##
|
@@ -387,8 +387,8 @@ module Google
|
|
387
387
|
#
|
388
388
|
# bucket.acl.project_private!
|
389
389
|
#
|
390
|
-
def project_private!
|
391
|
-
update_predefined_acl! "projectPrivate"
|
390
|
+
def project_private! if_metageneration_match: nil
|
391
|
+
update_predefined_acl! "projectPrivate", if_metageneration_match: if_metageneration_match
|
392
392
|
end
|
393
393
|
alias projectPrivate! project_private!
|
394
394
|
|
@@ -405,8 +405,8 @@ module Google
|
|
405
405
|
#
|
406
406
|
# bucket.acl.public!
|
407
407
|
#
|
408
|
-
def public!
|
409
|
-
update_predefined_acl! "publicRead"
|
408
|
+
def public! if_metageneration_match: nil
|
409
|
+
update_predefined_acl! "publicRead", if_metageneration_match: if_metageneration_match
|
410
410
|
end
|
411
411
|
alias publicRead! public!
|
412
412
|
alias public_read! public!
|
@@ -423,8 +423,8 @@ module Google
|
|
423
423
|
#
|
424
424
|
# bucket.acl.public_write!
|
425
425
|
#
|
426
|
-
def public_write!
|
427
|
-
update_predefined_acl! "publicReadWrite"
|
426
|
+
def public_write! if_metageneration_match: nil
|
427
|
+
update_predefined_acl! "publicReadWrite", if_metageneration_match: if_metageneration_match
|
428
428
|
end
|
429
429
|
alias publicReadWrite! public_write!
|
430
430
|
|
@@ -437,9 +437,10 @@ module Google
|
|
437
437
|
self
|
438
438
|
end
|
439
439
|
|
440
|
-
def update_predefined_acl! acl_role
|
440
|
+
def update_predefined_acl! acl_role, if_metageneration_match: nil
|
441
441
|
@service.patch_bucket @bucket, predefined_acl: acl_role,
|
442
|
-
user_project: user_project
|
442
|
+
user_project: user_project,
|
443
|
+
if_metageneration_match: if_metageneration_match
|
443
444
|
clear!
|
444
445
|
end
|
445
446
|
|
@@ -714,8 +715,8 @@ module Google
|
|
714
715
|
#
|
715
716
|
# bucket.default_acl.auth!
|
716
717
|
#
|
717
|
-
def auth!
|
718
|
-
update_predefined_default_acl! "authenticatedRead"
|
718
|
+
def auth! if_metageneration_match: nil
|
719
|
+
update_predefined_default_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
|
719
720
|
end
|
720
721
|
alias authenticatedRead! auth!
|
721
722
|
alias auth_read! auth!
|
@@ -735,8 +736,8 @@ module Google
|
|
735
736
|
#
|
736
737
|
# bucket.default_acl.owner_full!
|
737
738
|
#
|
738
|
-
def owner_full!
|
739
|
-
update_predefined_default_acl! "bucketOwnerFullControl"
|
739
|
+
def owner_full! if_metageneration_match: nil
|
740
|
+
update_predefined_default_acl! "bucketOwnerFullControl", if_metageneration_match: if_metageneration_match
|
740
741
|
end
|
741
742
|
alias bucketOwnerFullControl! owner_full!
|
742
743
|
|
@@ -753,8 +754,8 @@ module Google
|
|
753
754
|
#
|
754
755
|
# bucket.default_acl.owner_read!
|
755
756
|
#
|
756
|
-
def owner_read!
|
757
|
-
update_predefined_default_acl! "bucketOwnerRead"
|
757
|
+
def owner_read! if_metageneration_match: nil
|
758
|
+
update_predefined_default_acl! "bucketOwnerRead", if_metageneration_match: if_metageneration_match
|
758
759
|
end
|
759
760
|
alias bucketOwnerRead! owner_read!
|
760
761
|
|
@@ -771,8 +772,8 @@ module Google
|
|
771
772
|
#
|
772
773
|
# bucket.default_acl.private!
|
773
774
|
#
|
774
|
-
def private!
|
775
|
-
update_predefined_default_acl! "private"
|
775
|
+
def private! if_metageneration_match: nil
|
776
|
+
update_predefined_default_acl! "private", if_metageneration_match: if_metageneration_match
|
776
777
|
end
|
777
778
|
|
778
779
|
##
|
@@ -788,8 +789,8 @@ module Google
|
|
788
789
|
#
|
789
790
|
# bucket.default_acl.project_private!
|
790
791
|
#
|
791
|
-
def project_private!
|
792
|
-
update_predefined_default_acl! "projectPrivate"
|
792
|
+
def project_private! if_metageneration_match: nil
|
793
|
+
update_predefined_default_acl! "projectPrivate", if_metageneration_match: if_metageneration_match
|
793
794
|
end
|
794
795
|
alias projectPrivate! project_private!
|
795
796
|
|
@@ -806,8 +807,8 @@ module Google
|
|
806
807
|
#
|
807
808
|
# bucket.default_acl.public!
|
808
809
|
#
|
809
|
-
def public!
|
810
|
-
update_predefined_default_acl! "publicRead"
|
810
|
+
def public! if_metageneration_match: nil
|
811
|
+
update_predefined_default_acl! "publicRead", if_metageneration_match: if_metageneration_match
|
811
812
|
end
|
812
813
|
alias publicRead! public!
|
813
814
|
alias public_read! public!
|
@@ -820,9 +821,10 @@ module Google
|
|
820
821
|
self
|
821
822
|
end
|
822
823
|
|
823
|
-
def update_predefined_default_acl! acl_role
|
824
|
+
def update_predefined_default_acl! acl_role, if_metageneration_match: nil
|
824
825
|
@service.patch_bucket @bucket, predefined_default_acl: acl_role,
|
825
|
-
user_project: user_project
|
826
|
+
user_project: user_project,
|
827
|
+
if_metageneration_match: if_metageneration_match
|
826
828
|
clear!
|
827
829
|
end
|
828
830
|
|
@@ -301,6 +301,20 @@ module Google
|
|
301
301
|
@gapi.location_type
|
302
302
|
end
|
303
303
|
|
304
|
+
##
|
305
|
+
# Returns the list of regional locations for custom dual-region buckets.
|
306
|
+
#
|
307
|
+
# @return [String, nil] Returns nil if the property has not been set before creation,
|
308
|
+
# if the bucket's resource has not been loaded from the server,
|
309
|
+
# or if the bucket is not a dual-regions bucket.
|
310
|
+
|
311
|
+
# @see https://cloud.google.com/storage/docs/json_api/v1/buckets and
|
312
|
+
# https://cloud.google.com/storage/docs/locations
|
313
|
+
#
|
314
|
+
def data_locations
|
315
|
+
@gapi.custom_placement_config&.data_locations
|
316
|
+
end
|
317
|
+
|
304
318
|
##
|
305
319
|
# The destination bucket name for the bucket's logs.
|
306
320
|
#
|
@@ -1156,9 +1170,9 @@ module Google
|
|
1156
1170
|
updater.check_for_mutable_cors!
|
1157
1171
|
updater.check_for_mutable_lifecycle!
|
1158
1172
|
return if updater.updates.empty?
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1173
|
+
update_gapi! updater.updates,
|
1174
|
+
if_metageneration_match: if_metageneration_match,
|
1175
|
+
if_metageneration_not_match: if_metageneration_not_match
|
1162
1176
|
end
|
1163
1177
|
|
1164
1178
|
##
|
@@ -2891,6 +2905,26 @@ module Google
|
|
2891
2905
|
self
|
2892
2906
|
end
|
2893
2907
|
|
2908
|
+
def update_gapi! attributes,
|
2909
|
+
if_metageneration_match: nil,
|
2910
|
+
if_metageneration_not_match: nil
|
2911
|
+
attributes = Array(attributes)
|
2912
|
+
attributes.flatten!
|
2913
|
+
return if attributes.empty?
|
2914
|
+
ensure_service!
|
2915
|
+
update_args = Hash[attributes.map do |attr|
|
2916
|
+
[attr, @gapi.send(attr)]
|
2917
|
+
end]
|
2918
|
+
update_gapi = API::Bucket.new(**update_args)
|
2919
|
+
@gapi = service.update_bucket name,
|
2920
|
+
update_gapi,
|
2921
|
+
if_metageneration_match: if_metageneration_match,
|
2922
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
2923
|
+
user_project: user_project
|
2924
|
+
@lazy = nil
|
2925
|
+
self
|
2926
|
+
end
|
2927
|
+
|
2894
2928
|
##
|
2895
2929
|
# Raise an error if the file is not found.
|
2896
2930
|
def ensure_io_or_file_exists! file
|
@@ -290,9 +290,9 @@ module Google
|
|
290
290
|
# access, and allUsers get READER access.
|
291
291
|
# @param [String] location The location of the bucket. Optional.
|
292
292
|
# If not passed, the default location, 'US', will be used.
|
293
|
-
# If specifying a dual-region location, the
|
294
|
-
#
|
295
|
-
# [Storage
|
293
|
+
# If specifying a dual-region location, the `customPlacementConfig`
|
294
|
+
# property should be set in conjunction. See:
|
295
|
+
# [Storage Locations](https://cloud.google.com/storage/docs/locations).
|
296
296
|
# @param [String] logging_bucket The destination bucket for the bucket's
|
297
297
|
# logs. For more information, see [Access
|
298
298
|
# Logs](https://cloud.google.com/storage/docs/access-logs).
|
@@ -367,6 +367,7 @@ module Google
|
|
367
367
|
acl: nil,
|
368
368
|
default_acl: nil,
|
369
369
|
location: nil,
|
370
|
+
custom_placement_config: nil,
|
370
371
|
storage_class: nil,
|
371
372
|
logging_bucket: nil,
|
372
373
|
logging_prefix: nil,
|
@@ -377,7 +378,8 @@ module Google
|
|
377
378
|
user_project: nil
|
378
379
|
params = {
|
379
380
|
name: bucket_name,
|
380
|
-
location: location
|
381
|
+
location: location,
|
382
|
+
custom_placement_config: custom_placement_config
|
381
383
|
}.delete_if { |_, v| v.nil? }
|
382
384
|
new_bucket = Google::Apis::StorageV1::Bucket.new(**params)
|
383
385
|
storage_class = storage_class_for storage_class
|
@@ -64,6 +64,7 @@ module Google
|
|
64
64
|
@service.request_options.base_interval = base_interval if base_interval
|
65
65
|
@service.request_options.max_interval = max_interval if max_interval
|
66
66
|
@service.request_options.multiplier = multiplier if multiplier
|
67
|
+
@service.request_options.add_invocation_id_header = true
|
67
68
|
@service.authorization = @credentials.client if @credentials
|
68
69
|
@service.root_url = host if host
|
69
70
|
end
|
@@ -81,11 +82,11 @@ module Google
|
|
81
82
|
|
82
83
|
##
|
83
84
|
# Retrieves a list of buckets for the given project.
|
84
|
-
def list_buckets prefix: nil, token: nil, max: nil, user_project: nil
|
85
|
+
def list_buckets prefix: nil, token: nil, max: nil, user_project: nil, options: {}
|
85
86
|
execute do
|
86
87
|
service.list_buckets \
|
87
88
|
@project, prefix: prefix, page_token: token, max_results: max,
|
88
|
-
user_project: user_project(user_project)
|
89
|
+
user_project: user_project(user_project), options: options
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
@@ -95,12 +96,14 @@ module Google
|
|
95
96
|
def get_bucket bucket_name,
|
96
97
|
if_metageneration_match: nil,
|
97
98
|
if_metageneration_not_match: nil,
|
98
|
-
user_project: nil
|
99
|
+
user_project: nil,
|
100
|
+
options: {}
|
99
101
|
execute do
|
100
102
|
service.get_bucket bucket_name,
|
101
103
|
if_metageneration_match: if_metageneration_match,
|
102
104
|
if_metageneration_not_match: if_metageneration_not_match,
|
103
|
-
user_project: user_project(user_project)
|
105
|
+
user_project: user_project(user_project),
|
106
|
+
options: options
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
@@ -108,13 +111,14 @@ module Google
|
|
108
111
|
# Creates a new bucket.
|
109
112
|
# Returns Google::Apis::StorageV1::Bucket.
|
110
113
|
def insert_bucket bucket_gapi, acl: nil, default_acl: nil,
|
111
|
-
user_project: nil
|
114
|
+
user_project: nil, options: {}
|
112
115
|
execute do
|
113
116
|
service.insert_bucket \
|
114
117
|
@project, bucket_gapi,
|
115
118
|
predefined_acl: acl,
|
116
119
|
predefined_default_object_acl: default_acl,
|
117
|
-
user_project: user_project(user_project)
|
120
|
+
user_project: user_project(user_project),
|
121
|
+
options: options
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
@@ -126,11 +130,17 @@ module Google
|
|
126
130
|
predefined_default_acl: nil,
|
127
131
|
if_metageneration_match: nil,
|
128
132
|
if_metageneration_not_match: nil,
|
129
|
-
user_project: nil
|
133
|
+
user_project: nil,
|
134
|
+
options: {}
|
130
135
|
bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
|
131
136
|
bucket_gapi.acl = [] if predefined_acl
|
132
137
|
bucket_gapi.default_object_acl = [] if predefined_default_acl
|
133
138
|
|
139
|
+
if options[:retries].nil?
|
140
|
+
is_idempotent = retry? if_metageneration_match: if_metageneration_match
|
141
|
+
options = is_idempotent ? {} : { retries: 0 }
|
142
|
+
end
|
143
|
+
|
134
144
|
execute do
|
135
145
|
service.patch_bucket bucket_name,
|
136
146
|
bucket_gapi,
|
@@ -138,7 +148,8 @@ module Google
|
|
138
148
|
predefined_default_object_acl: predefined_default_acl,
|
139
149
|
if_metageneration_match: if_metageneration_match,
|
140
150
|
if_metageneration_not_match: if_metageneration_not_match,
|
141
|
-
user_project: user_project(user_project)
|
151
|
+
user_project: user_project(user_project),
|
152
|
+
options: options
|
142
153
|
end
|
143
154
|
end
|
144
155
|
|
@@ -147,119 +158,144 @@ module Google
|
|
147
158
|
def delete_bucket bucket_name,
|
148
159
|
if_metageneration_match: nil,
|
149
160
|
if_metageneration_not_match: nil,
|
150
|
-
user_project: nil
|
161
|
+
user_project: nil,
|
162
|
+
options: {}
|
151
163
|
execute do
|
152
164
|
service.delete_bucket bucket_name,
|
153
165
|
if_metageneration_match: if_metageneration_match,
|
154
166
|
if_metageneration_not_match: if_metageneration_not_match,
|
155
|
-
user_project: user_project(user_project)
|
167
|
+
user_project: user_project(user_project),
|
168
|
+
options: options
|
156
169
|
end
|
157
170
|
end
|
158
171
|
|
159
172
|
##
|
160
173
|
# Locks retention policy on a bucket.
|
161
174
|
def lock_bucket_retention_policy bucket_name, metageneration,
|
162
|
-
user_project: nil
|
175
|
+
user_project: nil,
|
176
|
+
options: {}
|
163
177
|
execute do
|
164
178
|
service.lock_bucket_retention_policy \
|
165
179
|
bucket_name, metageneration,
|
166
|
-
user_project: user_project(user_project)
|
180
|
+
user_project: user_project(user_project),
|
181
|
+
options: options
|
167
182
|
end
|
168
183
|
end
|
169
184
|
|
170
185
|
##
|
171
186
|
# Retrieves a list of ACLs for the given bucket.
|
172
|
-
def list_bucket_acls bucket_name, user_project: nil
|
187
|
+
def list_bucket_acls bucket_name, user_project: nil, options: {}
|
173
188
|
execute do
|
174
189
|
service.list_bucket_access_controls \
|
175
|
-
bucket_name, user_project: user_project(user_project)
|
190
|
+
bucket_name, user_project: user_project(user_project),
|
191
|
+
options: options
|
176
192
|
end
|
177
193
|
end
|
178
194
|
|
179
195
|
##
|
180
196
|
# Creates a new bucket ACL.
|
181
|
-
def insert_bucket_acl bucket_name, entity, role, user_project: nil
|
197
|
+
def insert_bucket_acl bucket_name, entity, role, user_project: nil, options: {}
|
182
198
|
params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
|
183
199
|
new_acl = Google::Apis::StorageV1::BucketAccessControl.new(**params)
|
200
|
+
if options[:retries].nil?
|
201
|
+
options = options.merge({ retries: 0 })
|
202
|
+
end
|
184
203
|
execute do
|
185
204
|
service.insert_bucket_access_control \
|
186
|
-
bucket_name, new_acl, user_project: user_project(user_project)
|
205
|
+
bucket_name, new_acl, user_project: user_project(user_project),
|
206
|
+
options: options
|
187
207
|
end
|
188
208
|
end
|
189
209
|
|
190
210
|
##
|
191
211
|
# Permanently deletes a bucket ACL.
|
192
|
-
def delete_bucket_acl bucket_name, entity, user_project: nil
|
212
|
+
def delete_bucket_acl bucket_name, entity, user_project: nil, options: {}
|
213
|
+
if options[:retries].nil?
|
214
|
+
options = options.merge({ retries: 0 })
|
215
|
+
end
|
193
216
|
execute do
|
194
217
|
service.delete_bucket_access_control \
|
195
|
-
bucket_name, entity, user_project: user_project(user_project)
|
218
|
+
bucket_name, entity, user_project: user_project(user_project),
|
219
|
+
options: options
|
196
220
|
end
|
197
221
|
end
|
198
222
|
|
199
223
|
##
|
200
224
|
# Retrieves a list of default ACLs for the given bucket.
|
201
|
-
def list_default_acls bucket_name, user_project: nil
|
225
|
+
def list_default_acls bucket_name, user_project: nil, options: {}
|
202
226
|
execute do
|
203
227
|
service.list_default_object_access_controls \
|
204
|
-
bucket_name, user_project: user_project(user_project)
|
228
|
+
bucket_name, user_project: user_project(user_project),
|
229
|
+
options: options
|
205
230
|
end
|
206
231
|
end
|
207
232
|
|
208
233
|
##
|
209
234
|
# Creates a new default ACL.
|
210
|
-
def insert_default_acl bucket_name, entity, role, user_project: nil
|
235
|
+
def insert_default_acl bucket_name, entity, role, user_project: nil, options: {}
|
236
|
+
if options[:retries].nil?
|
237
|
+
options = options.merge({ retries: 0 })
|
238
|
+
end
|
211
239
|
param = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
|
212
240
|
new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**param)
|
213
241
|
execute do
|
214
242
|
service.insert_default_object_access_control \
|
215
|
-
bucket_name, new_acl, user_project: user_project(user_project)
|
243
|
+
bucket_name, new_acl, user_project: user_project(user_project),
|
244
|
+
options: options
|
216
245
|
end
|
217
246
|
end
|
218
247
|
|
219
248
|
##
|
220
249
|
# Permanently deletes a default ACL.
|
221
|
-
def delete_default_acl bucket_name, entity, user_project: nil
|
250
|
+
def delete_default_acl bucket_name, entity, user_project: nil, options: {}
|
251
|
+
if options[:retries].nil?
|
252
|
+
options = options.merge({ retries: 0 })
|
253
|
+
end
|
222
254
|
execute do
|
223
255
|
service.delete_default_object_access_control \
|
224
|
-
bucket_name, entity, user_project: user_project(user_project)
|
256
|
+
bucket_name, entity, user_project: user_project(user_project),
|
257
|
+
options: options
|
225
258
|
end
|
226
259
|
end
|
227
260
|
|
228
261
|
##
|
229
262
|
# Returns Google::Apis::StorageV1::Policy
|
230
|
-
def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil
|
263
|
+
def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil,
|
264
|
+
options: {}
|
231
265
|
# get_bucket_iam_policy(bucket, fields: nil, quota_user: nil,
|
232
266
|
# user_ip: nil, options: nil)
|
233
267
|
execute do
|
234
268
|
service.get_bucket_iam_policy bucket_name, options_requested_policy_version: requested_policy_version,
|
235
|
-
user_project: user_project(user_project)
|
269
|
+
user_project: user_project(user_project), options: options
|
236
270
|
end
|
237
271
|
end
|
238
272
|
|
239
273
|
##
|
240
274
|
# Returns Google::Apis::StorageV1::Policy
|
241
|
-
def set_bucket_policy bucket_name, new_policy, user_project: nil
|
275
|
+
def set_bucket_policy bucket_name, new_policy, user_project: nil, options: {}
|
242
276
|
execute do
|
243
277
|
service.set_bucket_iam_policy \
|
244
|
-
bucket_name, new_policy, user_project: user_project(user_project)
|
278
|
+
bucket_name, new_policy, user_project: user_project(user_project), options: options
|
245
279
|
end
|
246
280
|
end
|
247
281
|
|
248
282
|
##
|
249
283
|
# Returns Google::Apis::StorageV1::TestIamPermissionsResponse
|
250
|
-
def test_bucket_permissions bucket_name, permissions, user_project: nil
|
284
|
+
def test_bucket_permissions bucket_name, permissions, user_project: nil, options: {}
|
251
285
|
execute do
|
252
286
|
service.test_bucket_iam_permissions \
|
253
|
-
bucket_name, permissions, user_project: user_project(user_project)
|
287
|
+
bucket_name, permissions, user_project: user_project(user_project),
|
288
|
+
options: options
|
254
289
|
end
|
255
290
|
end
|
256
291
|
|
257
292
|
##
|
258
293
|
# Retrieves a list of Pub/Sub notification subscriptions for a bucket.
|
259
|
-
def list_notifications bucket_name, user_project: nil
|
294
|
+
def list_notifications bucket_name, user_project: nil, options: {}
|
260
295
|
execute do
|
261
296
|
service.list_notifications bucket_name,
|
262
|
-
user_project: user_project(user_project)
|
297
|
+
user_project: user_project(user_project),
|
298
|
+
options: options
|
263
299
|
end
|
264
300
|
end
|
265
301
|
|
@@ -267,7 +303,7 @@ module Google
|
|
267
303
|
# Creates a new Pub/Sub notification subscription for a bucket.
|
268
304
|
def insert_notification bucket_name, topic_name, custom_attrs: nil,
|
269
305
|
event_types: nil, prefix: nil, payload: nil,
|
270
|
-
user_project: nil
|
306
|
+
user_project: nil, options: {}
|
271
307
|
params =
|
272
308
|
{ custom_attributes: custom_attrs,
|
273
309
|
event_types: event_types(event_types),
|
@@ -276,41 +312,50 @@ module Google
|
|
276
312
|
topic: topic_path(topic_name) }.delete_if { |_k, v| v.nil? }
|
277
313
|
new_notification = Google::Apis::StorageV1::Notification.new(**params)
|
278
314
|
|
315
|
+
if options[:retries].nil?
|
316
|
+
options = options.merge({ retries: 0 })
|
317
|
+
end
|
318
|
+
|
279
319
|
execute do
|
280
320
|
service.insert_notification \
|
281
321
|
bucket_name, new_notification,
|
282
|
-
user_project: user_project(user_project)
|
322
|
+
user_project: user_project(user_project),
|
323
|
+
options: options
|
283
324
|
end
|
284
325
|
end
|
285
326
|
|
286
327
|
##
|
287
328
|
# Retrieves a Pub/Sub notification subscription for a bucket.
|
288
|
-
def get_notification bucket_name, notification_id, user_project: nil
|
329
|
+
def get_notification bucket_name, notification_id, user_project: nil, options: {}
|
289
330
|
execute do
|
290
331
|
service.get_notification bucket_name, notification_id,
|
291
|
-
user_project: user_project(user_project)
|
332
|
+
user_project: user_project(user_project),
|
333
|
+
options: options
|
292
334
|
end
|
293
335
|
end
|
294
336
|
|
295
337
|
##
|
296
338
|
# Deletes a new Pub/Sub notification subscription for a bucket.
|
297
|
-
def delete_notification bucket_name, notification_id, user_project: nil
|
339
|
+
def delete_notification bucket_name, notification_id, user_project: nil, options: {}
|
298
340
|
execute do
|
299
341
|
service.delete_notification bucket_name, notification_id,
|
300
|
-
user_project: user_project(user_project)
|
342
|
+
user_project: user_project(user_project),
|
343
|
+
options: options
|
301
344
|
end
|
302
345
|
end
|
303
346
|
|
304
347
|
##
|
305
348
|
# Retrieves a list of files matching the criteria.
|
306
349
|
def list_files bucket_name, delimiter: nil, max: nil, token: nil,
|
307
|
-
prefix: nil, versions: nil, user_project: nil
|
350
|
+
prefix: nil, versions: nil, user_project: nil,
|
351
|
+
options: {}
|
308
352
|
execute do
|
309
353
|
service.list_objects \
|
310
354
|
bucket_name, delimiter: delimiter, max_results: max,
|
311
355
|
page_token: token, prefix: prefix,
|
312
356
|
versions: versions,
|
313
|
-
user_project: user_project(user_project)
|
357
|
+
user_project: user_project(user_project),
|
358
|
+
options: options
|
314
359
|
end
|
315
360
|
end
|
316
361
|
|
@@ -338,7 +383,8 @@ module Google
|
|
338
383
|
if_generation_not_match: nil,
|
339
384
|
if_metageneration_match: nil,
|
340
385
|
if_metageneration_not_match: nil,
|
341
|
-
user_project: nil
|
386
|
+
user_project: nil,
|
387
|
+
options: {}
|
342
388
|
params = {
|
343
389
|
cache_control: cache_control,
|
344
390
|
content_type: content_type,
|
@@ -356,6 +402,13 @@ module Google
|
|
356
402
|
file_obj = Google::Apis::StorageV1::Object.new(**params)
|
357
403
|
content_type ||= mime_type_for(path || Pathname(source).to_path)
|
358
404
|
|
405
|
+
if options[:retries].nil?
|
406
|
+
is_idempotent = retry? if_generation_match: if_generation_match
|
407
|
+
options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
|
408
|
+
else
|
409
|
+
options = key_options(key).merge options
|
410
|
+
end
|
411
|
+
|
359
412
|
execute do
|
360
413
|
service.insert_object bucket_name,
|
361
414
|
file_obj,
|
@@ -370,7 +423,7 @@ module Google
|
|
370
423
|
if_metageneration_not_match: if_metageneration_not_match,
|
371
424
|
kms_key_name: kms_key,
|
372
425
|
user_project: user_project(user_project),
|
373
|
-
options:
|
426
|
+
options: options
|
374
427
|
end
|
375
428
|
end
|
376
429
|
|
@@ -384,7 +437,8 @@ module Google
|
|
384
437
|
if_metageneration_match: nil,
|
385
438
|
if_metageneration_not_match: nil,
|
386
439
|
key: nil,
|
387
|
-
user_project: nil
|
440
|
+
user_project: nil,
|
441
|
+
options: {}
|
388
442
|
execute do
|
389
443
|
service.get_object \
|
390
444
|
bucket_name, file_path,
|
@@ -394,7 +448,7 @@ module Google
|
|
394
448
|
if_metageneration_match: if_metageneration_match,
|
395
449
|
if_metageneration_not_match: if_metageneration_not_match,
|
396
450
|
user_project: user_project(user_project),
|
397
|
-
options: key_options(key)
|
451
|
+
options: key_options(key).merge(options)
|
398
452
|
end
|
399
453
|
end
|
400
454
|
|
@@ -419,8 +473,17 @@ module Google
|
|
419
473
|
if_source_metageneration_match: nil,
|
420
474
|
if_source_metageneration_not_match: nil,
|
421
475
|
token: nil,
|
422
|
-
user_project: nil
|
476
|
+
user_project: nil,
|
477
|
+
options: {}
|
423
478
|
key_options = rewrite_key_options source_key, destination_key
|
479
|
+
|
480
|
+
if options[:retries].nil?
|
481
|
+
is_idempotent = retry? if_generation_match: if_generation_match
|
482
|
+
options = is_idempotent ? key_options : key_options.merge(retries: 0)
|
483
|
+
else
|
484
|
+
options = key_options.merge options
|
485
|
+
end
|
486
|
+
|
424
487
|
execute do
|
425
488
|
service.rewrite_object source_bucket_name,
|
426
489
|
source_file_path,
|
@@ -440,7 +503,7 @@ module Google
|
|
440
503
|
if_source_metageneration_not_match: if_source_metageneration_not_match,
|
441
504
|
rewrite_token: token,
|
442
505
|
user_project: user_project(user_project),
|
443
|
-
options:
|
506
|
+
options: options
|
444
507
|
end
|
445
508
|
end
|
446
509
|
|
@@ -455,12 +518,20 @@ module Google
|
|
455
518
|
if_source_generation_match: nil,
|
456
519
|
if_generation_match: nil,
|
457
520
|
if_metageneration_match: nil,
|
458
|
-
user_project: nil
|
521
|
+
user_project: nil,
|
522
|
+
options: {}
|
459
523
|
|
460
524
|
source_objects = compose_file_source_objects source_files, if_source_generation_match
|
461
525
|
compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
|
462
526
|
destination: destination_gapi
|
463
527
|
|
528
|
+
if options[:retries].nil?
|
529
|
+
is_idempotent = retry? if_generation_match: if_generation_match
|
530
|
+
options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
|
531
|
+
else
|
532
|
+
options = key_options.merge options
|
533
|
+
end
|
534
|
+
|
464
535
|
execute do
|
465
536
|
service.compose_object bucket_name,
|
466
537
|
destination_path,
|
@@ -469,7 +540,7 @@ module Google
|
|
469
540
|
if_generation_match: if_generation_match,
|
470
541
|
if_metageneration_match: if_metageneration_match,
|
471
542
|
user_project: user_project(user_project),
|
472
|
-
options:
|
543
|
+
options: options
|
473
544
|
end
|
474
545
|
end
|
475
546
|
|
@@ -483,12 +554,12 @@ module Google
|
|
483
554
|
# Apis::StorageV1::StorageService and Apis::Core::DownloadCommand at
|
484
555
|
# the end of this file.
|
485
556
|
def download_file bucket_name, file_path, target_path, generation: nil,
|
486
|
-
key: nil, range: nil, user_project: nil
|
487
|
-
options = key_options
|
557
|
+
key: nil, range: nil, user_project: nil, options: {}
|
558
|
+
options = key_options(key).merge(options)
|
488
559
|
options = range_header options, range
|
489
560
|
|
490
561
|
execute do
|
491
|
-
service.
|
562
|
+
service.get_object \
|
492
563
|
bucket_name, file_path,
|
493
564
|
download_dest: target_path, generation: generation,
|
494
565
|
user_project: user_project(user_project),
|
@@ -507,8 +578,15 @@ module Google
|
|
507
578
|
if_metageneration_match: nil,
|
508
579
|
if_metageneration_not_match: nil,
|
509
580
|
predefined_acl: nil,
|
510
|
-
user_project: nil
|
581
|
+
user_project: nil,
|
582
|
+
options: {}
|
511
583
|
file_gapi ||= Google::Apis::StorageV1::Object.new
|
584
|
+
|
585
|
+
if options[:retries].nil?
|
586
|
+
is_idempotent = retry? if_metageneration_match: if_metageneration_match
|
587
|
+
options = is_idempotent ? {} : { retries: 0 }
|
588
|
+
end
|
589
|
+
|
512
590
|
execute do
|
513
591
|
service.patch_object bucket_name,
|
514
592
|
file_path,
|
@@ -519,7 +597,8 @@ module Google
|
|
519
597
|
if_metageneration_match: if_metageneration_match,
|
520
598
|
if_metageneration_not_match: if_metageneration_not_match,
|
521
599
|
predefined_acl: predefined_acl,
|
522
|
-
user_project: user_project(user_project)
|
600
|
+
user_project: user_project(user_project),
|
601
|
+
options: options
|
523
602
|
end
|
524
603
|
end
|
525
604
|
|
@@ -532,7 +611,14 @@ module Google
|
|
532
611
|
if_generation_not_match: nil,
|
533
612
|
if_metageneration_match: nil,
|
534
613
|
if_metageneration_not_match: nil,
|
535
|
-
user_project: nil
|
614
|
+
user_project: nil,
|
615
|
+
options: {}
|
616
|
+
|
617
|
+
if options[:retries].nil?
|
618
|
+
is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
|
619
|
+
options = is_idempotent ? {} : { retries: 0 }
|
620
|
+
end
|
621
|
+
|
536
622
|
execute do
|
537
623
|
service.delete_object bucket_name, file_path,
|
538
624
|
generation: generation,
|
@@ -540,40 +626,51 @@ module Google
|
|
540
626
|
if_generation_not_match: if_generation_not_match,
|
541
627
|
if_metageneration_match: if_metageneration_match,
|
542
628
|
if_metageneration_not_match: if_metageneration_not_match,
|
543
|
-
user_project: user_project(user_project)
|
629
|
+
user_project: user_project(user_project),
|
630
|
+
options: options
|
544
631
|
end
|
545
632
|
end
|
546
633
|
|
547
634
|
##
|
548
635
|
# Retrieves a list of ACLs for the given file.
|
549
|
-
def list_file_acls bucket_name, file_name, user_project: nil
|
636
|
+
def list_file_acls bucket_name, file_name, user_project: nil, options: {}
|
550
637
|
execute do
|
551
638
|
service.list_object_access_controls \
|
552
|
-
bucket_name, file_name, user_project: user_project(user_project)
|
639
|
+
bucket_name, file_name, user_project: user_project(user_project),
|
640
|
+
options: options
|
553
641
|
end
|
554
642
|
end
|
555
643
|
|
556
644
|
##
|
557
645
|
# Creates a new file ACL.
|
558
646
|
def insert_file_acl bucket_name, file_name, entity, role,
|
559
|
-
generation: nil, user_project: nil
|
647
|
+
generation: nil, user_project: nil,
|
648
|
+
options: {}
|
649
|
+
if options[:retries].nil?
|
650
|
+
options = options.merge({ retries: 0 })
|
651
|
+
end
|
560
652
|
params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
|
561
653
|
new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**params)
|
562
654
|
execute do
|
563
655
|
service.insert_object_access_control \
|
564
656
|
bucket_name, file_name, new_acl,
|
565
|
-
generation: generation, user_project: user_project(user_project)
|
657
|
+
generation: generation, user_project: user_project(user_project),
|
658
|
+
options: options
|
566
659
|
end
|
567
660
|
end
|
568
661
|
|
569
662
|
##
|
570
663
|
# Permanently deletes a file ACL.
|
571
664
|
def delete_file_acl bucket_name, file_name, entity, generation: nil,
|
572
|
-
user_project: nil
|
665
|
+
user_project: nil, options: {}
|
666
|
+
if options[:retries].nil?
|
667
|
+
options = options.merge({ retries: 0 })
|
668
|
+
end
|
573
669
|
execute do
|
574
670
|
service.delete_object_access_control \
|
575
671
|
bucket_name, file_name, entity,
|
576
|
-
generation: generation, user_project: user_project(user_project)
|
672
|
+
generation: generation, user_project: user_project(user_project),
|
673
|
+
options: options
|
577
674
|
end
|
578
675
|
end
|
579
676
|
|
@@ -581,32 +678,42 @@ module Google
|
|
581
678
|
# Creates a new HMAC key for the specified service account.
|
582
679
|
# Returns Google::Apis::StorageV1::HmacKey.
|
583
680
|
def create_hmac_key service_account_email, project_id: nil,
|
584
|
-
user_project: nil
|
681
|
+
user_project: nil, options: {}
|
682
|
+
|
683
|
+
if options[:retries].nil?
|
684
|
+
options = options.merge({ retries: 0 })
|
685
|
+
end
|
686
|
+
|
585
687
|
execute do
|
586
688
|
service.create_project_hmac_key \
|
587
689
|
(project_id || @project), service_account_email,
|
588
|
-
user_project: user_project(user_project)
|
690
|
+
user_project: user_project(user_project),
|
691
|
+
options: options
|
589
692
|
end
|
590
693
|
end
|
591
694
|
|
592
695
|
##
|
593
696
|
# Deletes an HMAC key. Key must be in the INACTIVE state.
|
594
|
-
def delete_hmac_key access_id, project_id: nil, user_project: nil
|
697
|
+
def delete_hmac_key access_id, project_id: nil, user_project: nil,
|
698
|
+
options: {}
|
595
699
|
execute do
|
596
700
|
service.delete_project_hmac_key \
|
597
701
|
(project_id || @project), access_id,
|
598
|
-
user_project: user_project(user_project)
|
702
|
+
user_project: user_project(user_project),
|
703
|
+
options: options
|
599
704
|
end
|
600
705
|
end
|
601
706
|
|
602
707
|
##
|
603
708
|
# Retrieves an HMAC key's metadata.
|
604
709
|
# Returns Google::Apis::StorageV1::HmacKeyMetadata.
|
605
|
-
def get_hmac_key access_id, project_id: nil, user_project: nil
|
710
|
+
def get_hmac_key access_id, project_id: nil, user_project: nil,
|
711
|
+
options: {}
|
606
712
|
execute do
|
607
713
|
service.get_project_hmac_key \
|
608
714
|
(project_id || @project), access_id,
|
609
|
-
user_project: user_project(user_project)
|
715
|
+
user_project: user_project(user_project),
|
716
|
+
options: options
|
610
717
|
end
|
611
718
|
end
|
612
719
|
|
@@ -615,14 +722,15 @@ module Google
|
|
615
722
|
# Returns Google::Apis::StorageV1::HmacKeysMetadata.
|
616
723
|
def list_hmac_keys max: nil, token: nil, service_account_email: nil,
|
617
724
|
project_id: nil, show_deleted_keys: nil,
|
618
|
-
user_project: nil
|
725
|
+
user_project: nil, options: {}
|
619
726
|
execute do
|
620
727
|
service.list_project_hmac_keys \
|
621
728
|
(project_id || @project),
|
622
729
|
max_results: max, page_token: token,
|
623
730
|
service_account_email: service_account_email,
|
624
731
|
show_deleted_keys: show_deleted_keys,
|
625
|
-
user_project: user_project(user_project)
|
732
|
+
user_project: user_project(user_project),
|
733
|
+
options: options
|
626
734
|
end
|
627
735
|
end
|
628
736
|
|
@@ -631,11 +739,44 @@ module Google
|
|
631
739
|
# for valid states.
|
632
740
|
# Returns Google::Apis::StorageV1::HmacKeyMetadata.
|
633
741
|
def update_hmac_key access_id, hmac_key_metadata_object,
|
634
|
-
project_id: nil, user_project: nil
|
742
|
+
project_id: nil, user_project: nil,
|
743
|
+
options: {}
|
635
744
|
execute do
|
636
745
|
service.update_project_hmac_key \
|
637
746
|
(project_id || @project), access_id, hmac_key_metadata_object,
|
638
|
-
user_project: user_project(user_project)
|
747
|
+
user_project: user_project(user_project),
|
748
|
+
options: options
|
749
|
+
end
|
750
|
+
end
|
751
|
+
|
752
|
+
##
|
753
|
+
# Updates a bucket, including its ACL metadata.
|
754
|
+
def update_bucket bucket_name,
|
755
|
+
bucket_gapi = nil,
|
756
|
+
predefined_acl: nil,
|
757
|
+
predefined_default_acl: nil,
|
758
|
+
if_metageneration_match: nil,
|
759
|
+
if_metageneration_not_match: nil,
|
760
|
+
user_project: nil,
|
761
|
+
options: {}
|
762
|
+
bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
|
763
|
+
bucket_gapi.acl = [] if predefined_acl
|
764
|
+
bucket_gapi.default_object_acl = [] if predefined_default_acl
|
765
|
+
|
766
|
+
if options[:retries].nil?
|
767
|
+
is_idempotent = retry? if_metageneration_match: if_metageneration_match
|
768
|
+
options = is_idempotent ? {} : { retries: 0 }
|
769
|
+
end
|
770
|
+
|
771
|
+
execute do
|
772
|
+
service.update_bucket bucket_name,
|
773
|
+
bucket_gapi,
|
774
|
+
predefined_acl: predefined_acl,
|
775
|
+
predefined_default_object_acl: predefined_default_acl,
|
776
|
+
if_metageneration_match: if_metageneration_match,
|
777
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
778
|
+
user_project: user_project(user_project),
|
779
|
+
options: options
|
639
780
|
end
|
640
781
|
end
|
641
782
|
|
@@ -771,163 +912,11 @@ module Google
|
|
771
912
|
rescue Google::Apis::Error => e
|
772
913
|
raise Google::Cloud::Error.from_error(e)
|
773
914
|
end
|
774
|
-
end
|
775
|
-
end
|
776
|
-
end
|
777
|
-
|
778
|
-
# rubocop:disable all
|
779
|
-
|
780
|
-
# @private
|
781
|
-
#
|
782
|
-
# IMPORTANT: These monkey-patches of Apis::StorageV1::StorageService and
|
783
|
-
# Apis::Core::DownloadCommand must be verified and updated (if needed) for
|
784
|
-
# every upgrade of google-api-client.
|
785
|
-
#
|
786
|
-
# The purpose of these modifications is to provide access to response headers
|
787
|
-
# (in particular, the Content-Encoding header) for the #download_file method,
|
788
|
-
# above. If google-api-client is modified to expose response headers to its
|
789
|
-
# clients, this code should be removed, and #download_file updated to use that
|
790
|
-
# solution instead.
|
791
|
-
#
|
792
|
-
module Apis
|
793
|
-
# @private
|
794
|
-
module StorageV1
|
795
|
-
# @private
|
796
|
-
class StorageService
|
797
|
-
# Returns a two-element array containing:
|
798
|
-
# * The `result` that is the usual return type of #get_object.
|
799
|
-
# * The `http_resp` from DownloadCommand#execute_once.
|
800
|
-
def get_object_with_response(bucket, object, generation: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, projection: nil, user_project: nil, fields: nil, quota_user: nil, user_ip: nil, download_dest: nil, options: nil, &block)
|
801
|
-
if download_dest.nil?
|
802
|
-
command = make_simple_command(:get, 'b/{bucket}/o/{object}', options)
|
803
|
-
else
|
804
|
-
command = make_download_command(:get, 'b/{bucket}/o/{object}', options)
|
805
|
-
command.download_dest = download_dest
|
806
|
-
end
|
807
|
-
command.response_representation = Google::Apis::StorageV1::Object::Representation
|
808
|
-
command.response_class = Google::Apis::StorageV1::Object
|
809
|
-
command.params['bucket'] = bucket unless bucket.nil?
|
810
|
-
command.params['object'] = object unless object.nil?
|
811
|
-
command.query['generation'] = generation unless generation.nil?
|
812
|
-
command.query['ifGenerationMatch'] = if_generation_match unless if_generation_match.nil?
|
813
|
-
command.query['ifGenerationNotMatch'] = if_generation_not_match unless if_generation_not_match.nil?
|
814
|
-
command.query['ifMetagenerationMatch'] = if_metageneration_match unless if_metageneration_match.nil?
|
815
|
-
command.query['ifMetagenerationNotMatch'] = if_metageneration_not_match unless if_metageneration_not_match.nil?
|
816
|
-
command.query['projection'] = projection unless projection.nil?
|
817
|
-
command.query['userProject'] = user_project unless user_project.nil?
|
818
|
-
command.query['fields'] = fields unless fields.nil?
|
819
|
-
command.query['quotaUser'] = quota_user unless quota_user.nil?
|
820
|
-
command.query['userIp'] = user_ip unless user_ip.nil?
|
821
|
-
execute_or_queue_command_with_response(command, &block)
|
822
|
-
end
|
823
|
-
|
824
|
-
# Returns a two-element array containing:
|
825
|
-
# * The `result` that is the usual return type of #execute_or_queue_command.
|
826
|
-
# * The `http_resp` from DownloadCommand#execute_once.
|
827
|
-
def execute_or_queue_command_with_response(command, &callback)
|
828
|
-
batch_command = current_batch
|
829
|
-
if batch_command
|
830
|
-
raise "Can not combine services in a batch" if Thread.current[:google_api_batch_service] != self
|
831
|
-
batch_command.add(command, &callback)
|
832
|
-
nil
|
833
|
-
else
|
834
|
-
command.execute_with_response(client, &callback)
|
835
|
-
end
|
836
|
-
end
|
837
|
-
end
|
838
|
-
end
|
839
|
-
# @private
|
840
|
-
module Core
|
841
|
-
# @private
|
842
|
-
# Streaming/resumable media download support
|
843
|
-
class DownloadCommand < ApiCommand
|
844
|
-
# Returns a two-element array containing:
|
845
|
-
# * The `result` that is the usual return type of #execute.
|
846
|
-
# * The `http_resp` from #execute_once.
|
847
|
-
def execute_with_response(client)
|
848
|
-
prepare!
|
849
|
-
begin
|
850
|
-
Retriable.retriable tries: options.retries + 1,
|
851
|
-
base_interval: 1,
|
852
|
-
multiplier: 2,
|
853
|
-
on: RETRIABLE_ERRORS do |try|
|
854
|
-
# This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
|
855
|
-
# auth to be re-attempted without having to retry all sorts of other failures like
|
856
|
-
# NotFound, etc
|
857
|
-
auth_tries = (try == 1 && authorization_refreshable? ? 2 : 1)
|
858
|
-
Retriable.retriable tries: auth_tries,
|
859
|
-
on: [Google::Apis::AuthorizationError, Signet::AuthorizationError],
|
860
|
-
on_retry: proc { |*| refresh_authorization } do
|
861
|
-
execute_once_with_response(client).tap do |result|
|
862
|
-
if block_given?
|
863
|
-
yield result, nil
|
864
|
-
end
|
865
|
-
end
|
866
|
-
end
|
867
|
-
end
|
868
|
-
rescue => e
|
869
|
-
if block_given?
|
870
|
-
yield nil, e
|
871
|
-
else
|
872
|
-
raise e
|
873
|
-
end
|
874
|
-
end
|
875
|
-
ensure
|
876
|
-
release!
|
877
|
-
end
|
878
915
|
|
879
|
-
|
880
|
-
|
881
|
-
# * The `http_resp`.
|
882
|
-
def execute_once_with_response(client, &block)
|
883
|
-
request_header = header.dup
|
884
|
-
apply_request_options(request_header)
|
885
|
-
download_offset = nil
|
886
|
-
|
887
|
-
if @offset > 0
|
888
|
-
logger.debug { sprintf('Resuming download from offset %d', @offset) }
|
889
|
-
request_header[RANGE_HEADER] = sprintf('bytes=%d-', @offset)
|
890
|
-
end
|
891
|
-
|
892
|
-
http_res = client.get(url.to_s,
|
893
|
-
query: query,
|
894
|
-
header: request_header,
|
895
|
-
follow_redirect: true) do |res, chunk|
|
896
|
-
status = res.http_header.status_code.to_i
|
897
|
-
next unless OK_STATUS.include?(status)
|
898
|
-
|
899
|
-
download_offset ||= (status == 206 ? @offset : 0)
|
900
|
-
download_offset += chunk.bytesize
|
901
|
-
|
902
|
-
if download_offset - chunk.bytesize == @offset
|
903
|
-
next_chunk = chunk
|
904
|
-
else
|
905
|
-
# Oh no! Requested a chunk, but received the entire content
|
906
|
-
chunk_index = @offset - (download_offset - chunk.bytesize)
|
907
|
-
next_chunk = chunk.byteslice(chunk_index..-1)
|
908
|
-
next if next_chunk.nil?
|
909
|
-
end
|
910
|
-
# logger.debug { sprintf('Writing chunk (%d bytes, %d total)', chunk.length, bytes_read) }
|
911
|
-
@download_io.write(next_chunk)
|
912
|
-
|
913
|
-
@offset += next_chunk.bytesize
|
914
|
-
end
|
915
|
-
|
916
|
-
@download_io.flush
|
917
|
-
|
918
|
-
if @close_io_on_finish
|
919
|
-
result = nil
|
920
|
-
else
|
921
|
-
result = @download_io
|
922
|
-
end
|
923
|
-
check_status(http_res.status.to_i, http_res.header, http_res.body)
|
924
|
-
success([result, http_res], &block)
|
925
|
-
rescue => e
|
926
|
-
@download_io.flush
|
927
|
-
error(e, rethrow: true, &block)
|
916
|
+
def retry? query_params
|
917
|
+
query_params.any? { |_key, val| !val.nil? }
|
928
918
|
end
|
929
919
|
end
|
930
920
|
end
|
931
921
|
end
|
932
|
-
# rubocop:enable all
|
933
922
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 0.17.0
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 0.17.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: googleauth
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|