google-cloud-storage 0.21.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +7 -0
- data/LICENSE +201 -0
- data/README.md +68 -0
- data/lib/google/cloud/storage.rb +10 -13
- data/lib/google/cloud/storage/bucket.rb +29 -43
- data/lib/google/cloud/storage/bucket/acl.rb +6 -6
- data/lib/google/cloud/storage/bucket/cors.rb +7 -7
- data/lib/google/cloud/storage/file.rb +17 -22
- data/lib/google/cloud/storage/project.rb +1 -1
- data/lib/google/cloud/storage/service.rb +9 -11
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ea4be7f9752b1d98381c5f9eb8109a5a3bee1f5
|
4
|
+
data.tar.gz: b7f3164a319ac37f66badeca1c789b59042ad741
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26edfa57afbf8251e3463677b3b9c524a789d61a426b5e43459a221717cb1c7a838052e5e6f454944c247ef78c0a24f79b1339805c1ae7bee0ad6be35b532536
|
7
|
+
data.tar.gz: bcedbb48b9d1cef2fccf80c45f28a1f4b384e7805ba50027808d21931c27204a5647d785bdb1d595dda58c073caf77f3bae71bb36402c7221f14d3b4f0189e74
|
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# google-cloud-storage
|
2
|
+
|
3
|
+
[Google Cloud Storage](https://cloud.google.com/storage/) ([docs](https://cloud.google.com/storage/docs/json_api/)) allows you to store data on Google infrastructure with very high reliability, performance and availability, and can be used to distribute large data objects to users via direct download.
|
4
|
+
|
5
|
+
- [google-cloud-storage API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/master/google/cloud/storage)
|
6
|
+
- [google-cloud-storage on RubyGems](https://rubygems.org/gems/google-cloud-storage)
|
7
|
+
- [Google Cloud Storage documentation](https://cloud.google.com/storage/docs)
|
8
|
+
|
9
|
+
## Quick Start
|
10
|
+
|
11
|
+
```sh
|
12
|
+
$ gem install google-cloud-storage
|
13
|
+
```
|
14
|
+
|
15
|
+
## Authentication
|
16
|
+
|
17
|
+
This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
|
18
|
+
|
19
|
+
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/guides/authentication).
|
20
|
+
|
21
|
+
## Example
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "google/cloud/storage"
|
25
|
+
|
26
|
+
storage = Google::Cloud::Storage.new(
|
27
|
+
project: "my-todo-project",
|
28
|
+
keyfile: "/path/to/keyfile.json"
|
29
|
+
)
|
30
|
+
|
31
|
+
bucket = storage.bucket "task-attachments"
|
32
|
+
|
33
|
+
file = bucket.file "path/to/my-file.ext"
|
34
|
+
|
35
|
+
# Download the file to the local file system
|
36
|
+
file.download "/tasks/attachments/#{file.name}"
|
37
|
+
|
38
|
+
# Copy the file to a backup bucket
|
39
|
+
backup = storage.bucket "task-attachment-backups"
|
40
|
+
file.copy backup, file.name
|
41
|
+
```
|
42
|
+
|
43
|
+
## Supported Ruby Versions
|
44
|
+
|
45
|
+
This library is supported on Ruby 2.0+.
|
46
|
+
|
47
|
+
## Versioning
|
48
|
+
|
49
|
+
This library follows [Semantic Versioning](http://semver.org/).
|
50
|
+
|
51
|
+
It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Contributions to this library are always welcome and highly encouraged.
|
56
|
+
|
57
|
+
See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.
|
58
|
+
|
59
|
+
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
|
64
|
+
|
65
|
+
## Support
|
66
|
+
|
67
|
+
Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
|
68
|
+
Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
|
data/lib/google/cloud/storage.rb
CHANGED
@@ -199,14 +199,14 @@ module Google
|
|
199
199
|
# By default, Google Cloud Storage manages server-side encryption keys on
|
200
200
|
# your behalf. However, a [customer-supplied encryption
|
201
201
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
202
|
-
# can be provided with the `encryption_key`
|
203
|
-
#
|
204
|
-
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
#
|
208
|
-
#
|
209
|
-
#
|
202
|
+
# can be provided with the `encryption_key` option. If given, the same key
|
203
|
+
# must be provided to subsequently download or copy the file. If you use
|
204
|
+
# customer-supplied encryption keys, you must securely manage your keys and
|
205
|
+
# ensure that they are not lost. Also, please note that file metadata is not
|
206
|
+
# encrypted, with the exception of the CRC32C checksum and MD5 hash. The
|
207
|
+
# names of files and buckets are also not encrypted, and you can read or
|
208
|
+
# update the metadata of an encrypted file without providing the encryption
|
209
|
+
# key.
|
210
210
|
#
|
211
211
|
# ```ruby
|
212
212
|
# require "google/cloud/storage"
|
@@ -219,17 +219,14 @@ module Google
|
|
219
219
|
# cipher = OpenSSL::Cipher.new "aes-256-cfb"
|
220
220
|
# cipher.encrypt
|
221
221
|
# key = cipher.random_key
|
222
|
-
# key_hash = Digest::SHA256.digest key
|
223
222
|
#
|
224
223
|
# bucket.create_file "/var/todo-app/avatars/heidi/400x400.png",
|
225
224
|
# "avatars/heidi/400x400.png",
|
226
|
-
# encryption_key: key
|
227
|
-
# encryption_key_sha256: key_hash
|
225
|
+
# encryption_key: key
|
228
226
|
#
|
229
227
|
# # Store your key and hash securely for later use.
|
230
228
|
# file = bucket.file "avatars/heidi/400x400.png",
|
231
|
-
# encryption_key: key
|
232
|
-
# encryption_key_sha256: key_hash
|
229
|
+
# encryption_key: key
|
233
230
|
# ```
|
234
231
|
#
|
235
232
|
# ## Downloading a File
|
@@ -105,10 +105,12 @@ module Google
|
|
105
105
|
# storage = Google::Cloud::Storage.new
|
106
106
|
#
|
107
107
|
# bucket = storage.bucket "my-todo-app"
|
108
|
-
# bucket.cors #=>
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
108
|
+
# bucket.cors.size #=> 2
|
109
|
+
# rule = bucket.cors.first
|
110
|
+
# rule.origin #=> ["http://example.org"]
|
111
|
+
# rule.methods #=> ["GET","POST","DELETE"]
|
112
|
+
# rule.headers #=> ["X-My-Custom-Header"]
|
113
|
+
# rule.max_age #=> 3600
|
112
114
|
#
|
113
115
|
# @example Updating the bucket's CORS rules inside a block.
|
114
116
|
# require "google/cloud/storage"
|
@@ -120,7 +122,7 @@ module Google
|
|
120
122
|
# b.cors do |c|
|
121
123
|
# c.add_rule ["http://example.org", "https://example.org"],
|
122
124
|
# "*",
|
123
|
-
#
|
125
|
+
# headers: ["X-My-Custom-Header"],
|
124
126
|
# max_age: 3600
|
125
127
|
# end
|
126
128
|
# end
|
@@ -289,12 +291,12 @@ module Google
|
|
289
291
|
#
|
290
292
|
# storage = Google::Cloud::Storage.new
|
291
293
|
#
|
292
|
-
# bucket = storage.bucket "my-
|
294
|
+
# bucket = storage.bucket "my-todo-app"
|
293
295
|
# bucket.update do |b|
|
294
296
|
# b.website_main = "index.html"
|
295
297
|
# b.website_404 = "not_found.html"
|
296
|
-
# b.cors[0]
|
297
|
-
# b.cors[1]
|
298
|
+
# b.cors[0].methods = ["GET","POST","DELETE"]
|
299
|
+
# b.cors[1].headers << "X-Another-Custom-Header"
|
298
300
|
# end
|
299
301
|
#
|
300
302
|
# @example New CORS rules can also be added in a nested block:
|
@@ -307,7 +309,7 @@ module Google
|
|
307
309
|
# b.cors do |c|
|
308
310
|
# c.add_rule ["http://example.org", "https://example.org"],
|
309
311
|
# "*",
|
310
|
-
#
|
312
|
+
# headers: ["X-My-Custom-Header"],
|
311
313
|
# max_age: 300
|
312
314
|
# end
|
313
315
|
# end
|
@@ -411,21 +413,16 @@ module Google
|
|
411
413
|
#
|
412
414
|
# If a [customer-supplied encryption
|
413
415
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
414
|
-
# was used with {#create_file}, the `encryption_key`
|
415
|
-
#
|
416
|
-
#
|
416
|
+
# was used with {#create_file}, the `encryption_key` option must be
|
417
|
+
# provided or else the file's CRC32C checksum and MD5 hash will not be
|
418
|
+
# returned.
|
417
419
|
#
|
418
420
|
# @param [String] path Name (path) of the file.
|
419
421
|
# @param [Integer] generation When present, selects a specific revision
|
420
422
|
# of this object. Default is the latest version.
|
421
423
|
# @param [String] encryption_key Optional. The customer-supplied,
|
422
424
|
# AES-256 encryption key used to encrypt the file, if one was provided
|
423
|
-
# to {#create_file}.
|
424
|
-
# provided.
|
425
|
-
# @param [String] encryption_key_sha256 Optional. The SHA256 hash of the
|
426
|
-
# customer-supplied, AES-256 encryption key used to encrypt the file,
|
427
|
-
# if one was provided to {#create_file}. Must be provided if
|
428
|
-
# `encryption_key` is provided.
|
425
|
+
# to {#create_file}.
|
429
426
|
#
|
430
427
|
# @return [Google::Cloud::Storage::File, nil] Returns nil if file does
|
431
428
|
# not exist
|
@@ -440,11 +437,9 @@ module Google
|
|
440
437
|
# file = bucket.file "path/to/my-file.ext"
|
441
438
|
# puts file.name
|
442
439
|
#
|
443
|
-
def file path, generation: nil, encryption_key: nil
|
444
|
-
encryption_key_sha256: nil
|
440
|
+
def file path, generation: nil, encryption_key: nil
|
445
441
|
ensure_service!
|
446
|
-
options = { generation: generation, key: encryption_key
|
447
|
-
key_sha256: encryption_key_sha256 }
|
442
|
+
options = { generation: generation, key: encryption_key }
|
448
443
|
gapi = service.get_file name, path, options
|
449
444
|
File.from_gapi gapi, service
|
450
445
|
rescue Google::Cloud::NotFoundError
|
@@ -459,13 +454,11 @@ module Google
|
|
459
454
|
# #### Customer-supplied encryption keys
|
460
455
|
#
|
461
456
|
# By default, Google Cloud Storage manages server-side encryption keys
|
462
|
-
# on your behalf. However, a [customer-supplied encryption
|
463
|
-
#
|
464
|
-
#
|
465
|
-
#
|
466
|
-
#
|
467
|
-
# customer-supplied encryption keys, you must securely manage your keys
|
468
|
-
# and ensure that they are not lost. Also, please note that file
|
457
|
+
# on your behalf. However, a [customer-supplied encryption key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
458
|
+
# can be provided with the `encryption_key` option. If given, the same
|
459
|
+
# key must be provided to subsequently download or copy the file. If you
|
460
|
+
# use customer-supplied encryption keys, you must securely manage your
|
461
|
+
# keys and ensure that they are not lost. Also, please note that file
|
469
462
|
# metadata is not encrypted, with the exception of the CRC32C checksum
|
470
463
|
# and MD5 hash. The names of files and buckets are also not encrypted,
|
471
464
|
# and you can read or update the metadata of an encrypted file without
|
@@ -522,11 +515,7 @@ module Google
|
|
522
515
|
# and arbitrary string values that will returned with requests for the
|
523
516
|
# file as "x-goog-meta-" response headers.
|
524
517
|
# @param [String] encryption_key Optional. A customer-supplied, AES-256
|
525
|
-
# encryption key that will be used to encrypt the file.
|
526
|
-
# provided if `encryption_key_sha256` is provided.
|
527
|
-
# @param [String] encryption_key_sha256 Optional. The SHA256 hash of the
|
528
|
-
# customer-supplied, AES-256 encryption key that will be used to
|
529
|
-
# encrypt the file. Must be provided if `encryption_key` is provided.
|
518
|
+
# encryption key that will be used to encrypt the file.
|
530
519
|
#
|
531
520
|
# @return [Google::Cloud::Storage::File]
|
532
521
|
#
|
@@ -560,30 +549,27 @@ module Google
|
|
560
549
|
# cipher = OpenSSL::Cipher.new "aes-256-cfb"
|
561
550
|
# cipher.encrypt
|
562
551
|
# key = cipher.random_key
|
563
|
-
# key_hash = Digest::SHA256.digest key
|
564
552
|
#
|
565
553
|
# bucket.create_file "path/to/local.file.ext",
|
566
554
|
# "destination/path/file.ext",
|
567
|
-
# encryption_key: key
|
568
|
-
# encryption_key_sha256: key_hash
|
555
|
+
# encryption_key: key
|
569
556
|
#
|
570
557
|
# # Store your key and hash securely for later use.
|
571
558
|
# file = bucket.file "destination/path/file.ext",
|
572
|
-
# encryption_key: key
|
573
|
-
# encryption_key_sha256: key_hash
|
559
|
+
# encryption_key: key
|
574
560
|
#
|
575
561
|
def create_file file, path = nil, acl: nil, cache_control: nil,
|
576
562
|
content_disposition: nil, content_encoding: nil,
|
577
563
|
content_language: nil, content_type: nil,
|
578
564
|
crc32c: nil, md5: nil, metadata: nil,
|
579
|
-
encryption_key: nil
|
565
|
+
encryption_key: nil
|
580
566
|
ensure_service!
|
581
567
|
options = { acl: File::Acl.predefined_rule_for(acl), md5: md5,
|
582
568
|
cache_control: cache_control, content_type: content_type,
|
583
569
|
content_disposition: content_disposition, crc32c: crc32c,
|
584
570
|
content_encoding: content_encoding,
|
585
571
|
content_language: content_language, metadata: metadata,
|
586
|
-
key: encryption_key
|
572
|
+
key: encryption_key }
|
587
573
|
ensure_file_exists! file
|
588
574
|
# TODO: Handle file as an IO and path is missing more gracefully
|
589
575
|
path ||= Pathname(file).to_path
|
@@ -640,7 +626,7 @@ module Google
|
|
640
626
|
# storage = Google::Cloud::Storage.new
|
641
627
|
#
|
642
628
|
# bucket = storage.bucket "my-todo-app"
|
643
|
-
# shared_url = bucket.signed_url "avatars/heidi/400x400.png"
|
629
|
+
# shared_url = bucket.signed_url "avatars/heidi/400x400.png"
|
644
630
|
#
|
645
631
|
# @example Any of the option parameters may be specified:
|
646
632
|
# require "google/cloud/storage"
|
@@ -652,7 +638,7 @@ module Google
|
|
652
638
|
# method: "PUT",
|
653
639
|
# expires: 300 # 5 minutes from now
|
654
640
|
#
|
655
|
-
# @example Using the
|
641
|
+
# @example Using the issuer and signing_key options:
|
656
642
|
# require "google/cloud/storage"
|
657
643
|
#
|
658
644
|
# storage = Google::Cloud.storage
|
@@ -656,7 +656,7 @@ module Google
|
|
656
656
|
#
|
657
657
|
# bucket = storage.bucket "my-bucket"
|
658
658
|
#
|
659
|
-
# bucket.
|
659
|
+
# bucket.default_acl.auth!
|
660
660
|
#
|
661
661
|
def auth!
|
662
662
|
update_predefined_default_acl! "authenticatedRead"
|
@@ -677,7 +677,7 @@ module Google
|
|
677
677
|
#
|
678
678
|
# bucket = storage.bucket "my-bucket"
|
679
679
|
#
|
680
|
-
# bucket.
|
680
|
+
# bucket.default_acl.owner_full!
|
681
681
|
#
|
682
682
|
def owner_full!
|
683
683
|
update_predefined_default_acl! "bucketOwnerFullControl"
|
@@ -695,7 +695,7 @@ module Google
|
|
695
695
|
#
|
696
696
|
# bucket = storage.bucket "my-bucket"
|
697
697
|
#
|
698
|
-
# bucket.
|
698
|
+
# bucket.default_acl.owner_read!
|
699
699
|
#
|
700
700
|
def owner_read!
|
701
701
|
update_predefined_default_acl! "bucketOwnerRead"
|
@@ -713,7 +713,7 @@ module Google
|
|
713
713
|
#
|
714
714
|
# bucket = storage.bucket "my-bucket"
|
715
715
|
#
|
716
|
-
# bucket.
|
716
|
+
# bucket.default_acl.private!
|
717
717
|
#
|
718
718
|
def private!
|
719
719
|
update_predefined_default_acl! "private"
|
@@ -730,7 +730,7 @@ module Google
|
|
730
730
|
#
|
731
731
|
# bucket = storage.bucket "my-bucket"
|
732
732
|
#
|
733
|
-
# bucket.
|
733
|
+
# bucket.default_acl.project_private!
|
734
734
|
#
|
735
735
|
def project_private!
|
736
736
|
update_predefined_default_acl! "projectPrivate"
|
@@ -748,7 +748,7 @@ module Google
|
|
748
748
|
#
|
749
749
|
# bucket = storage.bucket "my-bucket"
|
750
750
|
#
|
751
|
-
# bucket.
|
751
|
+
# bucket.default_acl.public!
|
752
752
|
#
|
753
753
|
def public!
|
754
754
|
update_predefined_default_acl! "publicRead"
|
@@ -32,9 +32,9 @@ module Google
|
|
32
32
|
# require "google/cloud/storage"
|
33
33
|
#
|
34
34
|
# storage = Google::Cloud::Storage.new
|
35
|
-
# bucket = storage.bucket "my-todo-app"
|
36
35
|
#
|
37
36
|
# bucket = storage.bucket "my-bucket"
|
37
|
+
#
|
38
38
|
# bucket.cors do |c|
|
39
39
|
# # Remove the last CORS rule from the array
|
40
40
|
# c.pop
|
@@ -42,7 +42,7 @@ module Google
|
|
42
42
|
# c.delete_if { |r| r.origin.include? "http://example.com" }
|
43
43
|
# c.add_rule ["http://example.org", "https://example.org"],
|
44
44
|
# ["GET", "POST", "DELETE"],
|
45
|
-
#
|
45
|
+
# headers: ["X-My-Custom-Header"],
|
46
46
|
# max_age: 3600
|
47
47
|
# end
|
48
48
|
#
|
@@ -90,11 +90,11 @@ module Google
|
|
90
90
|
#
|
91
91
|
# storage = Google::Cloud::Storage.new
|
92
92
|
#
|
93
|
-
# bucket = storage.create_bucket "my-bucket" do |
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
93
|
+
# bucket = storage.create_bucket "my-bucket" do |b|
|
94
|
+
# b.cors.add_rule ["http://example.org", "https://example.org"],
|
95
|
+
# "*",
|
96
|
+
# headers: ["X-My-Custom-Header"],
|
97
|
+
# max_age: 300
|
98
98
|
# end
|
99
99
|
#
|
100
100
|
def add_rule origin, methods, headers: nil, max_age: nil
|
@@ -307,8 +307,8 @@ module Google
|
|
307
307
|
#
|
308
308
|
# If a [customer-supplied encryption
|
309
309
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
310
|
-
# was used with {Bucket#create_file}, the `encryption_key`
|
311
|
-
#
|
310
|
+
# was used with {Bucket#create_file}, the `encryption_key` option must
|
311
|
+
# be provided.
|
312
312
|
#
|
313
313
|
# @param [String] path The path on the local file system to write the
|
314
314
|
# data to. The path provided must be writable.
|
@@ -324,12 +324,7 @@ module Google
|
|
324
324
|
#
|
325
325
|
# @param [String] encryption_key Optional. The customer-supplied,
|
326
326
|
# AES-256 encryption key used to encrypt the file, if one was provided
|
327
|
-
# to {Bucket#create_file}.
|
328
|
-
# is provided.
|
329
|
-
# @param [String] encryption_key_sha256 Optional. The SHA256 hash of the
|
330
|
-
# customer-supplied, AES-256 encryption key used to encrypt the file,
|
331
|
-
# if one was provided to {Bucket#create_file}. Must be provided if
|
332
|
-
# `encryption_key` is provided.
|
327
|
+
# to {Bucket#create_file}.
|
333
328
|
#
|
334
329
|
# @return [File] Returns a `::File` object on the local file system
|
335
330
|
#
|
@@ -373,12 +368,11 @@ module Google
|
|
373
368
|
# file = bucket.file "path/to/my-file.ext"
|
374
369
|
# file.download "path/to/downloaded/file.ext", verify: :none
|
375
370
|
#
|
376
|
-
def download path, verify: :md5, encryption_key: nil
|
377
|
-
encryption_key_sha256: nil
|
371
|
+
def download path, verify: :md5, encryption_key: nil
|
378
372
|
ensure_service!
|
379
373
|
service.download_file \
|
380
374
|
bucket, name, path,
|
381
|
-
key: encryption_key
|
375
|
+
key: encryption_key
|
382
376
|
verify_file! ::File.new(path), verify
|
383
377
|
end
|
384
378
|
|
@@ -387,8 +381,8 @@ module Google
|
|
387
381
|
#
|
388
382
|
# If a [customer-supplied encryption
|
389
383
|
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
390
|
-
# was used with {Bucket#create_file}, the `encryption_key`
|
391
|
-
#
|
384
|
+
# was used with {Bucket#create_file}, the `encryption_key` option must
|
385
|
+
# be provided.
|
392
386
|
#
|
393
387
|
# @param [String] dest_bucket_or_path Either the bucket to copy the file
|
394
388
|
# to, or the path to copy the file to in the current bucket.
|
@@ -417,12 +411,7 @@ module Google
|
|
417
411
|
# copy. The default is the latest version.
|
418
412
|
# @param [String] encryption_key Optional. The customer-supplied,
|
419
413
|
# AES-256 encryption key used to encrypt the file, if one was provided
|
420
|
-
# to {Bucket#create_file}.
|
421
|
-
# is provided.
|
422
|
-
# @param [String] encryption_key_sha256 Optional. The SHA256 hash of the
|
423
|
-
# customer-supplied, AES-256 encryption key used to encrypt the file,
|
424
|
-
# if one was provided to {Bucket#create_file}. Must be provided if
|
425
|
-
# `encryption_key` is provided.
|
414
|
+
# to {Bucket#create_file}.
|
426
415
|
#
|
427
416
|
# @return [Google::Cloud::Storage::File]
|
428
417
|
#
|
@@ -448,15 +437,21 @@ module Google
|
|
448
437
|
# "path/to/destination/file.ext"
|
449
438
|
#
|
450
439
|
# @example The file can also be copied by specifying a generation:
|
440
|
+
# require "google/cloud/storage"
|
441
|
+
#
|
442
|
+
# storage = Google::Cloud::Storage.new
|
443
|
+
#
|
444
|
+
# bucket = storage.bucket "my-bucket"
|
445
|
+
#
|
446
|
+
# file = bucket.file "path/to/my-file.ext"
|
451
447
|
# file.copy "copy/of/previous/generation/file.ext",
|
452
448
|
# generation: 123456
|
453
449
|
#
|
454
450
|
def copy dest_bucket_or_path, dest_path = nil, acl: nil,
|
455
|
-
generation: nil, encryption_key: nil
|
456
|
-
encryption_key_sha256: nil
|
451
|
+
generation: nil, encryption_key: nil
|
457
452
|
ensure_service!
|
458
453
|
options = { acl: acl, generation: generation,
|
459
|
-
key: encryption_key
|
454
|
+
key: encryption_key }
|
460
455
|
dest_bucket, dest_path, options = fix_copy_args dest_bucket_or_path,
|
461
456
|
dest_path, options
|
462
457
|
|
@@ -272,7 +272,7 @@ module Google
|
|
272
272
|
# b.website_404 = "not_found.html"
|
273
273
|
# b.cors.add_rule ["http://example.org", "https://example.org"],
|
274
274
|
# "*",
|
275
|
-
#
|
275
|
+
# headers: ["X-My-Custom-Header"],
|
276
276
|
# max_age: 300
|
277
277
|
# end
|
278
278
|
#
|
@@ -171,7 +171,7 @@ module Google
|
|
171
171
|
cache_control: nil, content_disposition: nil,
|
172
172
|
content_encoding: nil, content_language: nil,
|
173
173
|
content_type: nil, crc32c: nil, md5: nil, metadata: nil,
|
174
|
-
key: nil
|
174
|
+
key: nil
|
175
175
|
file_obj = Google::Apis::StorageV1::Object.new \
|
176
176
|
cache_control: cache_control, content_type: content_type,
|
177
177
|
content_disposition: content_disposition, md5_hash: md5,
|
@@ -183,19 +183,18 @@ module Google
|
|
183
183
|
bucket_name, file_obj,
|
184
184
|
name: path, predefined_acl: acl, upload_source: source,
|
185
185
|
content_encoding: content_encoding, content_type: content_type,
|
186
|
-
options: key_options(key
|
186
|
+
options: key_options(key)
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
190
|
##
|
191
191
|
# Retrieves an object or its metadata.
|
192
|
-
def get_file bucket_name, file_path, generation: nil, key: nil
|
193
|
-
key_sha256: nil
|
192
|
+
def get_file bucket_name, file_path, generation: nil, key: nil
|
194
193
|
execute do
|
195
194
|
service.get_object \
|
196
195
|
bucket_name, file_path,
|
197
196
|
generation: generation,
|
198
|
-
options: key_options(key
|
197
|
+
options: key_options(key)
|
199
198
|
end
|
200
199
|
end
|
201
200
|
|
@@ -210,20 +209,19 @@ module Google
|
|
210
209
|
destination_bucket_name, destination_file_path,
|
211
210
|
destination_predefined_acl: options[:acl],
|
212
211
|
source_generation: options[:generation],
|
213
|
-
options: key_options(
|
214
|
-
key_sha256: options[:key_sha256])
|
212
|
+
options: key_options(options[:key])
|
215
213
|
end
|
216
214
|
end
|
217
215
|
|
218
216
|
##
|
219
217
|
# Download contents of a file.
|
220
218
|
def download_file bucket_name, file_path, target_path, generation: nil,
|
221
|
-
key: nil
|
219
|
+
key: nil
|
222
220
|
execute do
|
223
221
|
service.get_object \
|
224
222
|
bucket_name, file_path,
|
225
223
|
download_dest: target_path, generation: generation,
|
226
|
-
options: key_options(key
|
224
|
+
options: key_options(key)
|
227
225
|
end
|
228
226
|
end
|
229
227
|
|
@@ -285,13 +283,13 @@ module Google
|
|
285
283
|
|
286
284
|
protected
|
287
285
|
|
288
|
-
def key_options key
|
286
|
+
def key_options key
|
289
287
|
options = {}
|
290
288
|
if key
|
289
|
+
key_sha256 = Digest::SHA256.digest key
|
291
290
|
headers = {}
|
292
291
|
headers["x-goog-encryption-algorithm"] = "AES256"
|
293
292
|
headers["x-goog-encryption-key"] = Base64.strict_encode64 key
|
294
|
-
key_sha256 ||= Digest::SHA256.digest key
|
295
293
|
headers["x-goog-encryption-key-sha256"] = \
|
296
294
|
Base64.strict_encode64 key_sha256
|
297
295
|
options[:header] = headers
|
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: 0.
|
4
|
+
version: 0.23.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: 2016-
|
12
|
+
date: 2016-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: google-cloud-core
|
@@ -171,14 +171,14 @@ dependencies:
|
|
171
171
|
requirements:
|
172
172
|
- - "~>"
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: 0.1.
|
174
|
+
version: 0.1.8
|
175
175
|
type: :development
|
176
176
|
prerelease: false
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
179
|
- - "~>"
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: 0.1.
|
181
|
+
version: 0.1.8
|
182
182
|
description: google-cloud-storage is the official library for Google Cloud Storage.
|
183
183
|
email:
|
184
184
|
- mike@blowmage.com
|
@@ -187,6 +187,9 @@ executables: []
|
|
187
187
|
extensions: []
|
188
188
|
extra_rdoc_files: []
|
189
189
|
files:
|
190
|
+
- ".yardopts"
|
191
|
+
- LICENSE
|
192
|
+
- README.md
|
190
193
|
- lib/google-cloud-storage.rb
|
191
194
|
- lib/google/cloud/storage.rb
|
192
195
|
- lib/google/cloud/storage/bucket.rb
|
@@ -222,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
225
|
version: '0'
|
223
226
|
requirements: []
|
224
227
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.4.5.1
|
226
229
|
signing_key:
|
227
230
|
specification_version: 4
|
228
231
|
summary: API Client library for Google Cloud Storage
|