google-cloud-storage 1.23.0 → 1.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/google/cloud/storage/file.rb +85 -23
- data/lib/google/cloud/storage/file/signer_v2.rb +13 -2
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a70c28bc015c2cde33d22c6af7ad022c4168fd32be38037a18f55e771780b866
|
4
|
+
data.tar.gz: 35c072fa504c5b0d3fd9984765a5049d41d7169755afeadc9e6554d74bb6b3e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa389bb4e5790362bec4d6376e72fd216739d44912c0d3254eb25dde0c83dfbf7ba02ba90ebd94c5d9b3c600bac0cc7c2c62e80128e59388a6426e04e2d21bf7
|
7
|
+
data.tar.gz: 85189ae6d33e7e4e95d42217d7a3aa90e44725c442b0ac912a937b314f27f6b333a3c6b566ffa1d3406f8f8388e2f27665a58174383275ddc5d81d7292c955cc
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.24.0 / 2019-11-12
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Add force_copy_metadata to File#copy and #rewrite
|
8
|
+
|
9
|
+
#### Bug Fixes
|
10
|
+
|
11
|
+
* Update #post_object to support special variable ${filename}
|
12
|
+
|
3
13
|
### 1.23.0 / 2019-11-05
|
4
14
|
|
5
15
|
#### Features
|
@@ -777,7 +777,7 @@ module Google
|
|
777
777
|
end
|
778
778
|
|
779
779
|
##
|
780
|
-
#
|
780
|
+
# Downloads the file's contents to a local file or an File-like object.
|
781
781
|
#
|
782
782
|
# By default, the download is verified by calculating the MD5 digest.
|
783
783
|
#
|
@@ -951,7 +951,15 @@ module Google
|
|
951
951
|
end
|
952
952
|
|
953
953
|
##
|
954
|
-
#
|
954
|
+
# Copies the file to a new location. Metadata excluding ACL from the source
|
955
|
+
# object will be copied to the destination object unless a block is provided.
|
956
|
+
#
|
957
|
+
# If an optional block for updating is provided, only the updates made in
|
958
|
+
# this block will appear in the destination object, and other metadata
|
959
|
+
# fields in the destination object will not be copied. To copy the other
|
960
|
+
# source file metadata fields while updating destination fields in a
|
961
|
+
# block, use the `force_copy_metadata: true` flag, and the client library
|
962
|
+
# will copy metadata from source metadata into the copy request.
|
955
963
|
#
|
956
964
|
# If a [customer-supplied encryption
|
957
965
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
@@ -986,6 +994,19 @@ module Google
|
|
986
994
|
# @param [String] encryption_key Optional. The customer-supplied,
|
987
995
|
# AES-256 encryption key used to encrypt the file, if one was provided
|
988
996
|
# to {Bucket#create_file}.
|
997
|
+
# @param [Boolean] force_copy_metadata Optional. If `true` and if updates
|
998
|
+
# are made in a block, the following fields will be copied from the
|
999
|
+
# source file to the destination file (except when changed by updates):
|
1000
|
+
#
|
1001
|
+
# * `cache_control`
|
1002
|
+
# * `content_disposition`
|
1003
|
+
# * `content_encoding`
|
1004
|
+
# * `content_language`
|
1005
|
+
# * `content_type`
|
1006
|
+
# * `metadata`
|
1007
|
+
#
|
1008
|
+
# If `nil` or `false`, only the updates made in the yielded block will
|
1009
|
+
# be applied to the destination object. The default is `nil`.
|
989
1010
|
# @yield [file] a block yielding a delegate object for updating
|
990
1011
|
#
|
991
1012
|
# @return [Google::Cloud::Storage::File]
|
@@ -1035,12 +1056,13 @@ module Google
|
|
1035
1056
|
# f.metadata["copied_from"] = "#{file.bucket}/#{file.name}"
|
1036
1057
|
# end
|
1037
1058
|
#
|
1038
|
-
def copy dest_bucket_or_path, dest_path = nil,
|
1039
|
-
|
1059
|
+
def copy dest_bucket_or_path, dest_path = nil, acl: nil, generation: nil, encryption_key: nil,
|
1060
|
+
force_copy_metadata: nil
|
1040
1061
|
rewrite dest_bucket_or_path, dest_path,
|
1041
1062
|
acl: acl, generation: generation,
|
1042
1063
|
encryption_key: encryption_key,
|
1043
|
-
new_encryption_key: encryption_key
|
1064
|
+
new_encryption_key: encryption_key,
|
1065
|
+
force_copy_metadata: force_copy_metadata do |updater|
|
1044
1066
|
yield updater if block_given?
|
1045
1067
|
end
|
1046
1068
|
end
|
@@ -1048,7 +1070,15 @@ module Google
|
|
1048
1070
|
##
|
1049
1071
|
# [Rewrites](https://cloud.google.com/storage/docs/json_api/v1/objects/rewrite)
|
1050
1072
|
# the file to a new location. Or the same location can be provided to
|
1051
|
-
# rewrite the file in place.
|
1073
|
+
# rewrite the file in place. Metadata from the source object will
|
1074
|
+
# be copied to the destination object unless a block is provided.
|
1075
|
+
#
|
1076
|
+
# If an optional block for updating is provided, only the updates made in
|
1077
|
+
# this block will appear in the destination object, and other metadata
|
1078
|
+
# fields in the destination object will not be copied. To copy the other
|
1079
|
+
# source file metadata fields while updating destination fields in a
|
1080
|
+
# block, use the `force_copy_metadata: true` flag, and the client library
|
1081
|
+
# will copy metadata from source metadata into the copy request.
|
1052
1082
|
#
|
1053
1083
|
# If a [customer-supplied encryption
|
1054
1084
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
@@ -1096,6 +1126,19 @@ module Google
|
|
1096
1126
|
# the same location as the bucket.The Service Account associated with
|
1097
1127
|
# your project requires access to this encryption key. Do not provide
|
1098
1128
|
# if `new_encryption_key` is used.
|
1129
|
+
# @param [Boolean] force_copy_metadata Optional. If `true` and if updates
|
1130
|
+
# are made in a block, the following fields will be copied from the
|
1131
|
+
# source file to the destination file (except when changed by updates):
|
1132
|
+
#
|
1133
|
+
# * `cache_control`
|
1134
|
+
# * `content_disposition`
|
1135
|
+
# * `content_encoding`
|
1136
|
+
# * `content_language`
|
1137
|
+
# * `content_type`
|
1138
|
+
# * `metadata`
|
1139
|
+
#
|
1140
|
+
# If `nil` or `false`, only the updates made in the yielded block will
|
1141
|
+
# be applied to the destination object. The default is `nil`.
|
1099
1142
|
# @yield [file] a block yielding a delegate object for updating
|
1100
1143
|
#
|
1101
1144
|
# @return [Google::Cloud::Storage::File]
|
@@ -1189,21 +1232,20 @@ module Google
|
|
1189
1232
|
# f.metadata["rewritten_from"] = "#{file.bucket}/#{file.name}"
|
1190
1233
|
# end
|
1191
1234
|
#
|
1192
|
-
def rewrite dest_bucket_or_path, dest_path = nil,
|
1193
|
-
|
1194
|
-
encryption_key: nil, new_encryption_key: nil,
|
1195
|
-
new_kms_key: nil
|
1235
|
+
def rewrite dest_bucket_or_path, dest_path = nil, acl: nil, generation: nil, encryption_key: nil,
|
1236
|
+
new_encryption_key: nil, new_kms_key: nil, force_copy_metadata: nil
|
1196
1237
|
ensure_service!
|
1197
1238
|
dest_bucket, dest_path = fix_rewrite_args dest_bucket_or_path,
|
1198
1239
|
dest_path
|
1199
1240
|
|
1200
1241
|
update_gapi = nil
|
1201
1242
|
if block_given?
|
1202
|
-
updater = Updater.new gapi
|
1243
|
+
updater = Updater.new gapi.dup
|
1203
1244
|
yield updater
|
1204
1245
|
updater.check_for_changed_metadata!
|
1205
1246
|
if updater.updates.any?
|
1206
|
-
|
1247
|
+
attributes = force_copy_metadata ? (Updater::COPY_ATTRS + updater.updates).uniq : updater.updates
|
1248
|
+
update_gapi = self.class.gapi_from_attrs updater.gapi, attributes
|
1207
1249
|
end
|
1208
1250
|
end
|
1209
1251
|
|
@@ -1678,6 +1720,21 @@ module Google
|
|
1678
1720
|
end
|
1679
1721
|
end
|
1680
1722
|
|
1723
|
+
##
|
1724
|
+
# @private
|
1725
|
+
#
|
1726
|
+
def self.gapi_from_attrs gapi, attributes
|
1727
|
+
attributes.flatten!
|
1728
|
+
return nil if attributes.empty?
|
1729
|
+
attr_params = Hash[attributes.map do |attr|
|
1730
|
+
[attr, gapi.send(attr)]
|
1731
|
+
end]
|
1732
|
+
# Sending nil metadata results in an Apiary runtime error:
|
1733
|
+
# NoMethodError: undefined method `each' for nil:NilClass
|
1734
|
+
attr_params.reject! { |k, v| k == :metadata && v.nil? }
|
1735
|
+
Google::Apis::StorageV1::Object.new attr_params
|
1736
|
+
end
|
1737
|
+
|
1681
1738
|
protected
|
1682
1739
|
|
1683
1740
|
##
|
@@ -1697,7 +1754,7 @@ module Google
|
|
1697
1754
|
def update_gapi! *attributes
|
1698
1755
|
attributes.flatten!
|
1699
1756
|
return if attributes.empty?
|
1700
|
-
update_gapi = gapi_from_attrs attributes
|
1757
|
+
update_gapi = self.class.gapi_from_attrs @gapi, attributes
|
1701
1758
|
return if update_gapi.nil?
|
1702
1759
|
|
1703
1760
|
ensure_service!
|
@@ -1712,15 +1769,6 @@ module Google
|
|
1712
1769
|
end
|
1713
1770
|
end
|
1714
1771
|
|
1715
|
-
def gapi_from_attrs *attributes
|
1716
|
-
attributes.flatten!
|
1717
|
-
return nil if attributes.empty?
|
1718
|
-
attr_params = Hash[attributes.map do |attr|
|
1719
|
-
[attr, @gapi.send(attr)]
|
1720
|
-
end]
|
1721
|
-
Google::Apis::StorageV1::Object.new attr_params
|
1722
|
-
end
|
1723
|
-
|
1724
1772
|
def rewrite_gapi bucket, name, updated_gapi,
|
1725
1773
|
new_bucket: nil, new_name: nil, acl: nil,
|
1726
1774
|
generation: nil, encryption_key: nil,
|
@@ -1791,7 +1839,21 @@ module Google
|
|
1791
1839
|
# Yielded to a block to accumulate changes for a patch request.
|
1792
1840
|
class Updater < File
|
1793
1841
|
# @private
|
1794
|
-
attr_reader :updates
|
1842
|
+
attr_reader :updates, :gapi
|
1843
|
+
|
1844
|
+
##
|
1845
|
+
# @private
|
1846
|
+
# Whitelist of Google::Apis::StorageV1::Object attributes to be
|
1847
|
+
# copied when File#copy or File#rewrite is called with
|
1848
|
+
# `force_copy_metadata: true`.
|
1849
|
+
COPY_ATTRS = [
|
1850
|
+
:cache_control,
|
1851
|
+
:content_disposition,
|
1852
|
+
:content_encoding,
|
1853
|
+
:content_language,
|
1854
|
+
:content_type,
|
1855
|
+
:metadata
|
1856
|
+
].freeze
|
1795
1857
|
|
1796
1858
|
##
|
1797
1859
|
# @private Create an Updater object.
|
@@ -41,9 +41,20 @@ module Google
|
|
41
41
|
end
|
42
42
|
|
43
43
|
##
|
44
|
-
# The external path to the file.
|
44
|
+
# The external path to the file, URI-encoded.
|
45
|
+
# Will not URI encode the special `${filename}` variable.
|
46
|
+
# "You can also use the ${filename} variable..."
|
47
|
+
# https://cloud.google.com/storage/docs/xml-api/post-object
|
48
|
+
#
|
45
49
|
def ext_path
|
46
|
-
|
50
|
+
path = "/#{@bucket}/#{@path}"
|
51
|
+
escaped = Addressable::URI.escape path
|
52
|
+
special_var = "${filename}"
|
53
|
+
# Restore the unencoded `${filename}` variable, if present.
|
54
|
+
if path.include? special_var
|
55
|
+
return escaped.gsub "$%7Bfilename%7D", special_var
|
56
|
+
end
|
57
|
+
escaped
|
47
58
|
end
|
48
59
|
|
49
60
|
##
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-cloud-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-11-
|
12
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|