google-cloud-storage 1.18.1 → 1.44.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +17 -30
  3. data/CHANGELOG.md +312 -0
  4. data/CONTRIBUTING.md +4 -5
  5. data/LOGGING.md +1 -1
  6. data/OVERVIEW.md +37 -5
  7. data/TROUBLESHOOTING.md +2 -8
  8. data/lib/google/cloud/storage/bucket/acl.rb +40 -40
  9. data/lib/google/cloud/storage/bucket/cors.rb +4 -1
  10. data/lib/google/cloud/storage/bucket/lifecycle.rb +259 -44
  11. data/lib/google/cloud/storage/bucket/list.rb +3 -3
  12. data/lib/google/cloud/storage/bucket.rb +1096 -172
  13. data/lib/google/cloud/storage/convert.rb +4 -3
  14. data/lib/google/cloud/storage/credentials.rb +16 -14
  15. data/lib/google/cloud/storage/errors.rb +7 -2
  16. data/lib/google/cloud/storage/file/acl.rb +181 -20
  17. data/lib/google/cloud/storage/file/list.rb +10 -8
  18. data/lib/google/cloud/storage/file/signer_v2.rb +36 -18
  19. data/lib/google/cloud/storage/file/signer_v4.rb +249 -61
  20. data/lib/google/cloud/storage/file/verifier.rb +2 -2
  21. data/lib/google/cloud/storage/file.rb +450 -84
  22. data/lib/google/cloud/storage/hmac_key/list.rb +182 -0
  23. data/lib/google/cloud/storage/hmac_key.rb +316 -0
  24. data/lib/google/cloud/storage/policy/binding.rb +246 -0
  25. data/lib/google/cloud/storage/policy/bindings.rb +196 -0
  26. data/lib/google/cloud/storage/policy/condition.rb +138 -0
  27. data/lib/google/cloud/storage/policy.rb +277 -24
  28. data/lib/google/cloud/storage/post_object.rb +20 -2
  29. data/lib/google/cloud/storage/project.rb +249 -50
  30. data/lib/google/cloud/storage/service.rb +479 -288
  31. data/lib/google/cloud/storage/version.rb +1 -1
  32. data/lib/google/cloud/storage.rb +86 -16
  33. data/lib/google-cloud-storage.rb +54 -7
  34. metadata +74 -27
@@ -198,7 +198,7 @@ module Google
198
198
  gapi = @service.insert_bucket_acl @bucket, entity, "OWNER",
199
199
  user_project: user_project
200
200
  entity = gapi.entity
201
- @owners.push entity unless @owners.nil?
201
+ @owners&.push entity
202
202
  entity
203
203
  end
204
204
 
@@ -243,7 +243,7 @@ module Google
243
243
  gapi = @service.insert_bucket_acl @bucket, entity, "WRITER",
244
244
  user_project: user_project
245
245
  entity = gapi.entity
246
- @writers.push entity unless @writers.nil?
246
+ @writers&.push entity
247
247
  entity
248
248
  end
249
249
 
@@ -288,7 +288,7 @@ module Google
288
288
  gapi = @service.insert_bucket_acl @bucket, entity, "READER",
289
289
  user_project: user_project
290
290
  entity = gapi.entity
291
- @readers.push entity unless @readers.nil?
291
+ @readers&.push entity
292
292
  entity
293
293
  end
294
294
 
@@ -323,9 +323,9 @@ module Google
323
323
  def delete entity
324
324
  @service.delete_bucket_acl @bucket, entity,
325
325
  user_project: user_project
326
- @owners.delete entity unless @owners.nil?
327
- @writers.delete entity unless @writers.nil?
328
- @readers.delete entity unless @readers.nil?
326
+ @owners&.delete entity
327
+ @writers&.delete entity
328
+ @readers&.delete entity
329
329
  true
330
330
  end
331
331
 
@@ -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,16 +437,16 @@ 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
 
446
447
  def entities_from_acls acls, role
447
448
  selected = acls.select { |acl| acl.role == role }
448
- entities = selected.map(&:entity)
449
- entities
449
+ selected.map(&:entity)
450
450
  end
451
451
  end
452
452
 
@@ -614,7 +614,7 @@ module Google
614
614
  gapi = @service.insert_default_acl @bucket, entity, "OWNER",
615
615
  user_project: user_project
616
616
  entity = gapi.entity
617
- @owners.push entity unless @owners.nil?
617
+ @owners&.push entity
618
618
  entity
619
619
  end
620
620
 
@@ -657,7 +657,7 @@ module Google
657
657
  gapi = @service.insert_default_acl @bucket, entity, "READER",
658
658
  user_project: user_project
659
659
  entity = gapi.entity
660
- @readers.push entity unless @readers.nil?
660
+ @readers&.push entity
661
661
  entity
662
662
  end
663
663
 
@@ -690,8 +690,8 @@ module Google
690
690
  def delete entity
691
691
  @service.delete_default_acl @bucket, entity,
692
692
  user_project: user_project
693
- @owners.delete entity unless @owners.nil?
694
- @readers.delete entity unless @readers.nil?
693
+ @owners&.delete entity
694
+ @readers&.delete entity
695
695
  true
696
696
  end
697
697
 
@@ -715,8 +715,8 @@ module Google
715
715
  #
716
716
  # bucket.default_acl.auth!
717
717
  #
718
- def auth!
719
- update_predefined_default_acl! "authenticatedRead"
718
+ def auth! if_metageneration_match: nil
719
+ update_predefined_default_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
720
720
  end
721
721
  alias authenticatedRead! auth!
722
722
  alias auth_read! auth!
@@ -736,8 +736,8 @@ module Google
736
736
  #
737
737
  # bucket.default_acl.owner_full!
738
738
  #
739
- def owner_full!
740
- 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
741
741
  end
742
742
  alias bucketOwnerFullControl! owner_full!
743
743
 
@@ -754,8 +754,8 @@ module Google
754
754
  #
755
755
  # bucket.default_acl.owner_read!
756
756
  #
757
- def owner_read!
758
- 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
759
759
  end
760
760
  alias bucketOwnerRead! owner_read!
761
761
 
@@ -772,8 +772,8 @@ module Google
772
772
  #
773
773
  # bucket.default_acl.private!
774
774
  #
775
- def private!
776
- update_predefined_default_acl! "private"
775
+ def private! if_metageneration_match: nil
776
+ update_predefined_default_acl! "private", if_metageneration_match: if_metageneration_match
777
777
  end
778
778
 
779
779
  ##
@@ -789,8 +789,8 @@ module Google
789
789
  #
790
790
  # bucket.default_acl.project_private!
791
791
  #
792
- def project_private!
793
- 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
794
794
  end
795
795
  alias projectPrivate! project_private!
796
796
 
@@ -807,8 +807,8 @@ module Google
807
807
  #
808
808
  # bucket.default_acl.public!
809
809
  #
810
- def public!
811
- update_predefined_default_acl! "publicRead"
810
+ def public! if_metageneration_match: nil
811
+ update_predefined_default_acl! "publicRead", if_metageneration_match: if_metageneration_match
812
812
  end
813
813
  alias publicRead! public!
814
814
  alias public_read! public!
@@ -821,16 +821,16 @@ module Google
821
821
  self
822
822
  end
823
823
 
824
- def update_predefined_default_acl! acl_role
824
+ def update_predefined_default_acl! acl_role, if_metageneration_match: nil
825
825
  @service.patch_bucket @bucket, predefined_default_acl: acl_role,
826
- user_project: user_project
826
+ user_project: user_project,
827
+ if_metageneration_match: if_metageneration_match
827
828
  clear!
828
829
  end
829
830
 
830
831
  def entities_from_acls acls, role
831
832
  selected = acls.select { |acl| acl.role == role }
832
- entities = selected.map(&:entity)
833
- entities
833
+ selected.map(&:entity)
834
834
  end
835
835
  end
836
836
  end
@@ -172,7 +172,10 @@ module Google
172
172
  # rule.max_age #=> 3600
173
173
  #
174
174
  class Rule
175
- attr_accessor :origin, :methods, :headers, :max_age
175
+ attr_accessor :origin
176
+ attr_accessor :methods
177
+ attr_accessor :headers
178
+ attr_accessor :max_age
176
179
 
177
180
  # @private
178
181
  def initialize origin, methods, headers: nil, max_age: nil
@@ -52,7 +52,9 @@ module Google
52
52
  # rule.action #=> "SetStorageClass"
53
53
  # rule.storage_class #=> "COLDLINE"
54
54
  # rule.age #=> 10
55
- # rule.matches_storage_class #=> ["MULTI_REGIONAL", "REGIONAL"]
55
+ # rule.matches_storage_class #=> ["STANDARD", "NEARLINE"]
56
+ # rule.matches_prefix #=> ["myprefix/foo"]
57
+ # rule.matches_suffix #=> [".jpg", ".png"]
56
58
  #
57
59
  # @example Updating the bucket's lifecycle management rules in a block.
58
60
  # require "google/cloud/storage"
@@ -105,19 +107,45 @@ module Google
105
107
  # only the date part (for instance, "2013-01-15"). This condition is
106
108
  # satisfied when a file is created before midnight of the specified
107
109
  # date in UTC.
110
+ # @param [String,Date] custom_time_before A date in RFC 3339 format with
111
+ # only the date part (for instance, "2013-01-15"). This condition is
112
+ # satisfied when the custom time on an object is before this date in UTC.
113
+ # @param [Integer] days_since_custom_time Represents the number of
114
+ # days elapsed since the user-specified timestamp set on an object.
115
+ # The condition is satisfied if the days elapsed is at least this
116
+ # number. If no custom timestamp is specified on an object, the
117
+ # condition does not apply.
118
+ # @param [Integer] days_since_noncurrent_time Represents the number of
119
+ # days elapsed since the noncurrent timestamp of an object. The
120
+ # condition is satisfied if the days elapsed is at least this number.
121
+ # The value of the field must be a nonnegative integer. If it's zero,
122
+ # the object version will become eligible for Lifecycle action as
123
+ # soon as it becomes noncurrent. Relevant only for versioning-enabled
124
+ # buckets. (See {Bucket#versioning?})
108
125
  # @param [Boolean] is_live Relevant only for versioned files. If the
109
126
  # value is `true`, this condition matches live files; if the value
110
127
  # is `false`, it matches archived files.
111
128
  # @param [String,Symbol,Array<String,Symbol>] matches_storage_class
112
129
  # Files having any of the storage classes specified by this
113
- # condition will be matched. Values include `MULTI_REGIONAL`,
114
- # `REGIONAL`, `NEARLINE`, `COLDLINE`, `STANDARD`, and
115
- # `DURABLE_REDUCED_AVAILABILITY`. Arguments will be converted from
116
- # symbols and lower-case to upper-case strings.
130
+ # condition will be matched. Values include `STANDARD`, `NEARLINE`,
131
+ # `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`, and
132
+ # `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
133
+ # classes. Arguments will be converted from symbols and lower-case
134
+ # to upper-case strings.
135
+ # @param [String,Date] noncurrent_time_before A date in RFC 3339 format
136
+ # with only the date part (for instance, "2013-01-15"). This condition
137
+ # is satisfied when the noncurrent time on an object is before this
138
+ # date in UTC. This condition is relevant only for versioned objects.
117
139
  # @param [Integer] num_newer_versions Relevant only for versioned
118
140
  # files. If the value is N, this condition is satisfied when there
119
141
  # are at least N versions (including the live version) newer than
120
142
  # this version of the file.
143
+ # @param [Array<String,Symbol>] matches_prefix
144
+ # Files having their name with the specified list of prefixs will be matched.
145
+ # Arguments will be converted from symbols to strings.
146
+ # @param [Array<String,Symbol>] matches_suffix
147
+ # Files having their name with the specified list of suffixes will be matched.
148
+ # Arguments will be converted from symbols to strings.
121
149
  #
122
150
  # @example
123
151
  # require "google/cloud/storage"
@@ -128,20 +156,37 @@ module Google
128
156
  # b.lifecycle.add_set_storage_class_rule "COLDLINE", age: 10
129
157
  # end
130
158
  #
131
- def add_set_storage_class_rule storage_class, age: nil,
132
- created_before: nil, is_live: nil,
159
+ def add_set_storage_class_rule storage_class,
160
+ age: nil,
161
+ created_before: nil,
162
+ custom_time_before: nil,
163
+ days_since_custom_time: nil,
164
+ days_since_noncurrent_time: nil,
165
+ is_live: nil,
133
166
  matches_storage_class: nil,
134
- num_newer_versions: nil
135
- push Rule.new \
167
+ noncurrent_time_before: nil,
168
+ num_newer_versions: nil,
169
+ matches_prefix: nil,
170
+ matches_suffix: nil
171
+ push Rule.new(
136
172
  "SetStorageClass",
137
173
  storage_class: storage_class_for(storage_class),
138
- age: age, created_before: created_before, is_live: is_live,
174
+ age: age,
175
+ created_before: created_before,
176
+ custom_time_before: custom_time_before,
177
+ days_since_custom_time: days_since_custom_time,
178
+ days_since_noncurrent_time: days_since_noncurrent_time,
179
+ is_live: is_live,
139
180
  matches_storage_class: storage_class_for(matches_storage_class),
140
- num_newer_versions: num_newer_versions
181
+ noncurrent_time_before: noncurrent_time_before,
182
+ num_newer_versions: num_newer_versions,
183
+ matches_prefix: Array(matches_prefix),
184
+ matches_suffix: Array(matches_suffix)
185
+ )
141
186
  end
142
187
 
143
188
  ##
144
- # Adds a SetStorageClass lifecycle rule to the Object Lifecycle
189
+ # Adds a Delete lifecycle rule to the Object Lifecycle
145
190
  # Management rules for a bucket.
146
191
  #
147
192
  # @see https://cloud.google.com/storage/docs/lifecycle Object
@@ -155,19 +200,45 @@ module Google
155
200
  # only the date part (for instance, "2013-01-15"). This condition is
156
201
  # satisfied when a file is created before midnight of the specified
157
202
  # date in UTC.
203
+ # @param [String,Date] custom_time_before A date in RFC 3339 format with
204
+ # only the date part (for instance, "2013-01-15"). This condition is
205
+ # satisfied when the custom time on an object is before this date in UTC.
206
+ # @param [Integer] days_since_custom_time Represents the number of
207
+ # days elapsed since the user-specified timestamp set on an object.
208
+ # The condition is satisfied if the days elapsed is at least this
209
+ # number. If no custom timestamp is specified on an object, the
210
+ # condition does not apply.
211
+ # @param [Integer] days_since_noncurrent_time Represents the number of
212
+ # days elapsed since the noncurrent timestamp of an object. The
213
+ # condition is satisfied if the days elapsed is at least this number.
214
+ # The value of the field must be a nonnegative integer. If it's zero,
215
+ # the object version will become eligible for Lifecycle action as
216
+ # soon as it becomes noncurrent. Relevant only for versioning-enabled
217
+ # buckets. (See {Bucket#versioning?})
158
218
  # @param [Boolean] is_live Relevant only for versioned files. If the
159
219
  # value is `true`, this condition matches live files; if the value
160
220
  # is `false`, it matches archived files.
161
221
  # @param [String,Symbol,Array<String,Symbol>] matches_storage_class
162
222
  # Files having any of the storage classes specified by this
163
- # condition will be matched. Values include `MULTI_REGIONAL`,
164
- # `REGIONAL`, `NEARLINE`, `COLDLINE`, `STANDARD`, and
165
- # `DURABLE_REDUCED_AVAILABILITY`. Arguments will be converted from
166
- # symbols and lower-case to upper-case strings.
223
+ # condition will be matched. Values include `STANDARD`, `NEARLINE`,
224
+ # `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`, and
225
+ # `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
226
+ # classes. Arguments will be converted from symbols and lower-case
227
+ # to upper-case strings.
228
+ # @param [String,Date] noncurrent_time_before A date in RFC 3339 format
229
+ # with only the date part (for instance, "2013-01-15"). This condition
230
+ # is satisfied when the noncurrent time on an object is before this
231
+ # date in UTC. This condition is relevant only for versioned objects.
167
232
  # @param [Integer] num_newer_versions Relevant only for versioned
168
233
  # files. If the value is N, this condition is satisfied when there
169
234
  # are at least N versions (including the live version) newer than
170
235
  # this version of the file.
236
+ # @param [Array<String,Symbol>] matches_prefix
237
+ # Files having their name with the specified list of prefixs will be matched.
238
+ # Arguments will be converted from symbols to strings.
239
+ # @param [Array<String,Symbol>] matches_suffix
240
+ # Files having their name with the specified list of suffixes will be matched.
241
+ # Arguments will be converted from symbols to strings.
171
242
  #
172
243
  # @example
173
244
  # require "google/cloud/storage"
@@ -178,14 +249,71 @@ module Google
178
249
  # b.lifecycle.add_delete_rule age: 30, is_live: false
179
250
  # end
180
251
  #
181
- def add_delete_rule age: nil, created_before: nil, is_live: nil,
252
+ def add_delete_rule age: nil,
253
+ created_before: nil,
254
+ custom_time_before: nil,
255
+ days_since_custom_time: nil,
256
+ days_since_noncurrent_time: nil,
257
+ is_live: nil,
182
258
  matches_storage_class: nil,
183
- num_newer_versions: nil
184
- push Rule.new \
259
+ noncurrent_time_before: nil,
260
+ num_newer_versions: nil,
261
+ matches_prefix: nil,
262
+ matches_suffix: nil
263
+ push Rule.new(
185
264
  "Delete",
186
- age: age, created_before: created_before, is_live: is_live,
265
+ age: age,
266
+ created_before: created_before,
267
+ custom_time_before: custom_time_before,
268
+ days_since_custom_time: days_since_custom_time,
269
+ days_since_noncurrent_time: days_since_noncurrent_time,
270
+ is_live: is_live,
187
271
  matches_storage_class: storage_class_for(matches_storage_class),
188
- num_newer_versions: num_newer_versions
272
+ noncurrent_time_before: noncurrent_time_before,
273
+ num_newer_versions: num_newer_versions,
274
+ matches_prefix: Array(matches_prefix),
275
+ matches_suffix: Array(matches_suffix)
276
+ )
277
+ end
278
+
279
+ ##
280
+ # Adds a AbortIncompleteMultipartUpload lifecycle rule to the Object Lifecycle
281
+ # Management rules for a bucket.
282
+ #
283
+ # @see https://cloud.google.com/storage/docs/lifecycle Object
284
+ # Lifecycle Management
285
+ # @see https://cloud.google.com/storage/docs/managing-lifecycles
286
+ # Managing Object Lifecycles
287
+ #
288
+ # @param [Integer] age The age of a file (in days). This condition is
289
+ # satisfied when a file reaches the specified age.
290
+ # @param [Array<String,Symbol>] matches_prefix
291
+ # Files having their name with the specified list of prefixs will be matched.
292
+ # Arguments will be converted from symbols to strings.
293
+ # @param [Array<String,Symbol>] matches_suffix
294
+ # Files having their name with the specified list of suffixes will be matched.
295
+ # Arguments will be converted from symbols to strings.
296
+ #
297
+ # @example
298
+ # require "google/cloud/storage"
299
+ #
300
+ # storage = Google::Cloud::Storage.new
301
+ #
302
+ # bucket = storage.create_bucket "my-bucket" do |b|
303
+ # b.lifecycle.add_abort_incomplete_multipart_upload_rule age: 10,
304
+ # matches_prefix: ["images/"],
305
+ # matches_suffix: [".pdf"]
306
+ # end
307
+ #
308
+ def add_abort_incomplete_multipart_upload_rule age: nil,
309
+ matches_prefix: nil,
310
+ matches_suffix: nil
311
+ push Rule.new(
312
+ "AbortIncompleteMultipartUpload",
313
+ age: age,
314
+ matches_prefix: Array(matches_prefix),
315
+ matches_suffix: Array(matches_suffix)
316
+ )
189
317
  end
190
318
 
191
319
  # @private
@@ -229,17 +357,40 @@ module Google
229
357
  # action. Required only if the action is `SetStorageClass`.
230
358
  # @attr [Integer] age The age of a file (in days). This condition is
231
359
  # satisfied when a file reaches the specified age.
232
- # @attr [String,Date] created_before A date in RFC 3339 format with
360
+ # @attr [String,Date,nil] created_before A date in RFC 3339 format with
233
361
  # only the date part (for instance, "2013-01-15"). This condition is
234
362
  # satisfied when a file is created before midnight of the specified
235
- # date in UTC.
363
+ # date in UTC. When returned by the service, a non-empty value will
364
+ # always be a Date object.
365
+ # @attr [String,Date,nil] custom_time_before A date in RFC 3339 format with
366
+ # only the date part (for instance, "2013-01-15"). This condition is
367
+ # satisfied when the custom time on an object is before this date in UTC.
368
+ # @attr [Integer,nil] days_since_custom_time Represents the number of
369
+ # days elapsed since the user-specified timestamp set on an object.
370
+ # The condition is satisfied if the days elapsed is at least this
371
+ # number. If no custom timestamp is specified on an object, the
372
+ # condition does not apply.
373
+ # @attr [Integer] days_since_noncurrent_time Represents the number of
374
+ # days elapsed since the noncurrent timestamp of an object. The
375
+ # condition is satisfied if the days elapsed is at least this number.
376
+ # The value of the field must be a nonnegative integer. If it's zero,
377
+ # the object version will become eligible for Lifecycle action as
378
+ # soon as it becomes noncurrent. Relevant only for versioning-enabled
379
+ # buckets. (See {Bucket#versioning?})
236
380
  # @attr [Boolean] is_live Relevant only for versioned files. If the
237
381
  # value is `true`, this condition matches live files; if the value
238
382
  # is `false`, it matches archived files.
239
383
  # @attr [Array<String>] matches_storage_class Files having any of the
240
384
  # storage classes specified by this condition will be matched.
241
- # Values include `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`,
242
- # `COLDLINE`, `STANDARD`, and `DURABLE_REDUCED_AVAILABILITY`.
385
+ # Values include `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`.
386
+ # `REGIONAL`, `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY`
387
+ # are supported as legacy storage classes.
388
+ # @attr [String,Date,nil] noncurrent_time_before A date in RFC 3339 format
389
+ # with only the date part (for instance, "2013-01-15"). This condition
390
+ # is satisfied when the noncurrent time on an object is before this
391
+ # date in UTC. This condition is relevant only for versioned objects.
392
+ # When returned by the service, a non-empty value will always be a
393
+ # Date object.
243
394
  # @attr [Integer] num_newer_versions Relevant only for versioned
244
395
  # files. If the value is N, this condition is satisfied when there
245
396
  # are at least N versions (including the live version) newer than
@@ -256,7 +407,9 @@ module Google
256
407
  # rule.action #=> "SetStorageClass"
257
408
  # rule.storage_class #=> "COLDLINE"
258
409
  # rule.age #=> 10
259
- # rule.matches_storage_class #=> ["MULTI_REGIONAL", "REGIONAL"]
410
+ # rule.matches_storage_class #=> ["STANDARD", "NEARLINE"]
411
+ # rule.matches_prefix #=> ["myprefix/foo"]
412
+ # rule.matches_suffix #=> [".jpg", ".png"]
260
413
  #
261
414
  # @example Updating the bucket's lifecycle rules in a block.
262
415
  # require "google/cloud/storage"
@@ -282,28 +435,65 @@ module Google
282
435
  # end
283
436
  #
284
437
  class Rule
285
- attr_accessor :action, :storage_class, :age, :created_before,
286
- :is_live, :matches_storage_class, :num_newer_versions
438
+ attr_accessor :action
439
+ attr_accessor :storage_class
440
+ attr_accessor :age
441
+ attr_accessor :created_before
442
+ attr_accessor :custom_time_before
443
+ attr_accessor :days_since_custom_time
444
+ attr_accessor :days_since_noncurrent_time
445
+ attr_accessor :is_live
446
+ attr_accessor :matches_storage_class
447
+ attr_accessor :noncurrent_time_before
448
+ attr_accessor :num_newer_versions
449
+ attr_accessor :matches_prefix
450
+ attr_accessor :matches_suffix
287
451
 
288
452
  # @private
289
- def initialize action, storage_class: nil, age: nil,
290
- created_before: nil, is_live: nil,
291
- matches_storage_class: nil, num_newer_versions: nil
453
+ def initialize action,
454
+ storage_class: nil,
455
+ age: nil,
456
+ created_before: nil,
457
+ custom_time_before: nil,
458
+ days_since_custom_time: nil,
459
+ days_since_noncurrent_time: nil,
460
+ is_live: nil,
461
+ matches_storage_class: nil,
462
+ noncurrent_time_before: nil,
463
+ num_newer_versions: nil,
464
+ matches_prefix: nil,
465
+ matches_suffix: nil
292
466
  @action = action
293
467
  @storage_class = storage_class
294
468
  @age = age
295
469
  @created_before = created_before
470
+ @custom_time_before = custom_time_before
471
+ @days_since_custom_time = days_since_custom_time
472
+ @days_since_noncurrent_time = days_since_noncurrent_time
296
473
  @is_live = is_live
297
474
  @matches_storage_class = Array(matches_storage_class)
475
+ @noncurrent_time_before = noncurrent_time_before
298
476
  @num_newer_versions = num_newer_versions
477
+ @matches_prefix = Array(matches_prefix)
478
+ @matches_suffix = Array(matches_suffix)
299
479
  end
300
480
 
301
481
  # @private
302
482
  # @return [Google::Apis::StorageV1::Bucket::Lifecycle]
303
483
  def to_gapi
304
- condition = condition_gapi(age, created_before, is_live,
305
- matches_storage_class,
306
- num_newer_versions)
484
+ condition = condition_gapi(
485
+ age,
486
+ created_before,
487
+ custom_time_before,
488
+ days_since_custom_time,
489
+ days_since_noncurrent_time,
490
+ is_live,
491
+ matches_storage_class,
492
+ noncurrent_time_before,
493
+ num_newer_versions,
494
+ matches_prefix,
495
+ matches_suffix
496
+ )
307
497
  Google::Apis::StorageV1::Bucket::Lifecycle::Rule.new(
308
498
  action: action_gapi(action, storage_class),
309
499
  condition: condition
@@ -313,19 +503,35 @@ module Google
313
503
  # @private
314
504
  def action_gapi action, storage_class
315
505
  Google::Apis::StorageV1::Bucket::Lifecycle::Rule::Action.new(
316
- type: action, storage_class: storage_class
506
+ type: action,
507
+ storage_class: storage_class
317
508
  )
318
509
  end
319
510
 
320
511
  # @private
321
- def condition_gapi age, created_before, is_live,
322
- matches_storage_class, num_newer_versions
512
+ def condition_gapi age,
513
+ created_before,
514
+ custom_time_before,
515
+ days_since_custom_time,
516
+ days_since_noncurrent_time,
517
+ is_live,
518
+ matches_storage_class,
519
+ noncurrent_time_before,
520
+ num_newer_versions,
521
+ matches_prefix,
522
+ matches_suffix
323
523
  Google::Apis::StorageV1::Bucket::Lifecycle::Rule::Condition.new(
324
524
  age: age,
325
525
  created_before: created_before,
526
+ custom_time_before: custom_time_before,
527
+ days_since_custom_time: days_since_custom_time,
528
+ days_since_noncurrent_time: days_since_noncurrent_time,
326
529
  is_live: is_live,
327
530
  matches_storage_class: Array(matches_storage_class),
328
- num_newer_versions: num_newer_versions
531
+ noncurrent_time_before: noncurrent_time_before,
532
+ num_newer_versions: num_newer_versions,
533
+ matches_prefix: Array(matches_prefix),
534
+ matches_suffix: Array(matches_suffix)
329
535
  )
330
536
  end
331
537
 
@@ -334,12 +540,21 @@ module Google
334
540
  def self.from_gapi gapi
335
541
  action = gapi.action
336
542
  c = gapi.condition
337
- new action.type, storage_class: action.storage_class,
338
- age: c.age,
339
- created_before: c.created_before,
340
- is_live: c.is_live,
341
- matches_storage_class: c.matches_storage_class,
342
- num_newer_versions: c.num_newer_versions
543
+ new(
544
+ action.type,
545
+ storage_class: action.storage_class,
546
+ age: c.age,
547
+ created_before: c.created_before,
548
+ custom_time_before: c.custom_time_before,
549
+ days_since_custom_time: c.days_since_custom_time,
550
+ days_since_noncurrent_time: c.days_since_noncurrent_time,
551
+ is_live: c.is_live,
552
+ matches_storage_class: c.matches_storage_class,
553
+ noncurrent_time_before: c.noncurrent_time_before,
554
+ num_newer_versions: c.num_newer_versions,
555
+ matches_prefix: c.matches_prefix,
556
+ matches_suffix: c.matches_suffix
557
+ )
343
558
  end
344
559
 
345
560
  # @private