google-cloud-storage 1.44.0 → 1.54.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.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +8 -26
- data/CHANGELOG.md +70 -0
- data/lib/google/cloud/storage/bucket/cors.rb +2 -2
- data/lib/google/cloud/storage/bucket.rb +261 -12
- data/lib/google/cloud/storage/file/list.rb +10 -3
- data/lib/google/cloud/storage/file/signer_v2.rb +5 -4
- data/lib/google/cloud/storage/file/signer_v4.rb +5 -5
- data/lib/google/cloud/storage/file.rb +141 -10
- data/lib/google/cloud/storage/project.rb +63 -3
- data/lib/google/cloud/storage/service.rb +74 -7
- data/lib/google/cloud/storage/version.rb +1 -1
- data/lib/google/cloud/storage.rb +23 -8
- data/lib/google-cloud-storage.rb +24 -16
- metadata +28 -20
|
@@ -763,6 +763,30 @@ module Google
|
|
|
763
763
|
@gapi.retention_expiration_time
|
|
764
764
|
end
|
|
765
765
|
|
|
766
|
+
##
|
|
767
|
+
# This soft delete time is the time when the object became
|
|
768
|
+
# soft-deleted.
|
|
769
|
+
#
|
|
770
|
+
# @return [DateTime, nil] A DateTime representing the time at
|
|
771
|
+
# which the object became soft-deleted, or `nil` if the file was
|
|
772
|
+
# not deleted.
|
|
773
|
+
#
|
|
774
|
+
def soft_delete_time
|
|
775
|
+
@gapi.soft_delete_time
|
|
776
|
+
end
|
|
777
|
+
|
|
778
|
+
##
|
|
779
|
+
# This hard delete time is The time when the file will be permanently
|
|
780
|
+
# deleted.
|
|
781
|
+
#
|
|
782
|
+
# @return [DateTime, nil] A DateTime representing the time at
|
|
783
|
+
# which the file will be permanently deleted, or `nil` if the file is
|
|
784
|
+
# not soft deleted.
|
|
785
|
+
#
|
|
786
|
+
def hard_delete_time
|
|
787
|
+
@gapi.hard_delete_time
|
|
788
|
+
end
|
|
789
|
+
|
|
766
790
|
##
|
|
767
791
|
# Retrieves a list of versioned files for the current object.
|
|
768
792
|
#
|
|
@@ -825,6 +849,9 @@ module Google
|
|
|
825
849
|
# @param [Integer] if_metageneration_not_match Makes the operation
|
|
826
850
|
# conditional on whether the file's current metageneration does not
|
|
827
851
|
# match the given value.
|
|
852
|
+
# @param [Boolean] override_unlocked_retention
|
|
853
|
+
# Must be true to remove the retention configuration, reduce its unlocked
|
|
854
|
+
# retention period, or change its mode from unlocked to locked.
|
|
828
855
|
#
|
|
829
856
|
# @yield [file] a block yielding a delegate object for updating the file
|
|
830
857
|
#
|
|
@@ -865,7 +892,8 @@ module Google
|
|
|
865
892
|
if_generation_match: nil,
|
|
866
893
|
if_generation_not_match: nil,
|
|
867
894
|
if_metageneration_match: nil,
|
|
868
|
-
if_metageneration_not_match: nil
|
|
895
|
+
if_metageneration_not_match: nil,
|
|
896
|
+
override_unlocked_retention: nil
|
|
869
897
|
updater = Updater.new gapi
|
|
870
898
|
yield updater
|
|
871
899
|
updater.check_for_changed_metadata!
|
|
@@ -875,7 +903,8 @@ module Google
|
|
|
875
903
|
if_generation_match: if_generation_match,
|
|
876
904
|
if_generation_not_match: if_generation_not_match,
|
|
877
905
|
if_metageneration_match: if_metageneration_match,
|
|
878
|
-
if_metageneration_not_match: if_metageneration_not_match
|
|
906
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
|
907
|
+
override_unlocked_retention: override_unlocked_retention
|
|
879
908
|
end
|
|
880
909
|
|
|
881
910
|
##
|
|
@@ -1560,6 +1589,64 @@ module Google
|
|
|
1560
1589
|
true
|
|
1561
1590
|
end
|
|
1562
1591
|
|
|
1592
|
+
# Mode of object level retention configuration.
|
|
1593
|
+
# Valid values are 'Locked' or 'Unlocked'
|
|
1594
|
+
#
|
|
1595
|
+
# @return [String]
|
|
1596
|
+
def retention_mode
|
|
1597
|
+
@gapi.retention&.mode
|
|
1598
|
+
end
|
|
1599
|
+
|
|
1600
|
+
# The earliest time in RFC 3339 UTC "Zulu" format that the object can
|
|
1601
|
+
# be deleted or replaced.
|
|
1602
|
+
#
|
|
1603
|
+
# @return [DateTime]
|
|
1604
|
+
def retention_retain_until_time
|
|
1605
|
+
@gapi.retention&.retain_until_time
|
|
1606
|
+
end
|
|
1607
|
+
|
|
1608
|
+
# A collection of object level retention parameters.
|
|
1609
|
+
# The full list of available options are outlined at the [JSON API docs]
|
|
1610
|
+
# (https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request-body).
|
|
1611
|
+
#
|
|
1612
|
+
# @return [Google::Apis::StorageV1::Object::Retention]
|
|
1613
|
+
def retention
|
|
1614
|
+
@gapi.retention
|
|
1615
|
+
end
|
|
1616
|
+
|
|
1617
|
+
##
|
|
1618
|
+
# Update method to update retention parameter of an object / file
|
|
1619
|
+
# It accepts params as a Hash of attributes in the following format:
|
|
1620
|
+
#
|
|
1621
|
+
# { mode: 'Locked|Unlocked', retain_until_time: '2023-12-19T03:22:23+00:00' }
|
|
1622
|
+
#
|
|
1623
|
+
# @param [Hash(String => String)] new_retention_attributes
|
|
1624
|
+
#
|
|
1625
|
+
# @example Update retention parameters for the File / Object
|
|
1626
|
+
# require "google/cloud/storage"
|
|
1627
|
+
# storage = Google::Cloud::Storage.new
|
|
1628
|
+
# bucket = storage.bucket "my-bucket"
|
|
1629
|
+
# file = bucket.file "avatars/heidi/400x400.png"
|
|
1630
|
+
# retention_params = { mode: 'Unlocked', retain_until_time: '2023-12-19T03:22:23+00:00'.to_datetime }
|
|
1631
|
+
# file.retention = retention_params
|
|
1632
|
+
#
|
|
1633
|
+
# @example Update retention parameters for the File / Object with override enabled
|
|
1634
|
+
# require "google/cloud/storage"
|
|
1635
|
+
# storage = Google::Cloud::Storage.new
|
|
1636
|
+
# bucket = storage.bucket "my-bucket"
|
|
1637
|
+
# file = bucket.file "avatars/heidi/400x400.png"
|
|
1638
|
+
# retention_params = { mode: 'Unlocked',
|
|
1639
|
+
# retain_until_time: '2023-12-19T03:22:23+00:00'.to_datetime,
|
|
1640
|
+
# override_unlocked_retention: true }
|
|
1641
|
+
# file.retention = retention_params
|
|
1642
|
+
#
|
|
1643
|
+
def retention= new_retention_attributes
|
|
1644
|
+
@gapi.retention ||= Google::Apis::StorageV1::Object::Retention.new
|
|
1645
|
+
@gapi.retention.mode = new_retention_attributes[:mode]
|
|
1646
|
+
@gapi.retention.retain_until_time = new_retention_attributes[:retain_until_time]
|
|
1647
|
+
update_gapi! :retention, override_unlocked_retention: new_retention_attributes[:override_unlocked_retention]
|
|
1648
|
+
end
|
|
1649
|
+
|
|
1563
1650
|
##
|
|
1564
1651
|
# Public URL to access the file. If the file is not public, requests to
|
|
1565
1652
|
# the URL will return an error. (See {File::Acl#public!} and
|
|
@@ -1985,15 +2072,59 @@ module Google
|
|
|
1985
2072
|
def self.gapi_from_attrs gapi, attributes
|
|
1986
2073
|
attributes.flatten!
|
|
1987
2074
|
return nil if attributes.empty?
|
|
1988
|
-
attr_params =
|
|
1989
|
-
|
|
1990
|
-
|
|
2075
|
+
attr_params = attributes.to_h do |attr|
|
|
2076
|
+
[attr, gapi.send(attr)]
|
|
2077
|
+
end
|
|
1991
2078
|
# Sending nil metadata results in an Apiary runtime error:
|
|
1992
2079
|
# NoMethodError: undefined method `each' for nil:NilClass
|
|
1993
2080
|
attr_params.reject! { |k, v| k == :metadata && v.nil? }
|
|
1994
2081
|
Google::Apis::StorageV1::Object.new(**attr_params)
|
|
1995
2082
|
end
|
|
1996
2083
|
|
|
2084
|
+
##
|
|
2085
|
+
# from_gs_url is a method to fetch bucket details and file details from a gs url
|
|
2086
|
+
#
|
|
2087
|
+
# @return [Hash(String => String)]
|
|
2088
|
+
#
|
|
2089
|
+
# @example Fetch bucket_name and file_Path from gs url:
|
|
2090
|
+
# require "google/cloud/storage"
|
|
2091
|
+
# gs_url= "gs://my-todo-app/avatars/heidi.jpeg"
|
|
2092
|
+
# file=Google::Cloud::Storage::File
|
|
2093
|
+
# file.from_gs_url(gs_url)
|
|
2094
|
+
# =>
|
|
2095
|
+
# {"bucket_name"=>"my-todo-app", "file_path"=>"avatars/heidi.jpeg"}
|
|
2096
|
+
#
|
|
2097
|
+
# @example Fetch bucket_name , file_Path and other query params from gs url:
|
|
2098
|
+
# require "google/cloud/storage"
|
|
2099
|
+
# gs_url= "gs://my-todo-app/test_sub_folder/heidi.jpeg?params1=test1¶ms2=test2"
|
|
2100
|
+
# file=Google::Cloud::Storage::File
|
|
2101
|
+
# file.from_gs_url(gs_url)
|
|
2102
|
+
# =>{
|
|
2103
|
+
# "bucket_name"=>"my-todo-app",
|
|
2104
|
+
# "file_path"=>"test_sub_folder/heidi.jpeg",
|
|
2105
|
+
# "options" => {
|
|
2106
|
+
# "params1"=>"test1",
|
|
2107
|
+
# "params2"=>"test2"
|
|
2108
|
+
# }
|
|
2109
|
+
# }
|
|
2110
|
+
|
|
2111
|
+
def self.from_gs_url gs_url
|
|
2112
|
+
prefix = "gs://".freeze
|
|
2113
|
+
raise ArgumentError, "Invalid GCS URL" unless gs_url.start_with? prefix
|
|
2114
|
+
# seprating params from input url
|
|
2115
|
+
path, query = gs_url.sub(prefix, "").split("?", 2)
|
|
2116
|
+
# parsing the url
|
|
2117
|
+
bucket_name, file_path = path.split "/", 2
|
|
2118
|
+
query_params = URI.decode_www_form(query).to_h if query
|
|
2119
|
+
url_items = {
|
|
2120
|
+
"bucket_name" => bucket_name,
|
|
2121
|
+
"file_path" => file_path
|
|
2122
|
+
}
|
|
2123
|
+
# adding url params to output hash
|
|
2124
|
+
url_items.merge! "options" => query_params if query
|
|
2125
|
+
url_items
|
|
2126
|
+
end
|
|
2127
|
+
|
|
1997
2128
|
protected
|
|
1998
2129
|
|
|
1999
2130
|
##
|
|
@@ -2015,7 +2146,8 @@ module Google
|
|
|
2015
2146
|
if_generation_match: nil,
|
|
2016
2147
|
if_generation_not_match: nil,
|
|
2017
2148
|
if_metageneration_match: nil,
|
|
2018
|
-
if_metageneration_not_match: nil
|
|
2149
|
+
if_metageneration_not_match: nil,
|
|
2150
|
+
override_unlocked_retention: nil
|
|
2019
2151
|
attributes = Array(attributes)
|
|
2020
2152
|
attributes.flatten!
|
|
2021
2153
|
return if attributes.empty?
|
|
@@ -2044,7 +2176,8 @@ module Google
|
|
|
2044
2176
|
if_generation_not_match: if_generation_not_match,
|
|
2045
2177
|
if_metageneration_match: if_metageneration_match,
|
|
2046
2178
|
if_metageneration_not_match: if_metageneration_not_match,
|
|
2047
|
-
user_project: user_project
|
|
2179
|
+
user_project: user_project,
|
|
2180
|
+
override_unlocked_retention: override_unlocked_retention
|
|
2048
2181
|
end
|
|
2049
2182
|
end
|
|
2050
2183
|
|
|
@@ -2107,10 +2240,8 @@ module Google
|
|
|
2107
2240
|
[dest_bucket, dest_path]
|
|
2108
2241
|
end
|
|
2109
2242
|
|
|
2110
|
-
# rubocop:disable Style/MultipleComparison
|
|
2111
|
-
|
|
2112
2243
|
def verify_file! file, verify = :md5
|
|
2113
|
-
verify_md5 = verify == :md5
|
|
2244
|
+
verify_md5 = verify == :md5 || verify == :all
|
|
2114
2245
|
verify_crc32c = verify == :crc32c || verify == :all
|
|
2115
2246
|
Verifier.verify_md5! self, file if verify_md5 && md5
|
|
2116
2247
|
Verifier.verify_crc32c! self, file if verify_crc32c && crc32c
|
|
@@ -62,6 +62,15 @@ module Google
|
|
|
62
62
|
@service = service
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
##
|
|
66
|
+
# The universe domain the client is connected to
|
|
67
|
+
#
|
|
68
|
+
# @return [String]
|
|
69
|
+
#
|
|
70
|
+
def universe_domain
|
|
71
|
+
service.universe_domain
|
|
72
|
+
end
|
|
73
|
+
|
|
65
74
|
##
|
|
66
75
|
# The Storage project connected to.
|
|
67
76
|
#
|
|
@@ -94,6 +103,41 @@ module Google
|
|
|
94
103
|
service.project_service_account.email_address
|
|
95
104
|
end
|
|
96
105
|
|
|
106
|
+
##
|
|
107
|
+
# Add custom Google extension headers to the requests that use the signed URLs.
|
|
108
|
+
#
|
|
109
|
+
# @param [Hash] headers Google extension headers (custom HTTP headers that
|
|
110
|
+
# begin with `x-goog-`) to be included in requests that use the signed URLs.
|
|
111
|
+
# Provide headers as a key/value array, where the key is
|
|
112
|
+
# the header name, and the value is an array of header values.
|
|
113
|
+
# For headers with multiple values, provide values as a simple
|
|
114
|
+
# array, or a comma-separated string. For a reference of allowed
|
|
115
|
+
# headers, see [Reference Headers](https://cloud.google.com/storage/docs/xml-api/reference-headers).
|
|
116
|
+
#
|
|
117
|
+
# @return [Google::Cloud::Storage::Project] Returns the Project for method chaining
|
|
118
|
+
#
|
|
119
|
+
def add_custom_headers headers
|
|
120
|
+
@service.add_custom_headers headers
|
|
121
|
+
self
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
##
|
|
125
|
+
# Add custom Google extension header to the requests that use the signed URLs.
|
|
126
|
+
#
|
|
127
|
+
# @param [String] header_name Name of Google extension header (custom HTTP header that
|
|
128
|
+
# begin with `x-goog-`) to be included in requests that use the signed URLs.
|
|
129
|
+
# For a reference of allowed headers, see
|
|
130
|
+
# [Reference Headers](https://cloud.google.com/storage/docs/xml-api/reference-headers).
|
|
131
|
+
# @param [Object] header_value Valid value of the Google extension header being added.
|
|
132
|
+
# For headers with multiple values, provide values as a simple array, or a comma-separated string.
|
|
133
|
+
#
|
|
134
|
+
# @return [Google::Cloud::Storage::Project] Returns the Project for method chaining
|
|
135
|
+
#
|
|
136
|
+
def add_custom_header header_name, header_value
|
|
137
|
+
@service.add_custom_header header_name, header_value
|
|
138
|
+
self
|
|
139
|
+
end
|
|
140
|
+
|
|
97
141
|
##
|
|
98
142
|
# Retrieves a list of buckets for the given project.
|
|
99
143
|
#
|
|
@@ -337,6 +381,8 @@ module Google
|
|
|
337
381
|
# bucket instance and its files.
|
|
338
382
|
#
|
|
339
383
|
# See also {Bucket#requester_pays=} and {Bucket#requester_pays}.
|
|
384
|
+
# @param [Boolean] enable_object_retention
|
|
385
|
+
# When set to true, object retention is enabled for this bucket.
|
|
340
386
|
#
|
|
341
387
|
# @yield [bucket] a block for configuring the bucket before it is
|
|
342
388
|
# created
|
|
@@ -351,6 +397,13 @@ module Google
|
|
|
351
397
|
#
|
|
352
398
|
# bucket = storage.create_bucket "my-bucket"
|
|
353
399
|
#
|
|
400
|
+
# @example
|
|
401
|
+
# require "google/cloud/storage"
|
|
402
|
+
#
|
|
403
|
+
# storage = Google::Cloud::Storage.new
|
|
404
|
+
#
|
|
405
|
+
# bucket = storage.create_bucket "my-bucket", enable_object_retention: true
|
|
406
|
+
#
|
|
354
407
|
# @example Configure the bucket in a block:
|
|
355
408
|
# require "google/cloud/storage"
|
|
356
409
|
#
|
|
@@ -368,6 +421,7 @@ module Google
|
|
|
368
421
|
# b.lifecycle.add_set_storage_class_rule "COLDLINE", age: 10
|
|
369
422
|
# end
|
|
370
423
|
#
|
|
424
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
371
425
|
def create_bucket bucket_name,
|
|
372
426
|
acl: nil,
|
|
373
427
|
default_acl: nil,
|
|
@@ -381,11 +435,14 @@ module Google
|
|
|
381
435
|
versioning: nil,
|
|
382
436
|
requester_pays: nil,
|
|
383
437
|
user_project: nil,
|
|
384
|
-
autoclass_enabled: false
|
|
438
|
+
autoclass_enabled: false,
|
|
439
|
+
enable_object_retention: nil,
|
|
440
|
+
hierarchical_namespace: nil
|
|
385
441
|
params = {
|
|
386
442
|
name: bucket_name,
|
|
387
443
|
location: location,
|
|
388
|
-
custom_placement_config: custom_placement_config
|
|
444
|
+
custom_placement_config: custom_placement_config,
|
|
445
|
+
hierarchical_namespace: hierarchical_namespace
|
|
389
446
|
}.delete_if { |_, v| v.nil? }
|
|
390
447
|
new_bucket = Google::Apis::StorageV1::Bucket.new(**params)
|
|
391
448
|
storage_class = storage_class_for storage_class
|
|
@@ -398,6 +455,7 @@ module Google
|
|
|
398
455
|
b.website_404 = website_404 unless website_404.nil?
|
|
399
456
|
b.versioning = versioning unless versioning.nil?
|
|
400
457
|
b.requester_pays = requester_pays unless requester_pays.nil?
|
|
458
|
+
b.hierarchical_namespace = hierarchical_namespace unless hierarchical_namespace.nil?
|
|
401
459
|
end
|
|
402
460
|
yield updater if block_given?
|
|
403
461
|
updater.check_for_changed_labels!
|
|
@@ -405,9 +463,11 @@ module Google
|
|
|
405
463
|
updater.check_for_mutable_lifecycle!
|
|
406
464
|
gapi = service.insert_bucket \
|
|
407
465
|
new_bucket, acl: acl_rule(acl), default_acl: acl_rule(default_acl),
|
|
408
|
-
user_project: user_project
|
|
466
|
+
user_project: user_project,
|
|
467
|
+
enable_object_retention: enable_object_retention
|
|
409
468
|
Bucket.from_gapi gapi, service, user_project: user_project
|
|
410
469
|
end
|
|
470
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
411
471
|
|
|
412
472
|
##
|
|
413
473
|
# Creates a new HMAC key.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
require "google/cloud/storage/version"
|
|
17
17
|
require "google/apis/storage_v1"
|
|
18
|
+
require "google/cloud/config"
|
|
18
19
|
require "digest"
|
|
19
20
|
require "mini_mime"
|
|
20
21
|
require "pathname"
|
|
@@ -36,6 +37,11 @@ module Google
|
|
|
36
37
|
# @private
|
|
37
38
|
attr_accessor :credentials
|
|
38
39
|
|
|
40
|
+
# @private
|
|
41
|
+
def universe_domain
|
|
42
|
+
service.universe_domain
|
|
43
|
+
end
|
|
44
|
+
|
|
39
45
|
##
|
|
40
46
|
# Creates a new Service instance.
|
|
41
47
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
@@ -43,7 +49,8 @@ module Google
|
|
|
43
49
|
timeout: nil, open_timeout: nil, read_timeout: nil,
|
|
44
50
|
send_timeout: nil, host: nil, quota_project: nil,
|
|
45
51
|
max_elapsed_time: nil, base_interval: nil, max_interval: nil,
|
|
46
|
-
multiplier: nil
|
|
52
|
+
multiplier: nil, upload_chunk_size: nil, universe_domain: nil
|
|
53
|
+
host ||= Google::Cloud::Storage.configure.endpoint
|
|
47
54
|
@project = project
|
|
48
55
|
@credentials = credentials
|
|
49
56
|
@service = API::StorageService.new
|
|
@@ -65,8 +72,16 @@ module Google
|
|
|
65
72
|
@service.request_options.max_interval = max_interval if max_interval
|
|
66
73
|
@service.request_options.multiplier = multiplier if multiplier
|
|
67
74
|
@service.request_options.add_invocation_id_header = true
|
|
75
|
+
@service.request_options.upload_chunk_size = upload_chunk_size if upload_chunk_size
|
|
68
76
|
@service.authorization = @credentials.client if @credentials
|
|
69
77
|
@service.root_url = host if host
|
|
78
|
+
@service.universe_domain = universe_domain || Google::Cloud::Storage.configure.universe_domain
|
|
79
|
+
begin
|
|
80
|
+
@service.verify_universe_domain!
|
|
81
|
+
rescue Google::Apis::UniverseDomainError => e
|
|
82
|
+
# TODO: Create a Google::Cloud::Error subclass for this.
|
|
83
|
+
raise Google::Cloud::Error, e.message
|
|
84
|
+
end
|
|
70
85
|
end
|
|
71
86
|
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
72
87
|
|
|
@@ -111,14 +126,16 @@ module Google
|
|
|
111
126
|
# Creates a new bucket.
|
|
112
127
|
# Returns Google::Apis::StorageV1::Bucket.
|
|
113
128
|
def insert_bucket bucket_gapi, acl: nil, default_acl: nil,
|
|
114
|
-
user_project: nil,
|
|
129
|
+
user_project: nil, enable_object_retention: nil,
|
|
130
|
+
options: {}
|
|
115
131
|
execute do
|
|
116
132
|
service.insert_bucket \
|
|
117
133
|
@project, bucket_gapi,
|
|
118
134
|
predefined_acl: acl,
|
|
119
135
|
predefined_default_object_acl: default_acl,
|
|
120
136
|
user_project: user_project(user_project),
|
|
121
|
-
options: options
|
|
137
|
+
options: options,
|
|
138
|
+
enable_object_retention: enable_object_retention
|
|
122
139
|
end
|
|
123
140
|
end
|
|
124
141
|
|
|
@@ -348,13 +365,17 @@ module Google
|
|
|
348
365
|
# Retrieves a list of files matching the criteria.
|
|
349
366
|
def list_files bucket_name, delimiter: nil, max: nil, token: nil,
|
|
350
367
|
prefix: nil, versions: nil, user_project: nil,
|
|
351
|
-
|
|
368
|
+
match_glob: nil, include_folders_as_prefixes: nil,
|
|
369
|
+
soft_deleted: nil, options: {}
|
|
352
370
|
execute do
|
|
353
371
|
service.list_objects \
|
|
354
372
|
bucket_name, delimiter: delimiter, max_results: max,
|
|
355
373
|
page_token: token, prefix: prefix,
|
|
356
374
|
versions: versions,
|
|
357
375
|
user_project: user_project(user_project),
|
|
376
|
+
match_glob: match_glob,
|
|
377
|
+
include_folders_as_prefixes: include_folders_as_prefixes,
|
|
378
|
+
soft_deleted: soft_deleted,
|
|
358
379
|
options: options
|
|
359
380
|
end
|
|
360
381
|
end
|
|
@@ -438,6 +459,7 @@ module Google
|
|
|
438
459
|
if_metageneration_not_match: nil,
|
|
439
460
|
key: nil,
|
|
440
461
|
user_project: nil,
|
|
462
|
+
soft_deleted: nil,
|
|
441
463
|
options: {}
|
|
442
464
|
execute do
|
|
443
465
|
service.get_object \
|
|
@@ -448,6 +470,7 @@ module Google
|
|
|
448
470
|
if_metageneration_match: if_metageneration_match,
|
|
449
471
|
if_metageneration_not_match: if_metageneration_not_match,
|
|
450
472
|
user_project: user_project(user_project),
|
|
473
|
+
soft_deleted: soft_deleted,
|
|
451
474
|
options: key_options(key).merge(options)
|
|
452
475
|
end
|
|
453
476
|
end
|
|
@@ -520,7 +543,6 @@ module Google
|
|
|
520
543
|
if_metageneration_match: nil,
|
|
521
544
|
user_project: nil,
|
|
522
545
|
options: {}
|
|
523
|
-
|
|
524
546
|
source_objects = compose_file_source_objects source_files, if_source_generation_match
|
|
525
547
|
compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
|
|
526
548
|
destination: destination_gapi
|
|
@@ -579,6 +601,7 @@ module Google
|
|
|
579
601
|
if_metageneration_not_match: nil,
|
|
580
602
|
predefined_acl: nil,
|
|
581
603
|
user_project: nil,
|
|
604
|
+
override_unlocked_retention: nil,
|
|
582
605
|
options: {}
|
|
583
606
|
file_gapi ||= Google::Apis::StorageV1::Object.new
|
|
584
607
|
|
|
@@ -598,6 +621,7 @@ module Google
|
|
|
598
621
|
if_metageneration_not_match: if_metageneration_not_match,
|
|
599
622
|
predefined_acl: predefined_acl,
|
|
600
623
|
user_project: user_project(user_project),
|
|
624
|
+
override_unlocked_retention: override_unlocked_retention,
|
|
601
625
|
options: options
|
|
602
626
|
end
|
|
603
627
|
end
|
|
@@ -613,7 +637,6 @@ module Google
|
|
|
613
637
|
if_metageneration_not_match: nil,
|
|
614
638
|
user_project: nil,
|
|
615
639
|
options: {}
|
|
616
|
-
|
|
617
640
|
if options[:retries].nil?
|
|
618
641
|
is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
|
|
619
642
|
options = is_idempotent ? {} : { retries: 0 }
|
|
@@ -631,6 +654,39 @@ module Google
|
|
|
631
654
|
end
|
|
632
655
|
end
|
|
633
656
|
|
|
657
|
+
##
|
|
658
|
+
# Restores a soft-deleted object.
|
|
659
|
+
def restore_file bucket_name,
|
|
660
|
+
file_path,
|
|
661
|
+
generation,
|
|
662
|
+
copy_source_acl: nil,
|
|
663
|
+
if_generation_match: nil,
|
|
664
|
+
if_generation_not_match: nil,
|
|
665
|
+
if_metageneration_match: nil,
|
|
666
|
+
if_metageneration_not_match: nil,
|
|
667
|
+
projection: nil,
|
|
668
|
+
user_project: nil,
|
|
669
|
+
fields: nil,
|
|
670
|
+
options: {}
|
|
671
|
+
if options[:retries].nil?
|
|
672
|
+
is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
|
|
673
|
+
options = is_idempotent ? {} : { retries: 0 }
|
|
674
|
+
end
|
|
675
|
+
|
|
676
|
+
execute do
|
|
677
|
+
service.restore_object bucket_name, file_path, generation,
|
|
678
|
+
copy_source_acl: copy_source_acl,
|
|
679
|
+
if_generation_match: if_generation_match,
|
|
680
|
+
if_generation_not_match: if_generation_not_match,
|
|
681
|
+
if_metageneration_match: if_metageneration_match,
|
|
682
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
|
683
|
+
projection: projection,
|
|
684
|
+
user_project: user_project(user_project),
|
|
685
|
+
fields: fields,
|
|
686
|
+
options: options
|
|
687
|
+
end
|
|
688
|
+
end
|
|
689
|
+
|
|
634
690
|
##
|
|
635
691
|
# Retrieves a list of ACLs for the given file.
|
|
636
692
|
def list_file_acls bucket_name, file_name, user_project: nil, options: {}
|
|
@@ -679,7 +735,6 @@ module Google
|
|
|
679
735
|
# Returns Google::Apis::StorageV1::HmacKey.
|
|
680
736
|
def create_hmac_key service_account_email, project_id: nil,
|
|
681
737
|
user_project: nil, options: {}
|
|
682
|
-
|
|
683
738
|
if options[:retries].nil?
|
|
684
739
|
options = options.merge({ retries: 0 })
|
|
685
740
|
end
|
|
@@ -794,6 +849,18 @@ module Google
|
|
|
794
849
|
"#{self.class}(#{@project})"
|
|
795
850
|
end
|
|
796
851
|
|
|
852
|
+
##
|
|
853
|
+
# Add custom Google extension headers to the requests that use the signed URLs.
|
|
854
|
+
def add_custom_headers headers
|
|
855
|
+
@service.request_options.header.merge! headers
|
|
856
|
+
end
|
|
857
|
+
|
|
858
|
+
##
|
|
859
|
+
# Add custom Google extension header to the requests that use the signed URLs.
|
|
860
|
+
def add_custom_header header_name, header_value
|
|
861
|
+
@service.request_options.header[header_name] = header_value
|
|
862
|
+
end
|
|
863
|
+
|
|
797
864
|
protected
|
|
798
865
|
|
|
799
866
|
def user_project user_project
|
data/lib/google/cloud/storage.rb
CHANGED
|
@@ -67,6 +67,11 @@ module Google
|
|
|
67
67
|
# @param [Integer] send_timeout How long, in seconds, before receiving response from server times out. Optional.
|
|
68
68
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
|
69
69
|
# If the param is nil, uses the default endpoint.
|
|
70
|
+
# @param universe_domain [String] Override of the universe domain. Optional.
|
|
71
|
+
# If unset or nil, uses the default unvierse domain
|
|
72
|
+
# @param [Integer] upload_chunk_size The chunk size of storage upload, in bytes.
|
|
73
|
+
# The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and upload
|
|
74
|
+
# the complete file regardless of size, pass 0 as the chunk size.
|
|
70
75
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
|
71
76
|
# @param [String] keyfile Alias for the `credentials` argument.
|
|
72
77
|
# Deprecated.
|
|
@@ -89,19 +94,21 @@ module Google
|
|
|
89
94
|
timeout: nil, open_timeout: nil, read_timeout: nil,
|
|
90
95
|
send_timeout: nil, endpoint: nil, project: nil, keyfile: nil,
|
|
91
96
|
max_elapsed_time: nil, base_interval: nil, max_interval: nil,
|
|
92
|
-
multiplier: nil
|
|
97
|
+
multiplier: nil, upload_chunk_size: nil, universe_domain: nil
|
|
93
98
|
scope ||= configure.scope
|
|
94
99
|
retries ||= configure.retries
|
|
95
100
|
timeout ||= configure.timeout
|
|
96
|
-
open_timeout ||=
|
|
97
|
-
read_timeout ||=
|
|
98
|
-
send_timeout ||=
|
|
101
|
+
open_timeout ||= configure.open_timeout || timeout
|
|
102
|
+
read_timeout ||= configure.read_timeout || timeout
|
|
103
|
+
send_timeout ||= configure.send_timeout || timeout
|
|
99
104
|
endpoint ||= configure.endpoint
|
|
100
|
-
credentials ||=
|
|
105
|
+
credentials ||= keyfile || default_credentials(scope: scope)
|
|
101
106
|
max_elapsed_time ||= configure.max_elapsed_time
|
|
102
107
|
base_interval ||= configure.base_interval
|
|
103
108
|
max_interval ||= configure.max_interval
|
|
104
109
|
multiplier ||= configure.multiplier
|
|
110
|
+
upload_chunk_size ||= configure.upload_chunk_size
|
|
111
|
+
universe_domain ||= configure.universe_domain
|
|
105
112
|
|
|
106
113
|
unless credentials.is_a? Google::Auth::Credentials
|
|
107
114
|
credentials = Storage::Credentials.new credentials, scope: scope
|
|
@@ -117,7 +124,8 @@ module Google
|
|
|
117
124
|
read_timeout: read_timeout, send_timeout: send_timeout,
|
|
118
125
|
host: endpoint, quota_project: configure.quota_project,
|
|
119
126
|
max_elapsed_time: max_elapsed_time, base_interval: base_interval,
|
|
120
|
-
max_interval: max_interval, multiplier: multiplier
|
|
127
|
+
max_interval: max_interval, multiplier: multiplier, upload_chunk_size: upload_chunk_size,
|
|
128
|
+
universe_domain: universe_domain
|
|
121
129
|
)
|
|
122
130
|
)
|
|
123
131
|
end
|
|
@@ -141,6 +149,11 @@ module Google
|
|
|
141
149
|
# @param [Integer] send_timeout How long, in seconds, before receiving response from server times out. Optional.
|
|
142
150
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
|
143
151
|
# If the param is nil, uses the default endpoint.
|
|
152
|
+
# @param universe_domain [String] Override of the universe domain. Optional.
|
|
153
|
+
# If unset or nil, uses the default unvierse domain
|
|
154
|
+
# @param [Integer] upload_chunk_size The chunk size of storage upload, in bytes.
|
|
155
|
+
# The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and upload
|
|
156
|
+
# the complete file regardless of size, pass 0 as the chunk size.
|
|
144
157
|
#
|
|
145
158
|
# @return [Google::Cloud::Storage::Project]
|
|
146
159
|
#
|
|
@@ -159,7 +172,7 @@ module Google
|
|
|
159
172
|
def self.anonymous retries: nil, timeout: nil, open_timeout: nil,
|
|
160
173
|
read_timeout: nil, send_timeout: nil, endpoint: nil,
|
|
161
174
|
max_elapsed_time: nil, base_interval: nil, max_interval: nil,
|
|
162
|
-
multiplier: nil
|
|
175
|
+
multiplier: nil, upload_chunk_size: nil, universe_domain: nil
|
|
163
176
|
open_timeout ||= timeout
|
|
164
177
|
read_timeout ||= timeout
|
|
165
178
|
send_timeout ||= timeout
|
|
@@ -168,7 +181,8 @@ module Google
|
|
|
168
181
|
nil, nil, retries: retries, timeout: timeout, open_timeout: open_timeout,
|
|
169
182
|
read_timeout: read_timeout, send_timeout: send_timeout, host: endpoint,
|
|
170
183
|
max_elapsed_time: max_elapsed_time, base_interval: base_interval,
|
|
171
|
-
max_interval: max_interval, multiplier: multiplier
|
|
184
|
+
max_interval: max_interval, multiplier: multiplier, upload_chunk_size: upload_chunk_size,
|
|
185
|
+
universe_domain: universe_domain
|
|
172
186
|
)
|
|
173
187
|
)
|
|
174
188
|
end
|
|
@@ -202,6 +216,7 @@ module Google
|
|
|
202
216
|
# * `open_timeout` - (Integer) How long, in seconds, before failed connections time out.
|
|
203
217
|
# * `read_timeout` - (Integer) How long, in seconds, before requests time out.
|
|
204
218
|
# * `send_timeout` - (Integer) How long, in seconds, before receiving response from server times out.
|
|
219
|
+
# * `upload_chunk_size` - (Integer) The chunk size of storage upload, in bytes.
|
|
205
220
|
#
|
|
206
221
|
# @return [Google::Cloud::Config] The configuration object the
|
|
207
222
|
# Google::Cloud::Storage library uses.
|