google-cloud-storage 1.31.1 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -297,6 +297,22 @@ module Google
297
297
  # Convenience method to apply the `authenticatedRead` predefined ACL
298
298
  # rule to the file.
299
299
  #
300
+ # @param [Integer] generation Select a specific revision of the file to
301
+ # update. The default is the latest version.
302
+ # @param [Integer] if_generation_match Makes the operation conditional
303
+ # on whether the file's current generation matches the given value.
304
+ # Setting to 0 makes the operation succeed only if there are no live
305
+ # versions of the file.
306
+ # @param [Integer] if_generation_not_match Makes the operation conditional
307
+ # on whether the file's current generation does not match the given
308
+ # value. If no live file exists, the precondition fails. Setting to 0
309
+ # makes the operation succeed only if there is a live version of the file.
310
+ # @param [Integer] if_metageneration_match Makes the operation conditional
311
+ # on whether the file's current metageneration matches the given value.
312
+ # @param [Integer] if_metageneration_not_match Makes the operation
313
+ # conditional on whether the file's current metageneration does not
314
+ # match the given value.
315
+ #
300
316
  # @example
301
317
  # require "google/cloud/storage"
302
318
  #
@@ -307,8 +323,17 @@ module Google
307
323
  # file = bucket.file "path/to/my-file.ext"
308
324
  # file.acl.auth!
309
325
  #
310
- def auth!
311
- update_predefined_acl! "authenticatedRead"
326
+ def auth! generation: nil,
327
+ if_generation_match: nil,
328
+ if_generation_not_match: nil,
329
+ if_metageneration_match: nil,
330
+ if_metageneration_not_match: nil
331
+ update_predefined_acl! "authenticatedRead",
332
+ generation: generation,
333
+ if_generation_match: if_generation_match,
334
+ if_generation_not_match: if_generation_not_match,
335
+ if_metageneration_match: if_metageneration_match,
336
+ if_metageneration_not_match: if_metageneration_not_match
312
337
  end
313
338
  alias authenticatedRead! auth!
314
339
  alias auth_read! auth!
@@ -319,6 +344,22 @@ module Google
319
344
  # Convenience method to apply the `bucketOwnerFullControl` predefined
320
345
  # ACL rule to the file.
321
346
  #
347
+ # @param [Integer] generation Select a specific revision of the file to
348
+ # update. The default is the latest version.
349
+ # @param [Integer] if_generation_match Makes the operation conditional
350
+ # on whether the file's current generation matches the given value.
351
+ # Setting to 0 makes the operation succeed only if there are no live
352
+ # versions of the file.
353
+ # @param [Integer] if_generation_not_match Makes the operation conditional
354
+ # on whether the file's current generation does not match the given
355
+ # value. If no live file exists, the precondition fails. Setting to 0
356
+ # makes the operation succeed only if there is a live version of the file.
357
+ # @param [Integer] if_metageneration_match Makes the operation conditional
358
+ # on whether the file's current metageneration matches the given value.
359
+ # @param [Integer] if_metageneration_not_match Makes the operation
360
+ # conditional on whether the file's current metageneration does not
361
+ # match the given value.
362
+ #
322
363
  # @example
323
364
  # require "google/cloud/storage"
324
365
  #
@@ -329,8 +370,17 @@ module Google
329
370
  # file = bucket.file "path/to/my-file.ext"
330
371
  # file.acl.owner_full!
331
372
  #
332
- def owner_full!
333
- update_predefined_acl! "bucketOwnerFullControl"
373
+ def owner_full! generation: nil,
374
+ if_generation_match: nil,
375
+ if_generation_not_match: nil,
376
+ if_metageneration_match: nil,
377
+ if_metageneration_not_match: nil
378
+ update_predefined_acl! "bucketOwnerFullControl",
379
+ generation: generation,
380
+ if_generation_match: if_generation_match,
381
+ if_generation_not_match: if_generation_not_match,
382
+ if_metageneration_match: if_metageneration_match,
383
+ if_metageneration_not_match: if_metageneration_not_match
334
384
  end
335
385
  alias bucketOwnerFullControl! owner_full!
336
386
 
@@ -338,6 +388,22 @@ module Google
338
388
  # Convenience method to apply the `bucketOwnerRead` predefined ACL
339
389
  # rule to the file.
340
390
  #
391
+ # @param [Integer] generation Select a specific revision of the file to
392
+ # update. The default is the latest version.
393
+ # @param [Integer] if_generation_match Makes the operation conditional
394
+ # on whether the file's current generation matches the given value.
395
+ # Setting to 0 makes the operation succeed only if there are no live
396
+ # versions of the file.
397
+ # @param [Integer] if_generation_not_match Makes the operation conditional
398
+ # on whether the file's current generation does not match the given
399
+ # value. If no live file exists, the precondition fails. Setting to 0
400
+ # makes the operation succeed only if there is a live version of the file.
401
+ # @param [Integer] if_metageneration_match Makes the operation conditional
402
+ # on whether the file's current metageneration matches the given value.
403
+ # @param [Integer] if_metageneration_not_match Makes the operation
404
+ # conditional on whether the file's current metageneration does not
405
+ # match the given value.
406
+ #
341
407
  # @example
342
408
  # require "google/cloud/storage"
343
409
  #
@@ -348,8 +414,17 @@ module Google
348
414
  # file = bucket.file "path/to/my-file.ext"
349
415
  # file.acl.owner_read!
350
416
  #
351
- def owner_read!
352
- update_predefined_acl! "bucketOwnerRead"
417
+ def owner_read! generation: nil,
418
+ if_generation_match: nil,
419
+ if_generation_not_match: nil,
420
+ if_metageneration_match: nil,
421
+ if_metageneration_not_match: nil
422
+ update_predefined_acl! "bucketOwnerRead",
423
+ generation: generation,
424
+ if_generation_match: if_generation_match,
425
+ if_generation_not_match: if_generation_not_match,
426
+ if_metageneration_match: if_metageneration_match,
427
+ if_metageneration_not_match: if_metageneration_not_match
353
428
  end
354
429
  alias bucketOwnerRead! owner_read!
355
430
 
@@ -357,6 +432,22 @@ module Google
357
432
  # Convenience method to apply the `private` predefined ACL
358
433
  # rule to the file.
359
434
  #
435
+ # @param [Integer] generation Select a specific revision of the file to
436
+ # update. The default is the latest version.
437
+ # @param [Integer] if_generation_match Makes the operation conditional
438
+ # on whether the file's current generation matches the given value.
439
+ # Setting to 0 makes the operation succeed only if there are no live
440
+ # versions of the file.
441
+ # @param [Integer] if_generation_not_match Makes the operation conditional
442
+ # on whether the file's current generation does not match the given
443
+ # value. If no live file exists, the precondition fails. Setting to 0
444
+ # makes the operation succeed only if there is a live version of the file.
445
+ # @param [Integer] if_metageneration_match Makes the operation conditional
446
+ # on whether the file's current metageneration matches the given value.
447
+ # @param [Integer] if_metageneration_not_match Makes the operation
448
+ # conditional on whether the file's current metageneration does not
449
+ # match the given value.
450
+ #
360
451
  # @example
361
452
  # require "google/cloud/storage"
362
453
  #
@@ -367,14 +458,39 @@ module Google
367
458
  # file = bucket.file "path/to/my-file.ext"
368
459
  # file.acl.private!
369
460
  #
370
- def private!
371
- update_predefined_acl! "private"
461
+ def private! generation: nil,
462
+ if_generation_match: nil,
463
+ if_generation_not_match: nil,
464
+ if_metageneration_match: nil,
465
+ if_metageneration_not_match: nil
466
+ update_predefined_acl! "private",
467
+ generation: generation,
468
+ if_generation_match: if_generation_match,
469
+ if_generation_not_match: if_generation_not_match,
470
+ if_metageneration_match: if_metageneration_match,
471
+ if_metageneration_not_match: if_metageneration_not_match
372
472
  end
373
473
 
374
474
  ##
375
475
  # Convenience method to apply the `projectPrivate` predefined ACL
376
476
  # rule to the file.
377
477
  #
478
+ # @param [Integer] generation Select a specific revision of the file to
479
+ # update. The default is the latest version.
480
+ # @param [Integer] if_generation_match Makes the operation conditional
481
+ # on whether the file's current generation matches the given value.
482
+ # Setting to 0 makes the operation succeed only if there are no live
483
+ # versions of the file.
484
+ # @param [Integer] if_generation_not_match Makes the operation conditional
485
+ # on whether the file's current generation does not match the given
486
+ # value. If no live file exists, the precondition fails. Setting to 0
487
+ # makes the operation succeed only if there is a live version of the file.
488
+ # @param [Integer] if_metageneration_match Makes the operation conditional
489
+ # on whether the file's current metageneration matches the given value.
490
+ # @param [Integer] if_metageneration_not_match Makes the operation
491
+ # conditional on whether the file's current metageneration does not
492
+ # match the given value.
493
+ #
378
494
  # @example
379
495
  # require "google/cloud/storage"
380
496
  #
@@ -385,8 +501,17 @@ module Google
385
501
  # file = bucket.file "path/to/my-file.ext"
386
502
  # file.acl.project_private!
387
503
  #
388
- def project_private!
389
- update_predefined_acl! "projectPrivate"
504
+ def project_private! generation: nil,
505
+ if_generation_match: nil,
506
+ if_generation_not_match: nil,
507
+ if_metageneration_match: nil,
508
+ if_metageneration_not_match: nil
509
+ update_predefined_acl! "projectPrivate",
510
+ generation: generation,
511
+ if_generation_match: if_generation_match,
512
+ if_generation_not_match: if_generation_not_match,
513
+ if_metageneration_match: if_metageneration_match,
514
+ if_metageneration_not_match: if_metageneration_not_match
390
515
  end
391
516
  alias projectPrivate! project_private!
392
517
 
@@ -394,6 +519,22 @@ module Google
394
519
  # Convenience method to apply the `publicRead` predefined ACL
395
520
  # rule to the file.
396
521
  #
522
+ # @param [Integer] generation Select a specific revision of the file to
523
+ # update. The default is the latest version.
524
+ # @param [Integer] if_generation_match Makes the operation conditional
525
+ # on whether the file's current generation matches the given value.
526
+ # Setting to 0 makes the operation succeed only if there are no live
527
+ # versions of the file.
528
+ # @param [Integer] if_generation_not_match Makes the operation conditional
529
+ # on whether the file's current generation does not match the given
530
+ # value. If no live file exists, the precondition fails. Setting to 0
531
+ # makes the operation succeed only if there is a live version of the file.
532
+ # @param [Integer] if_metageneration_match Makes the operation conditional
533
+ # on whether the file's current metageneration matches the given value.
534
+ # @param [Integer] if_metageneration_not_match Makes the operation
535
+ # conditional on whether the file's current metageneration does not
536
+ # match the given value.
537
+ #
397
538
  # @example
398
539
  # require "google/cloud/storage"
399
540
  #
@@ -404,8 +545,17 @@ module Google
404
545
  # file = bucket.file "path/to/my-file.ext"
405
546
  # file.acl.public!
406
547
  #
407
- def public!
408
- update_predefined_acl! "publicRead"
548
+ def public! generation: nil,
549
+ if_generation_match: nil,
550
+ if_generation_not_match: nil,
551
+ if_metageneration_match: nil,
552
+ if_metageneration_not_match: nil
553
+ update_predefined_acl! "publicRead",
554
+ generation: generation,
555
+ if_generation_match: if_generation_match,
556
+ if_generation_not_match: if_generation_not_match,
557
+ if_metageneration_match: if_metageneration_match,
558
+ if_metageneration_not_match: if_metageneration_not_match
409
559
  end
410
560
  alias publicRead! public!
411
561
  alias public_read! public!
@@ -418,9 +568,21 @@ module Google
418
568
  self
419
569
  end
420
570
 
421
- def update_predefined_acl! acl_role
571
+ def update_predefined_acl! acl_role,
572
+ generation: nil,
573
+ if_generation_match: nil,
574
+ if_generation_not_match: nil,
575
+ if_metageneration_match: nil,
576
+ if_metageneration_not_match: nil
422
577
  patched_file = Google::Apis::StorageV1::Object.new acl: []
423
- @service.patch_file @bucket, @file, patched_file,
578
+ @service.patch_file @bucket,
579
+ @file,
580
+ patched_file,
581
+ generation: generation,
582
+ if_generation_match: if_generation_match,
583
+ if_generation_not_match: if_generation_not_match,
584
+ if_metageneration_match: if_metageneration_match,
585
+ if_metageneration_not_match: if_metageneration_not_match,
424
586
  predefined_acl: acl_role,
425
587
  user_project: user_project
426
588
  clear!
@@ -50,7 +50,7 @@ module Google
50
50
  end
51
51
 
52
52
  def self.md5_for local_file
53
- if local_file.respond_to? :path
53
+ if local_file.respond_to? :to_path
54
54
  ::File.open Pathname(local_file).to_path, "rb" do |f|
55
55
  ::Digest::MD5.file(f).base64digest
56
56
  end
@@ -63,7 +63,7 @@ module Google
63
63
  end
64
64
 
65
65
  def self.crc32c_for local_file
66
- if local_file.respond_to? :path
66
+ if local_file.respond_to? :to_path
67
67
  ::File.open Pathname(local_file).to_path, "rb" do |f|
68
68
  ::Digest::CRC32c.file(f).base64digest
69
69
  end
@@ -165,6 +165,11 @@ module Google
165
165
  # without verifying the bucket resource exists on the Storage service.
166
166
  # Calls made on this object will raise errors if the bucket resource
167
167
  # does not exist. Default is `false`.
168
+ # @param [Integer] if_metageneration_match Makes the operation conditional
169
+ # on whether the bucket's current metageneration matches the given value.
170
+ # @param [Integer] if_metageneration_not_match Makes the operation
171
+ # conditional on whether the bucket's current metageneration does not
172
+ # match the given value.
168
173
  # @param [Boolean, String] user_project If this parameter is set to
169
174
  # `true`, transit costs for operations on the requested bucket or a
170
175
  # file it contains will be billed to the current project for this
@@ -208,12 +213,19 @@ module Google
208
213
  # user_project: "my-other-project"
209
214
  # files = bucket.files # Billed to "my-other-project"
210
215
  #
211
- def bucket bucket_name, skip_lookup: false, user_project: nil
216
+ def bucket bucket_name,
217
+ skip_lookup: false,
218
+ if_metageneration_match: nil,
219
+ if_metageneration_not_match: nil,
220
+ user_project: nil
212
221
  if skip_lookup
213
222
  return Bucket.new_lazy bucket_name, service,
214
223
  user_project: user_project
215
224
  end
216
- gapi = service.get_bucket bucket_name, user_project: user_project
225
+ gapi = service.get_bucket bucket_name,
226
+ if_metageneration_match: if_metageneration_match,
227
+ if_metageneration_not_match: if_metageneration_not_match,
228
+ user_project: user_project
217
229
  Bucket.from_gapi gapi, service, user_project: user_project
218
230
  rescue Google::Cloud::NotFoundError
219
231
  nil
@@ -83,9 +83,14 @@ module Google
83
83
  ##
84
84
  # Retrieves bucket by name.
85
85
  # Returns Google::Apis::StorageV1::Bucket.
86
- def get_bucket bucket_name, user_project: nil
86
+ def get_bucket bucket_name,
87
+ if_metageneration_match: nil,
88
+ if_metageneration_not_match: nil,
89
+ user_project: nil
87
90
  execute do
88
91
  service.get_bucket bucket_name,
92
+ if_metageneration_match: if_metageneration_match,
93
+ if_metageneration_not_match: if_metageneration_not_match,
89
94
  user_project: user_project(user_project)
90
95
  end
91
96
  end
@@ -106,26 +111,38 @@ module Google
106
111
 
107
112
  ##
108
113
  # Updates a bucket, including its ACL metadata.
109
- def patch_bucket bucket_name, bucket_gapi = nil, predefined_acl: nil,
110
- predefined_default_acl: nil, user_project: nil
114
+ def patch_bucket bucket_name,
115
+ bucket_gapi = nil,
116
+ predefined_acl: nil,
117
+ predefined_default_acl: nil,
118
+ if_metageneration_match: nil,
119
+ if_metageneration_not_match: nil,
120
+ user_project: nil
111
121
  bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
112
122
  bucket_gapi.acl = [] if predefined_acl
113
123
  bucket_gapi.default_object_acl = [] if predefined_default_acl
114
124
 
115
125
  execute do
116
- service.patch_bucket \
117
- bucket_name, bucket_gapi,
118
- predefined_acl: predefined_acl,
119
- predefined_default_object_acl: predefined_default_acl,
120
- user_project: user_project(user_project)
126
+ service.patch_bucket bucket_name,
127
+ bucket_gapi,
128
+ predefined_acl: predefined_acl,
129
+ predefined_default_object_acl: predefined_default_acl,
130
+ if_metageneration_match: if_metageneration_match,
131
+ if_metageneration_not_match: if_metageneration_not_match,
132
+ user_project: user_project(user_project)
121
133
  end
122
134
  end
123
135
 
124
136
  ##
125
137
  # Permanently deletes an empty bucket.
126
- def delete_bucket bucket_name, user_project: nil
138
+ def delete_bucket bucket_name,
139
+ if_metageneration_match: nil,
140
+ if_metageneration_not_match: nil,
141
+ user_project: nil
127
142
  execute do
128
143
  service.delete_bucket bucket_name,
144
+ if_metageneration_match: if_metageneration_match,
145
+ if_metageneration_not_match: if_metageneration_not_match,
129
146
  user_project: user_project(user_project)
130
147
  end
131
148
  end
@@ -290,41 +307,83 @@ module Google
290
307
 
291
308
  ##
292
309
  # Inserts a new file for the given bucket
293
- def insert_file bucket_name, source, path = nil, acl: nil,
294
- cache_control: nil, content_disposition: nil,
295
- content_encoding: nil, content_language: nil,
296
- content_type: nil, custom_time: nil, crc32c: nil, md5: nil, metadata: nil,
297
- storage_class: nil, key: nil, kms_key: nil,
298
- temporary_hold: nil, event_based_hold: nil,
310
+ def insert_file bucket_name,
311
+ source,
312
+ path = nil,
313
+ acl: nil,
314
+ cache_control: nil,
315
+ content_disposition: nil,
316
+ content_encoding: nil,
317
+ content_language: nil,
318
+ content_type: nil,
319
+ custom_time: nil,
320
+ crc32c: nil,
321
+ md5: nil,
322
+ metadata: nil,
323
+ storage_class: nil,
324
+ key: nil,
325
+ kms_key: nil,
326
+ temporary_hold: nil,
327
+ event_based_hold: nil,
328
+ if_generation_match: nil,
329
+ if_generation_not_match: nil,
330
+ if_metageneration_match: nil,
331
+ if_metageneration_not_match: nil,
299
332
  user_project: nil
300
- params =
301
- { cache_control: cache_control, content_type: content_type, custom_time: custom_time,
302
- content_disposition: content_disposition, md5_hash: md5,
303
- content_encoding: content_encoding, crc32c: crc32c,
304
- content_language: content_language, metadata: metadata,
305
- storage_class: storage_class, temporary_hold: temporary_hold,
306
- event_based_hold: event_based_hold }.delete_if { |_k, v| v.nil? }
333
+ params = {
334
+ cache_control: cache_control,
335
+ content_type: content_type,
336
+ custom_time: custom_time,
337
+ content_disposition: content_disposition,
338
+ md5_hash: md5,
339
+ content_encoding: content_encoding,
340
+ crc32c: crc32c,
341
+ content_language: content_language,
342
+ metadata: metadata,
343
+ storage_class: storage_class,
344
+ temporary_hold: temporary_hold,
345
+ event_based_hold: event_based_hold
346
+ }.delete_if { |_k, v| v.nil? }
307
347
  file_obj = Google::Apis::StorageV1::Object.new(**params)
308
348
  content_type ||= mime_type_for(path || Pathname(source).to_path)
309
349
 
310
350
  execute do
311
- service.insert_object \
312
- bucket_name, file_obj,
313
- name: path, predefined_acl: acl, upload_source: source,
314
- content_encoding: content_encoding, content_type: content_type,
315
- kms_key_name: kms_key, user_project: user_project(user_project),
316
- options: key_options(key)
351
+ service.insert_object bucket_name,
352
+ file_obj,
353
+ name: path,
354
+ predefined_acl: acl,
355
+ upload_source: source,
356
+ content_encoding: content_encoding,
357
+ content_type: content_type,
358
+ if_generation_match: if_generation_match,
359
+ if_generation_not_match: if_generation_not_match,
360
+ if_metageneration_match: if_metageneration_match,
361
+ if_metageneration_not_match: if_metageneration_not_match,
362
+ kms_key_name: kms_key,
363
+ user_project: user_project(user_project),
364
+ options: key_options(key)
317
365
  end
318
366
  end
319
367
 
320
368
  ##
321
369
  # Retrieves an object or its metadata.
322
- def get_file bucket_name, file_path, generation: nil, key: nil,
370
+ def get_file bucket_name,
371
+ file_path,
372
+ generation: nil,
373
+ if_generation_match: nil,
374
+ if_generation_not_match: nil,
375
+ if_metageneration_match: nil,
376
+ if_metageneration_not_match: nil,
377
+ key: nil,
323
378
  user_project: nil
324
379
  execute do
325
380
  service.get_object \
326
381
  bucket_name, file_path,
327
382
  generation: generation,
383
+ if_generation_match: if_generation_match,
384
+ if_generation_not_match: if_generation_not_match,
385
+ if_metageneration_match: if_metageneration_match,
386
+ if_metageneration_not_match: if_metageneration_not_match,
328
387
  user_project: user_project(user_project),
329
388
  options: key_options(key)
330
389
  end
@@ -332,42 +391,76 @@ module Google
332
391
 
333
392
  ## Rewrite a file from source bucket/object to a
334
393
  # destination bucket/object.
335
- def rewrite_file source_bucket_name, source_file_path,
336
- destination_bucket_name, destination_file_path,
337
- file_gapi = nil, source_key: nil, destination_key: nil,
338
- destination_kms_key: nil, acl: nil, generation: nil,
339
- token: nil, user_project: nil
394
+ def rewrite_file source_bucket_name,
395
+ source_file_path,
396
+ destination_bucket_name,
397
+ destination_file_path,
398
+ file_gapi = nil,
399
+ source_key: nil,
400
+ destination_key: nil,
401
+ destination_kms_key: nil,
402
+ acl: nil,
403
+ generation: nil,
404
+ if_generation_match: nil,
405
+ if_generation_not_match: nil,
406
+ if_metageneration_match: nil,
407
+ if_metageneration_not_match: nil,
408
+ if_source_generation_match: nil,
409
+ if_source_generation_not_match: nil,
410
+ if_source_metageneration_match: nil,
411
+ if_source_metageneration_not_match: nil,
412
+ token: nil,
413
+ user_project: nil
340
414
  key_options = rewrite_key_options source_key, destination_key
341
415
  execute do
342
- service.rewrite_object \
343
- source_bucket_name, source_file_path,
344
- destination_bucket_name, destination_file_path,
345
- file_gapi,
346
- destination_kms_key_name: destination_kms_key,
347
- destination_predefined_acl: acl,
348
- source_generation: generation,
349
- rewrite_token: token,
350
- user_project: user_project(user_project),
351
- options: key_options
416
+ service.rewrite_object source_bucket_name,
417
+ source_file_path,
418
+ destination_bucket_name,
419
+ destination_file_path,
420
+ file_gapi,
421
+ destination_kms_key_name: destination_kms_key,
422
+ destination_predefined_acl: acl,
423
+ source_generation: generation,
424
+ if_generation_match: if_generation_match,
425
+ if_generation_not_match: if_generation_not_match,
426
+ if_metageneration_match: if_metageneration_match,
427
+ if_metageneration_not_match: if_metageneration_not_match,
428
+ if_source_generation_match: if_source_generation_match,
429
+ if_source_generation_not_match: if_source_generation_not_match,
430
+ if_source_metageneration_match: if_source_metageneration_match,
431
+ if_source_metageneration_not_match: if_source_metageneration_not_match,
432
+ rewrite_token: token,
433
+ user_project: user_project(user_project),
434
+ options: key_options
352
435
  end
353
436
  end
354
437
 
355
438
  ## Copy a file from source bucket/object to a
356
439
  # destination bucket/object.
357
- def compose_file bucket_name, source_files, destination_path,
358
- destination_gapi, acl: nil, key: nil, user_project: nil
440
+ def compose_file bucket_name,
441
+ source_files,
442
+ destination_path,
443
+ destination_gapi,
444
+ acl: nil,
445
+ key: nil,
446
+ if_source_generation_match: nil,
447
+ if_generation_match: nil,
448
+ if_metageneration_match: nil,
449
+ user_project: nil
359
450
 
360
- compose_req = Google::Apis::StorageV1::ComposeRequest.new \
361
- source_objects: compose_file_source_objects(source_files),
362
- destination: destination_gapi
451
+ source_objects = compose_file_source_objects source_files, if_source_generation_match
452
+ compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
453
+ destination: destination_gapi
363
454
 
364
455
  execute do
365
- service.compose_object \
366
- bucket_name, destination_path,
367
- compose_req,
368
- destination_predefined_acl: acl,
369
- user_project: user_project(user_project),
370
- options: key_options(key)
456
+ service.compose_object bucket_name,
457
+ destination_path,
458
+ compose_req,
459
+ destination_predefined_acl: acl,
460
+ if_generation_match: if_generation_match,
461
+ if_metageneration_match: if_metageneration_match,
462
+ user_project: user_project(user_project),
463
+ options: key_options(key)
371
464
  end
372
465
  end
373
466
 
@@ -396,24 +489,48 @@ module Google
396
489
 
397
490
  ##
398
491
  # Updates a file's metadata.
399
- def patch_file bucket_name, file_path, file_gapi = nil,
400
- predefined_acl: nil, user_project: nil
492
+ def patch_file bucket_name,
493
+ file_path,
494
+ file_gapi = nil,
495
+ generation: nil,
496
+ if_generation_match: nil,
497
+ if_generation_not_match: nil,
498
+ if_metageneration_match: nil,
499
+ if_metageneration_not_match: nil,
500
+ predefined_acl: nil,
501
+ user_project: nil
401
502
  file_gapi ||= Google::Apis::StorageV1::Object.new
402
503
  execute do
403
- service.patch_object \
404
- bucket_name, file_path, file_gapi,
405
- predefined_acl: predefined_acl,
406
- user_project: user_project(user_project)
504
+ service.patch_object bucket_name,
505
+ file_path,
506
+ file_gapi,
507
+ generation: generation,
508
+ if_generation_match: if_generation_match,
509
+ if_generation_not_match: if_generation_not_match,
510
+ if_metageneration_match: if_metageneration_match,
511
+ if_metageneration_not_match: if_metageneration_not_match,
512
+ predefined_acl: predefined_acl,
513
+ user_project: user_project(user_project)
407
514
  end
408
515
  end
409
516
 
410
517
  ##
411
518
  # Permanently deletes a file.
412
- def delete_file bucket_name, file_path, generation: nil,
519
+ def delete_file bucket_name,
520
+ file_path,
521
+ generation: nil,
522
+ if_generation_match: nil,
523
+ if_generation_not_match: nil,
524
+ if_metageneration_match: nil,
525
+ if_metageneration_not_match: nil,
413
526
  user_project: nil
414
527
  execute do
415
528
  service.delete_object bucket_name, file_path,
416
529
  generation: generation,
530
+ if_generation_match: if_generation_match,
531
+ if_generation_not_match: if_generation_not_match,
532
+ if_metageneration_match: if_metageneration_match,
533
+ if_metageneration_not_match: if_metageneration_not_match,
417
534
  user_project: user_project(user_project)
418
535
  end
419
536
  end
@@ -615,8 +732,8 @@ module Google
615
732
  "false" => "NONE" }[str_or_bool.to_s.downcase]
616
733
  end
617
734
 
618
- def compose_file_source_objects source_files
619
- source_files.map do |file|
735
+ def compose_file_source_objects source_files, if_source_generation_match
736
+ source_objects = source_files.map do |file|
620
737
  if file.is_a? Google::Cloud::Storage::File
621
738
  Google::Apis::StorageV1::ComposeRequest::SourceObject.new \
622
739
  name: file.name,
@@ -626,6 +743,18 @@ module Google
626
743
  name: file
627
744
  end
628
745
  end
746
+ return source_objects unless if_source_generation_match
747
+ if source_files.count != if_source_generation_match.count
748
+ raise ArgumentError, "if provided, if_source_generation_match length must match sources length"
749
+ end
750
+ if_source_generation_match.each_with_index do |generation, i|
751
+ next unless generation
752
+ object_preconditions = Google::Apis::StorageV1::ComposeRequest::SourceObject::ObjectPreconditions.new(
753
+ if_generation_match: generation
754
+ )
755
+ source_objects[i].object_preconditions = object_preconditions
756
+ end
757
+ source_objects
629
758
  end
630
759
 
631
760
  def execute