google-cloud-storage 1.26.1 → 1.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +8 -2
- data/CHANGELOG.md +59 -0
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google-cloud-storage.rb +1 -0
- data/lib/google/cloud/storage.rb +2 -1
- data/lib/google/cloud/storage/bucket.rb +251 -60
- data/lib/google/cloud/storage/bucket/lifecycle.rb +160 -26
- data/lib/google/cloud/storage/errors.rb +7 -2
- data/lib/google/cloud/storage/file.rb +114 -34
- data/lib/google/cloud/storage/file/signer_v2.rb +21 -12
- data/lib/google/cloud/storage/file/signer_v4.rb +38 -20
- data/lib/google/cloud/storage/project.rb +84 -30
- data/lib/google/cloud/storage/service.rb +4 -3
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +3 -3
@@ -105,6 +105,21 @@ module Google
|
|
105
105
|
# only the date part (for instance, "2013-01-15"). This condition is
|
106
106
|
# satisfied when a file is created before midnight of the specified
|
107
107
|
# date in UTC.
|
108
|
+
# @param [String,Date] custom_time_before A date in RFC 3339 format with
|
109
|
+
# only the date part (for instance, "2013-01-15"). This condition is
|
110
|
+
# satisfied when the custom time on an object is before this date in UTC.
|
111
|
+
# @param [Integer] days_since_custom_time Represents the number of
|
112
|
+
# days elapsed since the user-specified timestamp set on an object.
|
113
|
+
# The condition is satisfied if the days elapsed is at least this
|
114
|
+
# number. If no custom timestamp is specified on an object, the
|
115
|
+
# condition does not apply.
|
116
|
+
# @param [Integer] days_since_noncurrent_time Represents the number of
|
117
|
+
# days elapsed since the noncurrent timestamp of an object. The
|
118
|
+
# condition is satisfied if the days elapsed is at least this number.
|
119
|
+
# The value of the field must be a nonnegative integer. If it's zero,
|
120
|
+
# the object version will become eligible for Lifecycle action as
|
121
|
+
# soon as it becomes noncurrent. Relevant only for versioning-enabled
|
122
|
+
# buckets. (See {Bucket#versioning?})
|
108
123
|
# @param [Boolean] is_live Relevant only for versioned files. If the
|
109
124
|
# value is `true`, this condition matches live files; if the value
|
110
125
|
# is `false`, it matches archived files.
|
@@ -115,6 +130,10 @@ module Google
|
|
115
130
|
# `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
|
116
131
|
# classes. Arguments will be converted from symbols and lower-case
|
117
132
|
# to upper-case strings.
|
133
|
+
# @param [String,Date] noncurrent_time_before A date in RFC 3339 format
|
134
|
+
# with only the date part (for instance, "2013-01-15"). This condition
|
135
|
+
# is satisfied when the noncurrent time on an object is before this
|
136
|
+
# date in UTC. This condition is relevant only for versioned objects.
|
118
137
|
# @param [Integer] num_newer_versions Relevant only for versioned
|
119
138
|
# files. If the value is N, this condition is satisfied when there
|
120
139
|
# are at least N versions (including the live version) newer than
|
@@ -129,16 +148,29 @@ module Google
|
|
129
148
|
# b.lifecycle.add_set_storage_class_rule "COLDLINE", age: 10
|
130
149
|
# end
|
131
150
|
#
|
132
|
-
def add_set_storage_class_rule storage_class,
|
133
|
-
|
151
|
+
def add_set_storage_class_rule storage_class,
|
152
|
+
age: nil,
|
153
|
+
created_before: nil,
|
154
|
+
custom_time_before: nil,
|
155
|
+
days_since_custom_time: nil,
|
156
|
+
days_since_noncurrent_time: nil,
|
157
|
+
is_live: nil,
|
134
158
|
matches_storage_class: nil,
|
159
|
+
noncurrent_time_before: nil,
|
135
160
|
num_newer_versions: nil
|
136
|
-
push Rule.new
|
161
|
+
push Rule.new(
|
137
162
|
"SetStorageClass",
|
138
163
|
storage_class: storage_class_for(storage_class),
|
139
|
-
age: age,
|
164
|
+
age: age,
|
165
|
+
created_before: created_before,
|
166
|
+
custom_time_before: custom_time_before,
|
167
|
+
days_since_custom_time: days_since_custom_time,
|
168
|
+
days_since_noncurrent_time: days_since_noncurrent_time,
|
169
|
+
is_live: is_live,
|
140
170
|
matches_storage_class: storage_class_for(matches_storage_class),
|
171
|
+
noncurrent_time_before: noncurrent_time_before,
|
141
172
|
num_newer_versions: num_newer_versions
|
173
|
+
)
|
142
174
|
end
|
143
175
|
|
144
176
|
##
|
@@ -156,6 +188,21 @@ module Google
|
|
156
188
|
# only the date part (for instance, "2013-01-15"). This condition is
|
157
189
|
# satisfied when a file is created before midnight of the specified
|
158
190
|
# date in UTC.
|
191
|
+
# @param [String,Date] custom_time_before A date in RFC 3339 format with
|
192
|
+
# only the date part (for instance, "2013-01-15"). This condition is
|
193
|
+
# satisfied when the custom time on an object is before this date in UTC.
|
194
|
+
# @param [Integer] days_since_custom_time Represents the number of
|
195
|
+
# days elapsed since the user-specified timestamp set on an object.
|
196
|
+
# The condition is satisfied if the days elapsed is at least this
|
197
|
+
# number. If no custom timestamp is specified on an object, the
|
198
|
+
# condition does not apply.
|
199
|
+
# @param [Integer] days_since_noncurrent_time Represents the number of
|
200
|
+
# days elapsed since the noncurrent timestamp of an object. The
|
201
|
+
# condition is satisfied if the days elapsed is at least this number.
|
202
|
+
# The value of the field must be a nonnegative integer. If it's zero,
|
203
|
+
# the object version will become eligible for Lifecycle action as
|
204
|
+
# soon as it becomes noncurrent. Relevant only for versioning-enabled
|
205
|
+
# buckets. (See {Bucket#versioning?})
|
159
206
|
# @param [Boolean] is_live Relevant only for versioned files. If the
|
160
207
|
# value is `true`, this condition matches live files; if the value
|
161
208
|
# is `false`, it matches archived files.
|
@@ -166,6 +213,10 @@ module Google
|
|
166
213
|
# `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
|
167
214
|
# classes. Arguments will be converted from symbols and lower-case
|
168
215
|
# to upper-case strings.
|
216
|
+
# @param [String,Date] noncurrent_time_before A date in RFC 3339 format
|
217
|
+
# with only the date part (for instance, "2013-01-15"). This condition
|
218
|
+
# is satisfied when the noncurrent time on an object is before this
|
219
|
+
# date in UTC. This condition is relevant only for versioned objects.
|
169
220
|
# @param [Integer] num_newer_versions Relevant only for versioned
|
170
221
|
# files. If the value is N, this condition is satisfied when there
|
171
222
|
# are at least N versions (including the live version) newer than
|
@@ -180,14 +231,27 @@ module Google
|
|
180
231
|
# b.lifecycle.add_delete_rule age: 30, is_live: false
|
181
232
|
# end
|
182
233
|
#
|
183
|
-
def add_delete_rule age: nil,
|
234
|
+
def add_delete_rule age: nil,
|
235
|
+
created_before: nil,
|
236
|
+
custom_time_before: nil,
|
237
|
+
days_since_custom_time: nil,
|
238
|
+
days_since_noncurrent_time: nil,
|
239
|
+
is_live: nil,
|
184
240
|
matches_storage_class: nil,
|
241
|
+
noncurrent_time_before: nil,
|
185
242
|
num_newer_versions: nil
|
186
|
-
push Rule.new
|
243
|
+
push Rule.new(
|
187
244
|
"Delete",
|
188
|
-
age: age,
|
245
|
+
age: age,
|
246
|
+
created_before: created_before,
|
247
|
+
custom_time_before: custom_time_before,
|
248
|
+
days_since_custom_time: days_since_custom_time,
|
249
|
+
days_since_noncurrent_time: days_since_noncurrent_time,
|
250
|
+
is_live: is_live,
|
189
251
|
matches_storage_class: storage_class_for(matches_storage_class),
|
252
|
+
noncurrent_time_before: noncurrent_time_before,
|
190
253
|
num_newer_versions: num_newer_versions
|
254
|
+
)
|
191
255
|
end
|
192
256
|
|
193
257
|
# @private
|
@@ -231,10 +295,26 @@ module Google
|
|
231
295
|
# action. Required only if the action is `SetStorageClass`.
|
232
296
|
# @attr [Integer] age The age of a file (in days). This condition is
|
233
297
|
# satisfied when a file reaches the specified age.
|
234
|
-
# @attr [String,Date] created_before A date in RFC 3339 format with
|
298
|
+
# @attr [String,Date,nil] created_before A date in RFC 3339 format with
|
235
299
|
# only the date part (for instance, "2013-01-15"). This condition is
|
236
300
|
# satisfied when a file is created before midnight of the specified
|
237
|
-
# date in UTC.
|
301
|
+
# date in UTC. When returned by the service, a non-empty value will
|
302
|
+
# always be a Date object.
|
303
|
+
# @attr [String,Date,nil] custom_time_before A date in RFC 3339 format with
|
304
|
+
# only the date part (for instance, "2013-01-15"). This condition is
|
305
|
+
# satisfied when the custom time on an object is before this date in UTC.
|
306
|
+
# @attr [Integer,nil] days_since_custom_time Represents the number of
|
307
|
+
# days elapsed since the user-specified timestamp set on an object.
|
308
|
+
# The condition is satisfied if the days elapsed is at least this
|
309
|
+
# number. If no custom timestamp is specified on an object, the
|
310
|
+
# condition does not apply.
|
311
|
+
# @attr [Integer] days_since_noncurrent_time Represents the number of
|
312
|
+
# days elapsed since the noncurrent timestamp of an object. The
|
313
|
+
# condition is satisfied if the days elapsed is at least this number.
|
314
|
+
# The value of the field must be a nonnegative integer. If it's zero,
|
315
|
+
# the object version will become eligible for Lifecycle action as
|
316
|
+
# soon as it becomes noncurrent. Relevant only for versioning-enabled
|
317
|
+
# buckets. (See {Bucket#versioning?})
|
238
318
|
# @attr [Boolean] is_live Relevant only for versioned files. If the
|
239
319
|
# value is `true`, this condition matches live files; if the value
|
240
320
|
# is `false`, it matches archived files.
|
@@ -243,6 +323,12 @@ module Google
|
|
243
323
|
# Values include `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`.
|
244
324
|
# `REGIONAL`, `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY`
|
245
325
|
# are supported as legacy storage classes.
|
326
|
+
# @attr [String,Date,nil] noncurrent_time_before A date in RFC 3339 format
|
327
|
+
# with only the date part (for instance, "2013-01-15"). This condition
|
328
|
+
# is satisfied when the noncurrent time on an object is before this
|
329
|
+
# date in UTC. This condition is relevant only for versioned objects.
|
330
|
+
# When returned by the service, a non-empty value will always be a
|
331
|
+
# Date object.
|
246
332
|
# @attr [Integer] num_newer_versions Relevant only for versioned
|
247
333
|
# files. If the value is N, this condition is satisfied when there
|
248
334
|
# are at least N versions (including the live version) newer than
|
@@ -285,28 +371,57 @@ module Google
|
|
285
371
|
# end
|
286
372
|
#
|
287
373
|
class Rule
|
288
|
-
attr_accessor :action,
|
289
|
-
:
|
374
|
+
attr_accessor :action,
|
375
|
+
:storage_class,
|
376
|
+
:age,
|
377
|
+
:created_before,
|
378
|
+
:custom_time_before,
|
379
|
+
:days_since_custom_time,
|
380
|
+
:days_since_noncurrent_time,
|
381
|
+
:is_live,
|
382
|
+
:matches_storage_class,
|
383
|
+
:noncurrent_time_before,
|
384
|
+
:num_newer_versions
|
290
385
|
|
291
386
|
# @private
|
292
|
-
def initialize action,
|
293
|
-
|
294
|
-
|
387
|
+
def initialize action,
|
388
|
+
storage_class: nil,
|
389
|
+
age: nil,
|
390
|
+
created_before: nil,
|
391
|
+
custom_time_before: nil,
|
392
|
+
days_since_custom_time: nil,
|
393
|
+
days_since_noncurrent_time: nil,
|
394
|
+
is_live: nil,
|
395
|
+
matches_storage_class: nil,
|
396
|
+
noncurrent_time_before: nil,
|
397
|
+
num_newer_versions: nil
|
295
398
|
@action = action
|
296
399
|
@storage_class = storage_class
|
297
400
|
@age = age
|
298
401
|
@created_before = created_before
|
402
|
+
@custom_time_before = custom_time_before
|
403
|
+
@days_since_custom_time = days_since_custom_time
|
404
|
+
@days_since_noncurrent_time = days_since_noncurrent_time
|
299
405
|
@is_live = is_live
|
300
406
|
@matches_storage_class = Array(matches_storage_class)
|
407
|
+
@noncurrent_time_before = noncurrent_time_before
|
301
408
|
@num_newer_versions = num_newer_versions
|
302
409
|
end
|
303
410
|
|
304
411
|
# @private
|
305
412
|
# @return [Google::Apis::StorageV1::Bucket::Lifecycle]
|
306
413
|
def to_gapi
|
307
|
-
condition = condition_gapi(
|
308
|
-
|
309
|
-
|
414
|
+
condition = condition_gapi(
|
415
|
+
age,
|
416
|
+
created_before,
|
417
|
+
custom_time_before,
|
418
|
+
days_since_custom_time,
|
419
|
+
days_since_noncurrent_time,
|
420
|
+
is_live,
|
421
|
+
matches_storage_class,
|
422
|
+
noncurrent_time_before,
|
423
|
+
num_newer_versions
|
424
|
+
)
|
310
425
|
Google::Apis::StorageV1::Bucket::Lifecycle::Rule.new(
|
311
426
|
action: action_gapi(action, storage_class),
|
312
427
|
condition: condition
|
@@ -316,18 +431,30 @@ module Google
|
|
316
431
|
# @private
|
317
432
|
def action_gapi action, storage_class
|
318
433
|
Google::Apis::StorageV1::Bucket::Lifecycle::Rule::Action.new(
|
319
|
-
type: action,
|
434
|
+
type: action,
|
435
|
+
storage_class: storage_class
|
320
436
|
)
|
321
437
|
end
|
322
438
|
|
323
439
|
# @private
|
324
|
-
def condition_gapi age,
|
325
|
-
|
440
|
+
def condition_gapi age,
|
441
|
+
created_before,
|
442
|
+
custom_time_before,
|
443
|
+
days_since_custom_time,
|
444
|
+
days_since_noncurrent_time,
|
445
|
+
is_live,
|
446
|
+
matches_storage_class,
|
447
|
+
noncurrent_time_before,
|
448
|
+
num_newer_versions
|
326
449
|
Google::Apis::StorageV1::Bucket::Lifecycle::Rule::Condition.new(
|
327
450
|
age: age,
|
328
451
|
created_before: created_before,
|
452
|
+
custom_time_before: custom_time_before,
|
453
|
+
days_since_custom_time: days_since_custom_time,
|
454
|
+
days_since_noncurrent_time: days_since_noncurrent_time,
|
329
455
|
is_live: is_live,
|
330
456
|
matches_storage_class: Array(matches_storage_class),
|
457
|
+
noncurrent_time_before: noncurrent_time_before,
|
331
458
|
num_newer_versions: num_newer_versions
|
332
459
|
)
|
333
460
|
end
|
@@ -337,12 +464,19 @@ module Google
|
|
337
464
|
def self.from_gapi gapi
|
338
465
|
action = gapi.action
|
339
466
|
c = gapi.condition
|
340
|
-
new
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
467
|
+
new(
|
468
|
+
action.type,
|
469
|
+
storage_class: action.storage_class,
|
470
|
+
age: c.age,
|
471
|
+
created_before: c.created_before,
|
472
|
+
custom_time_before: c.custom_time_before,
|
473
|
+
days_since_custom_time: c.days_since_custom_time,
|
474
|
+
days_since_noncurrent_time: c.days_since_noncurrent_time,
|
475
|
+
is_live: c.is_live,
|
476
|
+
matches_storage_class: c.matches_storage_class,
|
477
|
+
noncurrent_time_before: c.noncurrent_time_before,
|
478
|
+
num_newer_versions: c.num_newer_versions
|
479
|
+
)
|
346
480
|
end
|
347
481
|
|
348
482
|
# @private
|
@@ -58,8 +58,13 @@ module Google
|
|
58
58
|
##
|
59
59
|
# # SignedUrlUnavailable Error
|
60
60
|
#
|
61
|
-
#
|
62
|
-
# missing credentials
|
61
|
+
# Raised by signed URL methods if the service account credentials
|
62
|
+
# are missing. Service account credentials are acquired by following the
|
63
|
+
# steps in [Service Account Authentication](
|
64
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
65
|
+
#
|
66
|
+
# @see https://cloud.google.com/storage/docs/access-control/signed-urls Signed URLs
|
67
|
+
#
|
63
68
|
class SignedUrlUnavailable < Google::Cloud::Error
|
64
69
|
end
|
65
70
|
end
|
@@ -355,6 +355,29 @@ module Google
|
|
355
355
|
update_gapi! :content_type
|
356
356
|
end
|
357
357
|
|
358
|
+
##
|
359
|
+
# A custom time specified by the user for the file, or `nil`.
|
360
|
+
#
|
361
|
+
# @return [DateTime, nil]
|
362
|
+
#
|
363
|
+
def custom_time
|
364
|
+
@gapi.custom_time
|
365
|
+
end
|
366
|
+
|
367
|
+
##
|
368
|
+
# Updates the custom time specified by the user for the file. Once set,
|
369
|
+
# custom_time can't be unset, and it can only be changed to a time in the
|
370
|
+
# future. If custom_time must be unset, you must either perform a rewrite
|
371
|
+
# operation, or upload the data again and create a new file.
|
372
|
+
#
|
373
|
+
# @param [DateTime] custom_time A custom time specified by the user
|
374
|
+
# for the file.
|
375
|
+
#
|
376
|
+
def custom_time= custom_time
|
377
|
+
@gapi.custom_time = custom_time
|
378
|
+
update_gapi! :custom_time
|
379
|
+
end
|
380
|
+
|
358
381
|
##
|
359
382
|
# A hash of custom, user-provided web-safe keys and arbitrary string
|
360
383
|
# values that will returned with requests for the file as "x-goog-meta-"
|
@@ -389,7 +412,8 @@ module Google
|
|
389
412
|
# You can use this SHA256 hash to uniquely identify the AES-256
|
390
413
|
# encryption key required to decrypt this file.
|
391
414
|
#
|
392
|
-
# @return [String]
|
415
|
+
# @return [String, nil] The encoded SHA256 hash, or `nil` if there is
|
416
|
+
# no customer-supplied encryption key for this file.
|
393
417
|
#
|
394
418
|
def encryption_key_sha256
|
395
419
|
return nil unless @gapi.customer_encryption
|
@@ -746,8 +770,9 @@ module Google
|
|
746
770
|
# Updates the file with changes made in the given block in a single
|
747
771
|
# PATCH request. The following attributes may be set: {#cache_control=},
|
748
772
|
# {#content_disposition=}, {#content_encoding=}, {#content_language=},
|
749
|
-
# {#content_type=}, and {#metadata=}. The {#metadata} hash
|
750
|
-
# the block is completely mutable and will be included in the
|
773
|
+
# {#content_type=}, {#custom_time=} and {#metadata=}. The {#metadata} hash
|
774
|
+
# accessible in the block is completely mutable and will be included in the
|
775
|
+
# request.
|
751
776
|
#
|
752
777
|
# @yield [file] a block yielding a delegate object for updating the file
|
753
778
|
#
|
@@ -766,6 +791,7 @@ module Google
|
|
766
791
|
# f.content_encoding = "deflate"
|
767
792
|
# f.content_language = "de"
|
768
793
|
# f.content_type = "application/json"
|
794
|
+
# f.custom_time = DateTime.new 2025, 12, 31
|
769
795
|
# f.metadata["player"] = "Bob"
|
770
796
|
# f.metadata["score"] = "10"
|
771
797
|
# end
|
@@ -1204,7 +1230,7 @@ module Google
|
|
1204
1230
|
# cipher.encrypt
|
1205
1231
|
# new_key = cipher.random_key
|
1206
1232
|
#
|
1207
|
-
# file = bucket.file "path/to/my-file.ext"
|
1233
|
+
# file = bucket.file "path/to/my-file.ext", encryption_key: old_key
|
1208
1234
|
# file.rewrite "new-destination-bucket",
|
1209
1235
|
# "path/to/destination/file.ext",
|
1210
1236
|
# encryption_key: old_key,
|
@@ -1225,7 +1251,7 @@ module Google
|
|
1225
1251
|
# # Old customer-supplied key was stored securely for later use.
|
1226
1252
|
# old_key = "y\x03\"\x0E\xB6\xD3\x9B\x0E\xAB*\x19\xFAv\xDEY\xBEI..."
|
1227
1253
|
#
|
1228
|
-
# file = bucket.file "path/to/my-file.ext"
|
1254
|
+
# file = bucket.file "path/to/my-file.ext", encryption_key: old_key
|
1229
1255
|
# file.rewrite "new-destination-bucket",
|
1230
1256
|
# "path/to/destination/file.ext",
|
1231
1257
|
# encryption_key: old_key,
|
@@ -1442,7 +1468,7 @@ module Google
|
|
1442
1468
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
1443
1469
|
# are missing. Service account credentials are acquired by following the
|
1444
1470
|
# steps in [Service Account Authentication](
|
1445
|
-
# https://cloud.google.com/
|
1471
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
1446
1472
|
#
|
1447
1473
|
# @see https://cloud.google.com/storage/docs/access-control/signed-urls
|
1448
1474
|
# Signed URLs guide
|
@@ -1467,10 +1493,22 @@ module Google
|
|
1467
1493
|
# use the signed URL.
|
1468
1494
|
# @param [String] issuer Service Account's Client Email.
|
1469
1495
|
# @param [String] client_email Service Account's Client Email.
|
1470
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
1471
|
-
# Private Key
|
1472
|
-
#
|
1473
|
-
#
|
1496
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
|
1497
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
1498
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
1499
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
|
1500
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
1501
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
1502
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
|
1503
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
1504
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
1505
|
+
#
|
1506
|
+
# When using this method in environments such as GAE Flexible Environment,
|
1507
|
+
# GKE, or Cloud Functions where the private key is unavailable, it may be
|
1508
|
+
# necessary to provide a Proc (or lambda) via the signer parameter. This
|
1509
|
+
# Proc should return a signature created using a RPC call to the
|
1510
|
+
# [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
|
1511
|
+
# method as shown in the example below.
|
1474
1512
|
# @param [Hash] query Query string parameters to include in the signed
|
1475
1513
|
# URL. The given parameters are not verified by the signature.
|
1476
1514
|
#
|
@@ -1496,7 +1534,12 @@ module Google
|
|
1496
1534
|
# to create. Must be one of `:v2` or `:v4`. The default value is
|
1497
1535
|
# `:v2`.
|
1498
1536
|
#
|
1499
|
-
# @return [String]
|
1537
|
+
# @return [String] The signed URL.
|
1538
|
+
#
|
1539
|
+
# @raise [SignedUrlUnavailable] If the service account credentials
|
1540
|
+
# are missing. Service account credentials are acquired by following the
|
1541
|
+
# steps in [Service Account Authentication](
|
1542
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
1500
1543
|
#
|
1501
1544
|
# @example
|
1502
1545
|
# require "google/cloud/storage"
|
@@ -1556,6 +1599,40 @@ module Google
|
|
1556
1599
|
# # Send the `x-goog-resumable:start` header and the content type
|
1557
1600
|
# # with the resumable upload POST request.
|
1558
1601
|
#
|
1602
|
+
# @example Using Cloud IAMCredentials signBlob to create the signature:
|
1603
|
+
# require "google/cloud/storage"
|
1604
|
+
# require "google/apis/iamcredentials_v1"
|
1605
|
+
# require "googleauth"
|
1606
|
+
#
|
1607
|
+
# # Issuer is the service account email that the Signed URL will be signed with
|
1608
|
+
# # and any permission granted in the Signed URL must be granted to the
|
1609
|
+
# # Google Service Account.
|
1610
|
+
# issuer = "service-account@project-id.iam.gserviceaccount.com"
|
1611
|
+
#
|
1612
|
+
# # Create a lambda that accepts the string_to_sign
|
1613
|
+
# signer = lambda do |string_to_sign|
|
1614
|
+
# IAMCredentials = Google::Apis::IamcredentialsV1
|
1615
|
+
# iam_client = IAMCredentials::IAMCredentialsService.new
|
1616
|
+
#
|
1617
|
+
# # Get the environment configured authorization
|
1618
|
+
# scopes = ["https://www.googleapis.com/auth/iam"]
|
1619
|
+
# iam_client.authorization = Google::Auth.get_application_default scopes
|
1620
|
+
#
|
1621
|
+
# request = {
|
1622
|
+
# "payload": string_to_sign,
|
1623
|
+
# }
|
1624
|
+
# resource = "projects/-/serviceAccounts/#{issuer}"
|
1625
|
+
# response = iam_client.sign_service_account_blob resource, request, {}
|
1626
|
+
# response.signed_blob
|
1627
|
+
# end
|
1628
|
+
#
|
1629
|
+
# storage = Google::Cloud::Storage.new
|
1630
|
+
#
|
1631
|
+
# bucket = storage.bucket "my-todo-app"
|
1632
|
+
# file = bucket.file "avatars/heidi/400x400.png", skip_lookup: true
|
1633
|
+
# url = file.signed_url method: "GET", issuer: issuer,
|
1634
|
+
# signer: signer
|
1635
|
+
#
|
1559
1636
|
def signed_url method: "GET",
|
1560
1637
|
expires: nil,
|
1561
1638
|
content_type: nil,
|
@@ -1565,6 +1642,7 @@ module Google
|
|
1565
1642
|
client_email: nil,
|
1566
1643
|
signing_key: nil,
|
1567
1644
|
private_key: nil,
|
1645
|
+
signer: nil,
|
1568
1646
|
query: nil,
|
1569
1647
|
scheme: "HTTPS",
|
1570
1648
|
virtual_hosted_style: nil,
|
@@ -1574,30 +1652,32 @@ module Google
|
|
1574
1652
|
version ||= :v2
|
1575
1653
|
case version.to_sym
|
1576
1654
|
when :v2
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1655
|
+
sign = File::SignerV2.from_file self
|
1656
|
+
sign.signed_url method: method,
|
1657
|
+
expires: expires,
|
1658
|
+
headers: headers,
|
1659
|
+
content_type: content_type,
|
1660
|
+
content_md5: content_md5,
|
1661
|
+
issuer: issuer,
|
1662
|
+
client_email: client_email,
|
1663
|
+
signing_key: signing_key,
|
1664
|
+
private_key: private_key,
|
1665
|
+
signer: signer,
|
1666
|
+
query: query
|
1588
1667
|
when :v4
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1668
|
+
sign = File::SignerV4.from_file self
|
1669
|
+
sign.signed_url method: method,
|
1670
|
+
expires: expires,
|
1671
|
+
headers: headers,
|
1672
|
+
issuer: issuer,
|
1673
|
+
client_email: client_email,
|
1674
|
+
signing_key: signing_key,
|
1675
|
+
private_key: private_key,
|
1676
|
+
signer: signer,
|
1677
|
+
query: query,
|
1678
|
+
scheme: scheme,
|
1679
|
+
virtual_hosted_style: virtual_hosted_style,
|
1680
|
+
bucket_bound_hostname: bucket_bound_hostname
|
1601
1681
|
else
|
1602
1682
|
raise ArgumentError, "version '#{version}' not supported"
|
1603
1683
|
end
|