google-cloud-storage 1.26.0 → 1.29.0

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.
@@ -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, age: nil,
133
- created_before: nil, is_live: nil,
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, created_before: created_before, is_live: is_live,
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, created_before: nil, is_live: 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, created_before: created_before, is_live: is_live,
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, :storage_class, :age, :created_before,
289
- :is_live, :matches_storage_class, :num_newer_versions
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, storage_class: nil, age: nil,
293
- created_before: nil, is_live: nil,
294
- matches_storage_class: nil, num_newer_versions: nil
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(age, created_before, is_live,
308
- matches_storage_class,
309
- num_newer_versions)
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, storage_class: storage_class
434
+ type: action,
435
+ storage_class: storage_class
320
436
  )
321
437
  end
322
438
 
323
439
  # @private
324
- def condition_gapi age, created_before, is_live,
325
- matches_storage_class, num_newer_versions
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 action.type, storage_class: action.storage_class,
341
- age: c.age,
342
- created_before: c.created_before,
343
- is_live: c.is_live,
344
- matches_storage_class: c.matches_storage_class,
345
- num_newer_versions: c.num_newer_versions
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
- # This is raised when File#signed_url is unable to generate a URL due to
62
- # missing credentials needed to create the URL.
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-"
@@ -746,8 +769,9 @@ module Google
746
769
  # Updates the file with changes made in the given block in a single
747
770
  # PATCH request. The following attributes may be set: {#cache_control=},
748
771
  # {#content_disposition=}, {#content_encoding=}, {#content_language=},
749
- # {#content_type=}, and {#metadata=}. The {#metadata} hash accessible in
750
- # the block is completely mutable and will be included in the request.
772
+ # {#content_type=}, {#custom_time=} and {#metadata=}. The {#metadata} hash
773
+ # accessible in the block is completely mutable and will be included in the
774
+ # request.
751
775
  #
752
776
  # @yield [file] a block yielding a delegate object for updating the file
753
777
  #
@@ -766,6 +790,7 @@ module Google
766
790
  # f.content_encoding = "deflate"
767
791
  # f.content_language = "de"
768
792
  # f.content_type = "application/json"
793
+ # f.custom_time = DateTime.new 2025, 12, 31
769
794
  # f.metadata["player"] = "Bob"
770
795
  # f.metadata["score"] = "10"
771
796
  # end
@@ -1442,7 +1467,7 @@ module Google
1442
1467
  # A {SignedUrlUnavailable} is raised if the service account credentials
1443
1468
  # are missing. Service account credentials are acquired by following the
1444
1469
  # steps in [Service Account Authentication](
1445
- # https://cloud.google.com/storage/docs/authentication#service_accounts).
1470
+ # https://cloud.google.com/iam/docs/service-accounts).
1446
1471
  #
1447
1472
  # @see https://cloud.google.com/storage/docs/access-control/signed-urls
1448
1473
  # Signed URLs guide
@@ -1467,10 +1492,22 @@ module Google
1467
1492
  # use the signed URL.
1468
1493
  # @param [String] issuer Service Account's Client Email.
1469
1494
  # @param [String] client_email Service Account's Client Email.
1470
- # @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
1471
- # Private Key.
1472
- # @param [OpenSSL::PKey::RSA, String] private_key Service Account's
1473
- # Private Key.
1495
+ # @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
1496
+ # Private Key or a Proc that accepts a single String parameter and returns a
1497
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1498
+ # @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
1499
+ # Private Key or a Proc that accepts a single String parameter and returns a
1500
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1501
+ # @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
1502
+ # Private Key or a Proc that accepts a single String parameter and returns a
1503
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1504
+ #
1505
+ # When using this method in environments such as GAE Flexible Environment,
1506
+ # GKE, or Cloud Functions where the private key is unavailable, it may be
1507
+ # necessary to provide a Proc (or lambda) via the signer parameter. This
1508
+ # Proc should return a signature created using a RPC call to the
1509
+ # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1510
+ # method as shown in the example below.
1474
1511
  # @param [Hash] query Query string parameters to include in the signed
1475
1512
  # URL. The given parameters are not verified by the signature.
1476
1513
  #
@@ -1496,7 +1533,12 @@ module Google
1496
1533
  # to create. Must be one of `:v2` or `:v4`. The default value is
1497
1534
  # `:v2`.
1498
1535
  #
1499
- # @return [String]
1536
+ # @return [String] The signed URL.
1537
+ #
1538
+ # @raise [SignedUrlUnavailable] If the service account credentials
1539
+ # are missing. Service account credentials are acquired by following the
1540
+ # steps in [Service Account Authentication](
1541
+ # https://cloud.google.com/iam/docs/service-accounts).
1500
1542
  #
1501
1543
  # @example
1502
1544
  # require "google/cloud/storage"
@@ -1556,6 +1598,40 @@ module Google
1556
1598
  # # Send the `x-goog-resumable:start` header and the content type
1557
1599
  # # with the resumable upload POST request.
1558
1600
  #
1601
+ # @example Using Cloud IAMCredentials signBlob to create the signature:
1602
+ # require "google/cloud/storage"
1603
+ # require "google/apis/iamcredentials_v1"
1604
+ # require "googleauth"
1605
+ #
1606
+ # # Issuer is the service account email that the Signed URL will be signed with
1607
+ # # and any permission granted in the Signed URL must be granted to the
1608
+ # # Google Service Account.
1609
+ # issuer = "service-account@project-id.iam.gserviceaccount.com"
1610
+ #
1611
+ # # Create a lambda that accepts the string_to_sign
1612
+ # signer = lambda do |string_to_sign|
1613
+ # IAMCredentials = Google::Apis::IamcredentialsV1
1614
+ # iam_client = IAMCredentials::IAMCredentialsService.new
1615
+ #
1616
+ # # Get the environment configured authorization
1617
+ # scopes = ["https://www.googleapis.com/auth/iam"]
1618
+ # iam_client.authorization = Google::Auth.get_application_default scopes
1619
+ #
1620
+ # request = {
1621
+ # "payload": string_to_sign,
1622
+ # }
1623
+ # resource = "projects/-/serviceAccounts/#{issuer}"
1624
+ # response = iam_client.sign_service_account_blob resource, request, {}
1625
+ # response.signed_blob
1626
+ # end
1627
+ #
1628
+ # storage = Google::Cloud::Storage.new
1629
+ #
1630
+ # bucket = storage.bucket "my-todo-app"
1631
+ # file = bucket.file "avatars/heidi/400x400.png", skip_lookup: true
1632
+ # url = file.signed_url method: "GET", issuer: issuer,
1633
+ # signer: signer
1634
+ #
1559
1635
  def signed_url method: "GET",
1560
1636
  expires: nil,
1561
1637
  content_type: nil,
@@ -1565,6 +1641,7 @@ module Google
1565
1641
  client_email: nil,
1566
1642
  signing_key: nil,
1567
1643
  private_key: nil,
1644
+ signer: nil,
1568
1645
  query: nil,
1569
1646
  scheme: "HTTPS",
1570
1647
  virtual_hosted_style: nil,
@@ -1574,30 +1651,32 @@ module Google
1574
1651
  version ||= :v2
1575
1652
  case version.to_sym
1576
1653
  when :v2
1577
- signer = File::SignerV2.from_file self
1578
- signer.signed_url method: method,
1579
- expires: expires,
1580
- headers: headers,
1581
- content_type: content_type,
1582
- content_md5: content_md5,
1583
- issuer: issuer,
1584
- client_email: client_email,
1585
- signing_key: signing_key,
1586
- private_key: private_key,
1587
- query: query
1654
+ sign = File::SignerV2.from_file self
1655
+ sign.signed_url method: method,
1656
+ expires: expires,
1657
+ headers: headers,
1658
+ content_type: content_type,
1659
+ content_md5: content_md5,
1660
+ issuer: issuer,
1661
+ client_email: client_email,
1662
+ signing_key: signing_key,
1663
+ private_key: private_key,
1664
+ signer: signer,
1665
+ query: query
1588
1666
  when :v4
1589
- signer = File::SignerV4.from_file self
1590
- signer.signed_url method: method,
1591
- expires: expires,
1592
- headers: headers,
1593
- issuer: issuer,
1594
- client_email: client_email,
1595
- signing_key: signing_key,
1596
- private_key: private_key,
1597
- query: query,
1598
- scheme: scheme,
1599
- virtual_hosted_style: virtual_hosted_style,
1600
- bucket_bound_hostname: bucket_bound_hostname
1667
+ sign = File::SignerV4.from_file self
1668
+ sign.signed_url method: method,
1669
+ expires: expires,
1670
+ headers: headers,
1671
+ issuer: issuer,
1672
+ client_email: client_email,
1673
+ signing_key: signing_key,
1674
+ private_key: private_key,
1675
+ signer: signer,
1676
+ query: query,
1677
+ scheme: scheme,
1678
+ virtual_hosted_style: virtual_hosted_style,
1679
+ bucket_bound_hostname: bucket_bound_hostname
1601
1680
  else
1602
1681
  raise ArgumentError, "version '#{version}' not supported"
1603
1682
  end