google-cloud-storage 1.13.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -1
- data/README.md +20 -11
- data/lib/google-cloud-storage.rb +4 -4
- data/lib/google/cloud/storage.rb +2 -602
- data/lib/google/cloud/storage/bucket.rb +93 -17
- data/lib/google/cloud/storage/bucket/cors.rb +57 -0
- data/lib/google/cloud/storage/bucket/lifecycle.rb +355 -0
- data/lib/google/cloud/storage/convert.rb +40 -0
- data/lib/google/cloud/storage/file.rb +2 -12
- data/lib/google/cloud/storage/notification.rb +3 -3
- data/lib/google/cloud/storage/project.rb +7 -13
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f89f223328cb434f1b1f27c38475d5608f83be9b7adb358aa65691d90933ea
|
4
|
+
data.tar.gz: be494fa2f05dd9c00e4d4b0059ca3d654019703f5fadc844b8d3e203163b1e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1d7fcfa4de5d70f6dcfd72067cda51a44bbdc74358f54e1a52658965b34b2a6ac15e32c2226fafdf72ccc7f447edecb395f45a50c00c154bb87413aacdbe5a7
|
7
|
+
data.tar.gz: 2d06a35d929cdf7b7909a2407a3cb7886a604e58c58461b427a92c703f1241848df9605810ba957358552ab9069c033d2b14b9b9de27aa4f2814868d5d44ba61
|
data/.yardopts
CHANGED
@@ -2,7 +2,15 @@
|
|
2
2
|
--title=Google Cloud Storage
|
3
3
|
--markup markdown
|
4
4
|
--markup-provider redcarpet
|
5
|
+
--main OVERVIEW.md
|
5
6
|
|
6
7
|
./lib/**/*.rb
|
7
8
|
-
|
8
|
-
|
9
|
+
OVERVIEW.md
|
10
|
+
AUTHENTICATION.md
|
11
|
+
LOGGING.md
|
12
|
+
CONTRIBUTING.md
|
13
|
+
TROUBLESHOOTING.md
|
14
|
+
CHANGELOG.md
|
15
|
+
CODE_OF_CONDUCT.md
|
16
|
+
LICENSE
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
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
4
|
|
5
|
-
- [google-cloud-storage API documentation](http://googlecloudplatform.github.io/google-cloud-ruby
|
5
|
+
- [google-cloud-storage API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-storage/latest)
|
6
6
|
- [google-cloud-storage on RubyGems](https://rubygems.org/gems/google-cloud-storage)
|
7
7
|
- [Google Cloud Storage documentation](https://cloud.google.com/storage/docs)
|
8
8
|
|
@@ -16,7 +16,7 @@ $ gem install google-cloud-storage
|
|
16
16
|
|
17
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
18
|
|
19
|
-
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby
|
19
|
+
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-storage/latest/file.AUTHENTICATION).
|
20
20
|
|
21
21
|
## Example
|
22
22
|
|
@@ -42,7 +42,7 @@ file.copy backup, file.name
|
|
42
42
|
|
43
43
|
## Enabling Logging
|
44
44
|
|
45
|
-
To enable logging for this library, set the logger for the underlying [Google API Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby
|
45
|
+
To enable logging for this library, set the logger for the underlying [Google API Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-logging/latest/Google/Cloud/Logging/Logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/).
|
46
46
|
|
47
47
|
If you do not set the logger explicitly and your application is running in a Rails environment, it will default to `Rails.logger`. Otherwise, if you do not set the logger and you are not using Rails, logging is disabled by default.
|
48
48
|
|
@@ -63,9 +63,9 @@ Google::Apis.logger = my_logger
|
|
63
63
|
This library is supported on Ruby 2.3+.
|
64
64
|
|
65
65
|
Google provides official support for Ruby versions that are actively supported
|
66
|
-
by Ruby Core—that is, Ruby versions that are either in normal maintenance or
|
67
|
-
|
68
|
-
|
66
|
+
by Ruby Core—that is, Ruby versions that are either in normal maintenance or in
|
67
|
+
security maintenance, and not end of life. Currently, this means Ruby 2.3 and
|
68
|
+
later. Older versions of Ruby _may_ still work, but are unsupported and not
|
69
69
|
recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
|
70
70
|
about the Ruby support schedule.
|
71
71
|
|
@@ -77,15 +77,24 @@ This library follows [Semantic Versioning](http://semver.org/).
|
|
77
77
|
|
78
78
|
Contributions to this library are always welcome and highly encouraged.
|
79
79
|
|
80
|
-
See the [Contributing
|
80
|
+
See the [Contributing
|
81
|
+
Guide](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-storage/latest/file.CONTRIBUTING)
|
82
|
+
for more information on how to get started.
|
81
83
|
|
82
|
-
Please note that this project is released with a Contributor Code of Conduct. By
|
84
|
+
Please note that this project is released with a Contributor Code of Conduct. By
|
85
|
+
participating in this project you agree to abide by its terms. See [Code of
|
86
|
+
Conduct](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-storage/latest/file.CODE_OF_CONDUCT)
|
87
|
+
for more information.
|
83
88
|
|
84
89
|
## License
|
85
90
|
|
86
|
-
This library is licensed under Apache 2.0. Full license text is available in
|
91
|
+
This library is licensed under Apache 2.0. Full license text is available in
|
92
|
+
[LICENSE](https://googlecloudplatform.github.io/google-cloud-ruby/docs/google-cloud-storage/latest/file.LICENSE).
|
87
93
|
|
88
94
|
## Support
|
89
95
|
|
90
|
-
Please [report bugs at the project on
|
91
|
-
|
96
|
+
Please [report bugs at the project on
|
97
|
+
Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues). Don't
|
98
|
+
hesitate to [ask
|
99
|
+
questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby)
|
100
|
+
about the client or APIs on [StackOverflow](http://stackoverflow.com).
|
data/lib/google-cloud-storage.rb
CHANGED
@@ -29,8 +29,8 @@ module Google
|
|
29
29
|
# Creates a new object for connecting to the Storage service.
|
30
30
|
# Each call creates a new connection.
|
31
31
|
#
|
32
|
-
# For more information on connecting to Google Cloud see the
|
33
|
-
# Guide
|
32
|
+
# For more information on connecting to Google Cloud see the
|
33
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
34
34
|
#
|
35
35
|
# @see https://cloud.google.com/storage/docs/authentication#oauth Storage
|
36
36
|
# OAuth 2.0 Authentication
|
@@ -74,8 +74,8 @@ module Google
|
|
74
74
|
# Creates a new object for connecting to the Storage service.
|
75
75
|
# Each call creates a new connection.
|
76
76
|
#
|
77
|
-
# For more information on connecting to Google Cloud see the
|
78
|
-
# Guide
|
77
|
+
# For more information on connecting to Google Cloud see the
|
78
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
79
79
|
#
|
80
80
|
# @param [String] project_id Project identifier for the Storage service
|
81
81
|
# you are connecting to. If not present, the default project for the
|
data/lib/google/cloud/storage.rb
CHANGED
@@ -29,606 +29,7 @@ module Google
|
|
29
29
|
# networking infrastructure to perform data operations in a cost effective
|
30
30
|
# manner.
|
31
31
|
#
|
32
|
-
#
|
33
|
-
# Rubyists. Your authentication credentials are detected automatically in
|
34
|
-
# Google Cloud Platform environments such as Google Compute Engine, Google
|
35
|
-
# App Engine and Google Kubernetes Engine. In other environments you can
|
36
|
-
# configure authentication easily, either directly in your code or via
|
37
|
-
# environment variables. Read more about the options for connecting in the
|
38
|
-
# [Authentication
|
39
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
40
|
-
#
|
41
|
-
# ```ruby
|
42
|
-
# require "google/cloud/storage"
|
43
|
-
#
|
44
|
-
# storage = Google::Cloud::Storage.new(
|
45
|
-
# project_id: "my-project",
|
46
|
-
# credentials: "/path/to/keyfile.json"
|
47
|
-
# )
|
48
|
-
#
|
49
|
-
# bucket = storage.bucket "my-bucket"
|
50
|
-
# file = bucket.file "path/to/my-file.ext"
|
51
|
-
# ```
|
52
|
-
#
|
53
|
-
# You can learn more about various options for connection on the
|
54
|
-
# [Authentication
|
55
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
56
|
-
#
|
57
|
-
# To learn more about Cloud Storage, read the
|
58
|
-
# [Google Cloud Storage Overview
|
59
|
-
# ](https://cloud.google.com/storage/docs/overview).
|
60
|
-
#
|
61
|
-
# ## Enabling Logging
|
62
|
-
#
|
63
|
-
# To enable logging for this library, set the logger for the underlying
|
64
|
-
# [Google API Client](https://github.com/google/google-api-ruby-client/blob/master/README.md#logging)
|
65
|
-
# library. The logger that you set may be a Ruby stdlib
|
66
|
-
# [`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html)
|
67
|
-
# as shown below, or a
|
68
|
-
# [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
|
69
|
-
# that will write logs to [Stackdriver
|
70
|
-
# Logging](https://cloud.google.com/logging/).
|
71
|
-
#
|
72
|
-
# If you do not set the logger explicitly and your application is running in
|
73
|
-
# a Rails environment, it will default to `Rails.logger`. Otherwise, if you
|
74
|
-
# do not set the logger and you are not using Rails, logging is disabled by
|
75
|
-
# default.
|
76
|
-
#
|
77
|
-
# Configuring a Ruby stdlib logger:
|
78
|
-
#
|
79
|
-
# ```ruby
|
80
|
-
# require "logger"
|
81
|
-
#
|
82
|
-
# my_logger = Logger.new $stderr
|
83
|
-
# my_logger.level = Logger::WARN
|
84
|
-
#
|
85
|
-
# # Set the Google API Client logger
|
86
|
-
# Google::Apis.logger = my_logger
|
87
|
-
# ```
|
88
|
-
#
|
89
|
-
# ## Retrieving Buckets
|
90
|
-
#
|
91
|
-
# A {Google::Cloud::Storage::Bucket} instance is a container for your data.
|
92
|
-
# There is no limit on the number of buckets that you can create in a
|
93
|
-
# project. You can use buckets to organize and control access to your data.
|
94
|
-
# For more information, see [Working with
|
95
|
-
# Buckets](https://cloud.google.com/storage/docs/creating-buckets).
|
96
|
-
#
|
97
|
-
# Each bucket has a globally unique name, which is how they are retrieved:
|
98
|
-
# (See {Google::Cloud::Storage::Project#bucket})
|
99
|
-
#
|
100
|
-
# ```ruby
|
101
|
-
# require "google/cloud/storage"
|
102
|
-
#
|
103
|
-
# storage = Google::Cloud::Storage.new
|
104
|
-
#
|
105
|
-
# bucket = storage.bucket "my-todo-app"
|
106
|
-
# ```
|
107
|
-
#
|
108
|
-
# You can also retrieve all buckets on a project: (See
|
109
|
-
# {Google::Cloud::Storage::Project#buckets})
|
110
|
-
#
|
111
|
-
# ```ruby
|
112
|
-
# require "google/cloud/storage"
|
113
|
-
#
|
114
|
-
# storage = Google::Cloud::Storage.new
|
115
|
-
#
|
116
|
-
# all_buckets = storage.buckets
|
117
|
-
# ```
|
118
|
-
#
|
119
|
-
# If you have a significant number of buckets, you may need to fetch them
|
120
|
-
# in multiple service requests.
|
121
|
-
#
|
122
|
-
# Iterating over each bucket, potentially with multiple API calls, by
|
123
|
-
# invoking `all` with a block:
|
124
|
-
#
|
125
|
-
# ```ruby
|
126
|
-
# require "google/cloud/storage"
|
127
|
-
#
|
128
|
-
# storage = Google::Cloud::Storage.new
|
129
|
-
#
|
130
|
-
# buckets = storage.buckets
|
131
|
-
# buckets.all do |bucket|
|
132
|
-
# puts bucket.name
|
133
|
-
# end
|
134
|
-
# ```
|
135
|
-
#
|
136
|
-
# Limiting the number of API calls made:
|
137
|
-
#
|
138
|
-
# ```ruby
|
139
|
-
# require "google/cloud/storage"
|
140
|
-
#
|
141
|
-
# storage = Google::Cloud::Storage.new
|
142
|
-
#
|
143
|
-
# buckets = storage.buckets
|
144
|
-
# buckets.all(request_limit: 10) do |bucket|
|
145
|
-
# puts bucket.name
|
146
|
-
# end
|
147
|
-
# ```
|
148
|
-
#
|
149
|
-
# See {Google::Cloud::Storage::Bucket::List} for details.
|
150
|
-
#
|
151
|
-
# ## Creating a Bucket
|
152
|
-
#
|
153
|
-
# A unique name is all that is needed to create a new bucket: (See
|
154
|
-
# {Google::Cloud::Storage::Project#create_bucket})
|
155
|
-
#
|
156
|
-
# ```ruby
|
157
|
-
# require "google/cloud/storage"
|
158
|
-
#
|
159
|
-
# storage = Google::Cloud::Storage.new
|
160
|
-
#
|
161
|
-
# bucket = storage.create_bucket "my-todo-app-attachments"
|
162
|
-
# ```
|
163
|
-
#
|
164
|
-
# ## Retrieving Files
|
165
|
-
#
|
166
|
-
# A {Google::Cloud::Storage::File} instance is an individual data object
|
167
|
-
# that you store in Google Cloud Storage. Files contain the data stored as
|
168
|
-
# well as metadata describing the data. Files belong to a bucket and cannot
|
169
|
-
# be shared among buckets. There is no limit on the number of files that
|
170
|
-
# you can create in a bucket. For more information, see [Working with
|
171
|
-
# Objects](https://cloud.google.com/storage/docs/object-basics).
|
172
|
-
#
|
173
|
-
# Files are retrieved by their name, which is the path of the file in the
|
174
|
-
# bucket: (See {Google::Cloud::Storage::Bucket#file})
|
175
|
-
#
|
176
|
-
# ```ruby
|
177
|
-
# require "google/cloud/storage"
|
178
|
-
#
|
179
|
-
# storage = Google::Cloud::Storage.new
|
180
|
-
#
|
181
|
-
# bucket = storage.bucket "my-todo-app"
|
182
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
183
|
-
# ```
|
184
|
-
#
|
185
|
-
# You can also retrieve all files in a bucket: (See Bucket#files)
|
186
|
-
#
|
187
|
-
# ```ruby
|
188
|
-
# require "google/cloud/storage"
|
189
|
-
#
|
190
|
-
# storage = Google::Cloud::Storage.new
|
191
|
-
#
|
192
|
-
# bucket = storage.bucket "my-todo-app"
|
193
|
-
# all_files = bucket.files
|
194
|
-
# ```
|
195
|
-
#
|
196
|
-
# Or you can retrieve all files in a specified path:
|
197
|
-
#
|
198
|
-
# ```ruby
|
199
|
-
# require "google/cloud/storage"
|
200
|
-
#
|
201
|
-
# storage = Google::Cloud::Storage.new
|
202
|
-
#
|
203
|
-
# bucket = storage.bucket "my-todo-app"
|
204
|
-
# avatar_files = bucket.files prefix: "avatars/"
|
205
|
-
# ```
|
206
|
-
#
|
207
|
-
# If you have a significant number of files, you may need to fetch them
|
208
|
-
# in multiple service requests.
|
209
|
-
#
|
210
|
-
# Iterating over each file, potentially with multiple API calls, by
|
211
|
-
# invoking `all` with a block:
|
212
|
-
#
|
213
|
-
# ```ruby
|
214
|
-
# require "google/cloud/storage"
|
215
|
-
#
|
216
|
-
# storage = Google::Cloud::Storage.new
|
217
|
-
# bucket = storage.bucket "my-todo-app"
|
218
|
-
#
|
219
|
-
# files = storage.files
|
220
|
-
# files.all do |file|
|
221
|
-
# puts file.name
|
222
|
-
# end
|
223
|
-
# ```
|
224
|
-
#
|
225
|
-
# Limiting the number of API calls made:
|
226
|
-
#
|
227
|
-
# ```ruby
|
228
|
-
# require "google/cloud/storage"
|
229
|
-
#
|
230
|
-
# storage = Google::Cloud::Storage.new
|
231
|
-
#
|
232
|
-
# files = storage.files
|
233
|
-
# files.all(request_limit: 10) do |file|
|
234
|
-
# puts bucket.name
|
235
|
-
# end
|
236
|
-
# ```
|
237
|
-
#
|
238
|
-
# See {Google::Cloud::Storage::File::List} for details.
|
239
|
-
#
|
240
|
-
# ## Creating a File
|
241
|
-
#
|
242
|
-
# A new file can be uploaded by specifying the location of a file on the
|
243
|
-
# local file system, and the name/path that the file should be stored in the
|
244
|
-
# bucket. (See {Google::Cloud::Storage::Bucket#create_file})
|
245
|
-
#
|
246
|
-
# ```ruby
|
247
|
-
# require "google/cloud/storage"
|
248
|
-
#
|
249
|
-
# storage = Google::Cloud::Storage.new
|
250
|
-
#
|
251
|
-
# bucket = storage.bucket "my-todo-app"
|
252
|
-
# bucket.create_file "/var/todo-app/avatars/heidi/400x400.png",
|
253
|
-
# "avatars/heidi/400x400.png"
|
254
|
-
# ```
|
255
|
-
#
|
256
|
-
# Files can also be created from an in-memory StringIO object:
|
257
|
-
#
|
258
|
-
# ```ruby
|
259
|
-
# require "google/cloud/storage"
|
260
|
-
#
|
261
|
-
# storage = Google::Cloud::Storage.new
|
262
|
-
#
|
263
|
-
# bucket = storage.bucket "my-todo-app"
|
264
|
-
# bucket.create_file StringIO.new("Hello world!"), "hello-world.txt"
|
265
|
-
# ```
|
266
|
-
#
|
267
|
-
# ### Customer-supplied encryption keys
|
268
|
-
#
|
269
|
-
# By default, Google Cloud Storage manages server-side encryption keys on
|
270
|
-
# your behalf. However, a [customer-supplied encryption
|
271
|
-
# key](https://cloud.google.com/storage/docs/encryption#customer-supplied)
|
272
|
-
# can be provided with the `encryption_key` option. If given, the same key
|
273
|
-
# must be provided to subsequently download or copy the file. If you use
|
274
|
-
# customer-supplied encryption keys, you must securely manage your keys and
|
275
|
-
# ensure that they are not lost. Also, please note that file metadata is not
|
276
|
-
# encrypted, with the exception of the CRC32C checksum and MD5 hash. The
|
277
|
-
# names of files and buckets are also not encrypted, and you can read or
|
278
|
-
# update the metadata of an encrypted file without providing the encryption
|
279
|
-
# key.
|
280
|
-
#
|
281
|
-
# ```ruby
|
282
|
-
# require "google/cloud/storage"
|
283
|
-
#
|
284
|
-
# storage = Google::Cloud::Storage.new
|
285
|
-
# bucket = storage.bucket "my-todo-app"
|
286
|
-
#
|
287
|
-
# # Key generation shown for example purposes only. Write your own.
|
288
|
-
# cipher = OpenSSL::Cipher.new "aes-256-cfb"
|
289
|
-
# cipher.encrypt
|
290
|
-
# key = cipher.random_key
|
291
|
-
#
|
292
|
-
# bucket.create_file "/var/todo-app/avatars/heidi/400x400.png",
|
293
|
-
# "avatars/heidi/400x400.png",
|
294
|
-
# encryption_key: key
|
295
|
-
#
|
296
|
-
# # Store your key and hash securely for later use.
|
297
|
-
# file = bucket.file "avatars/heidi/400x400.png",
|
298
|
-
# encryption_key: key
|
299
|
-
# ```
|
300
|
-
#
|
301
|
-
# Use {Google::Cloud::Storage::File#rotate} to rotate customer-supplied
|
302
|
-
# encryption keys.
|
303
|
-
#
|
304
|
-
# ```ruby
|
305
|
-
# require "google/cloud/storage"
|
306
|
-
#
|
307
|
-
# storage = Google::Cloud::Storage.new
|
308
|
-
# bucket = storage.bucket "my-todo-app"
|
309
|
-
#
|
310
|
-
# # Old key was stored securely for later use.
|
311
|
-
# old_key = "y\x03\"\x0E\xB6\xD3\x9B\x0E\xAB*\x19\xFAv\xDEY\xBEI..."
|
312
|
-
#
|
313
|
-
# file = bucket.file "path/to/my-file.ext", encryption_key: old_key
|
314
|
-
#
|
315
|
-
# # Key generation shown for example purposes only. Write your own.
|
316
|
-
# cipher = OpenSSL::Cipher.new "aes-256-cfb"
|
317
|
-
# cipher.encrypt
|
318
|
-
# new_key = cipher.random_key
|
319
|
-
#
|
320
|
-
# file.rotate encryption_key: old_key, new_encryption_key: new_key
|
321
|
-
# ```
|
322
|
-
#
|
323
|
-
# ## Downloading a File
|
324
|
-
#
|
325
|
-
# Files can be downloaded to the local file system. (See
|
326
|
-
# {Google::Cloud::Storage::File#download})
|
327
|
-
#
|
328
|
-
# ```ruby
|
329
|
-
# require "google/cloud/storage"
|
330
|
-
#
|
331
|
-
# storage = Google::Cloud::Storage.new
|
332
|
-
#
|
333
|
-
# bucket = storage.bucket "my-todo-app"
|
334
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
335
|
-
# file.download "/var/todo-app/avatars/heidi/400x400.png"
|
336
|
-
# ```
|
337
|
-
#
|
338
|
-
# Files can also be downloaded to an in-memory StringIO object:
|
339
|
-
#
|
340
|
-
# ```ruby
|
341
|
-
# require "google/cloud/storage"
|
342
|
-
#
|
343
|
-
# storage = Google::Cloud::Storage.new
|
344
|
-
#
|
345
|
-
# bucket = storage.bucket "my-todo-app"
|
346
|
-
# file = bucket.file "hello-world.txt"
|
347
|
-
#
|
348
|
-
# downloaded = file.download
|
349
|
-
# downloaded.rewind
|
350
|
-
# downloaded.read #=> "Hello world!"
|
351
|
-
# ```
|
352
|
-
#
|
353
|
-
# Download a public file with an anonymous, unauthenticated client. Use
|
354
|
-
# `skip_lookup` to avoid errors retrieving non-public bucket and file
|
355
|
-
# metadata.
|
356
|
-
#
|
357
|
-
# ```ruby
|
358
|
-
# require "google/cloud/storage"
|
359
|
-
#
|
360
|
-
# storage = Google::Cloud::Storage.anonymous
|
361
|
-
#
|
362
|
-
# bucket = storage.bucket "public-bucket", skip_lookup: true
|
363
|
-
# file = bucket.file "path/to/public-file.ext", skip_lookup: true
|
364
|
-
#
|
365
|
-
# downloaded = file.download
|
366
|
-
# downloaded.rewind
|
367
|
-
# downloaded.read #=> "Hello world!"
|
368
|
-
# ```
|
369
|
-
#
|
370
|
-
# ## Creating and downloading gzip-encoded files
|
371
|
-
#
|
372
|
-
# When uploading a gzip-compressed file, you should pass
|
373
|
-
# `content_encoding: "gzip"` if you want the file to be eligible for
|
374
|
-
# [decompressive transcoding](https://cloud.google.com/storage/docs/transcoding)
|
375
|
-
# when it is later downloaded. In addition, giving the gzip-compressed file
|
376
|
-
# a name containing the original file extension (for example, `.txt`) will
|
377
|
-
# ensure that the file's `Content-Type` metadata is set correctly. (You can
|
378
|
-
# also set the file's `Content-Type` metadata explicitly with the
|
379
|
-
# `content_type` option.)
|
380
|
-
#
|
381
|
-
# ```ruby
|
382
|
-
# require "zlib"
|
383
|
-
# require "google/cloud/storage"
|
384
|
-
#
|
385
|
-
# storage = Google::Cloud::Storage.new
|
386
|
-
#
|
387
|
-
# gz = StringIO.new ""
|
388
|
-
# z = Zlib::GzipWriter.new gz
|
389
|
-
# z.write "Hello world!"
|
390
|
-
# z.close
|
391
|
-
# data = StringIO.new gz.string
|
392
|
-
#
|
393
|
-
# bucket = storage.bucket "my-bucket"
|
394
|
-
#
|
395
|
-
# bucket.create_file data, "path/to/gzipped.txt",
|
396
|
-
# content_encoding: "gzip"
|
397
|
-
#
|
398
|
-
# file = bucket.file "path/to/gzipped.txt"
|
399
|
-
#
|
400
|
-
# # The downloaded data is decompressed by default.
|
401
|
-
# file.download "path/to/downloaded/hello.txt"
|
402
|
-
#
|
403
|
-
# # The downloaded data remains compressed with skip_decompress.
|
404
|
-
# file.download "path/to/downloaded/gzipped.txt",
|
405
|
-
# skip_decompress: true
|
406
|
-
# ```
|
407
|
-
#
|
408
|
-
# ## Using Signed URLs
|
409
|
-
#
|
410
|
-
# Access without authentication can be granted to a file for a specified
|
411
|
-
# period of time. This URL uses a cryptographic signature of your
|
412
|
-
# credentials to access the file. (See
|
413
|
-
# {Google::Cloud::Storage::File#signed_url})
|
414
|
-
#
|
415
|
-
# ```ruby
|
416
|
-
# require "google/cloud/storage"
|
417
|
-
#
|
418
|
-
# storage = Google::Cloud::Storage.new
|
419
|
-
#
|
420
|
-
# bucket = storage.bucket "my-todo-app"
|
421
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
422
|
-
# shared_url = file.signed_url method: "GET",
|
423
|
-
# expires: 300 # 5 minutes from now
|
424
|
-
# ```
|
425
|
-
#
|
426
|
-
# ## Controlling Access to a Bucket
|
427
|
-
#
|
428
|
-
# Access to a bucket is controlled with
|
429
|
-
# {Google::Cloud::Storage::Bucket#acl}. A bucket has owners, writers, and
|
430
|
-
# readers. Permissions can be granted to an individual user's email address,
|
431
|
-
# a group's email address, as well as many predefined lists. See the [Access
|
432
|
-
# Control guide](https://cloud.google.com/storage/docs/access-control) for
|
433
|
-
# more.
|
434
|
-
#
|
435
|
-
# Access to a bucket can be granted to a user by appending `"user-"` to the
|
436
|
-
# email address:
|
437
|
-
#
|
438
|
-
# ```ruby
|
439
|
-
# require "google/cloud/storage"
|
440
|
-
#
|
441
|
-
# storage = Google::Cloud::Storage.new
|
442
|
-
#
|
443
|
-
# bucket = storage.bucket "my-todo-app"
|
444
|
-
#
|
445
|
-
# email = "heidi@example.net"
|
446
|
-
# bucket.acl.add_reader "user-#{email}"
|
447
|
-
# ```
|
448
|
-
#
|
449
|
-
# Access to a bucket can be granted to a group by appending `"group-"` to
|
450
|
-
# the email address:
|
451
|
-
#
|
452
|
-
# ```ruby
|
453
|
-
# require "google/cloud/storage"
|
454
|
-
#
|
455
|
-
# storage = Google::Cloud::Storage.new
|
456
|
-
#
|
457
|
-
# bucket = storage.bucket "my-todo-app"
|
458
|
-
#
|
459
|
-
# email = "authors@example.net"
|
460
|
-
# bucket.acl.add_reader "group-#{email}"
|
461
|
-
# ```
|
462
|
-
#
|
463
|
-
# Access to a bucket can also be granted to a predefined list of
|
464
|
-
# permissions:
|
465
|
-
#
|
466
|
-
# ```ruby
|
467
|
-
# require "google/cloud/storage"
|
468
|
-
#
|
469
|
-
# storage = Google::Cloud::Storage.new
|
470
|
-
#
|
471
|
-
# bucket = storage.bucket "my-todo-app"
|
472
|
-
#
|
473
|
-
# bucket.acl.public!
|
474
|
-
# ```
|
475
|
-
#
|
476
|
-
# ## Controlling Access to a File
|
477
|
-
#
|
478
|
-
# Access to a file is controlled in two ways, either by the setting the
|
479
|
-
# default permissions to all files in a bucket with
|
480
|
-
# {Google::Cloud::Storage::Bucket#default_acl}, or by setting permissions to
|
481
|
-
# an individual file with {Google::Cloud::Storage::File#acl}.
|
482
|
-
#
|
483
|
-
# Access to a file can be granted to a user by appending `"user-"` to the
|
484
|
-
# email address:
|
485
|
-
#
|
486
|
-
# ```ruby
|
487
|
-
# require "google/cloud/storage"
|
488
|
-
#
|
489
|
-
# storage = Google::Cloud::Storage.new
|
490
|
-
#
|
491
|
-
# bucket = storage.bucket "my-todo-app"
|
492
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
493
|
-
#
|
494
|
-
# email = "heidi@example.net"
|
495
|
-
# file.acl.add_reader "user-#{email}"
|
496
|
-
# ```
|
497
|
-
#
|
498
|
-
# Access to a file can be granted to a group by appending `"group-"` to the
|
499
|
-
# email address:
|
500
|
-
#
|
501
|
-
# ```ruby
|
502
|
-
# require "google/cloud/storage"
|
503
|
-
#
|
504
|
-
# storage = Google::Cloud::Storage.new
|
505
|
-
#
|
506
|
-
# bucket = storage.bucket "my-todo-app"
|
507
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
508
|
-
#
|
509
|
-
# email = "authors@example.net"
|
510
|
-
# file.acl.add_reader "group-#{email}"
|
511
|
-
# ```
|
512
|
-
#
|
513
|
-
# Access to a file can also be granted to a predefined list of permissions:
|
514
|
-
#
|
515
|
-
# ```ruby
|
516
|
-
# require "google/cloud/storage"
|
517
|
-
#
|
518
|
-
# storage = Google::Cloud::Storage.new
|
519
|
-
#
|
520
|
-
# bucket = storage.bucket "my-todo-app"
|
521
|
-
# file = bucket.file "avatars/heidi/400x400.png"
|
522
|
-
#
|
523
|
-
# file.acl.public!
|
524
|
-
# ```
|
525
|
-
#
|
526
|
-
# ## Assigning payment to the requester
|
527
|
-
#
|
528
|
-
# The requester pays feature enables the owner of a bucket to indicate that
|
529
|
-
# a client accessing the bucket or a file it contains must assume the
|
530
|
-
# transit costs related to the access.
|
531
|
-
#
|
532
|
-
# Assign transit costs for bucket and file operations to requesting clients
|
533
|
-
# with the `requester_pays` flag:
|
534
|
-
#
|
535
|
-
# ```ruby
|
536
|
-
# require "google/cloud/storage"
|
537
|
-
#
|
538
|
-
# storage = Google::Cloud::Storage.new
|
539
|
-
#
|
540
|
-
# bucket = storage.bucket "my-bucket"
|
541
|
-
#
|
542
|
-
# bucket.requester_pays = true # API call
|
543
|
-
# # Clients must now provide `user_project` option when calling
|
544
|
-
# # Project#bucket to access this bucket.
|
545
|
-
# ```
|
546
|
-
#
|
547
|
-
# Once the `requester_pays` flag is enabled for a bucket, a client
|
548
|
-
# attempting to access the bucket and its files must provide the
|
549
|
-
# `user_project` option to {Project#bucket}. If the argument given is
|
550
|
-
# `true`, transit costs for operations on the requested bucket or a file it
|
551
|
-
# contains will be billed to the current project for the client. (See
|
552
|
-
# {Project#project} for the ID of the current project.)
|
553
|
-
#
|
554
|
-
# ```ruby
|
555
|
-
# require "google/cloud/storage"
|
556
|
-
#
|
557
|
-
# storage = Google::Cloud::Storage.new
|
558
|
-
#
|
559
|
-
# bucket = storage.bucket "other-project-bucket", user_project: true
|
560
|
-
#
|
561
|
-
# files = bucket.files # Billed to current project
|
562
|
-
# ```
|
563
|
-
#
|
564
|
-
# If the argument is a project ID string, and the indicated project is
|
565
|
-
# authorized for the currently authenticated service account, transit costs
|
566
|
-
# will be billed to the indicated project.
|
567
|
-
#
|
568
|
-
# ```ruby
|
569
|
-
# require "google/cloud/storage"
|
570
|
-
#
|
571
|
-
# storage = Google::Cloud::Storage.new
|
572
|
-
#
|
573
|
-
# bucket = storage.bucket "other-project-bucket",
|
574
|
-
# user_project: "my-other-project"
|
575
|
-
# files = bucket.files # Billed to "my-other-project"
|
576
|
-
# ```
|
577
|
-
#
|
578
|
-
# ## Configuring Pub/Sub notification subscriptions
|
579
|
-
#
|
580
|
-
# You can configure notifications to send Google Cloud Pub/Sub messages
|
581
|
-
# about changes to files in your buckets. For example, you can track files
|
582
|
-
# that are created and deleted in your bucket. Each notification contains
|
583
|
-
# information describing both the event that triggered it and the file that
|
584
|
-
# changed.
|
585
|
-
#
|
586
|
-
# You can send notifications to any Cloud Pub/Sub topic in any project for
|
587
|
-
# which your service account has sufficient permissions. As shown below, you
|
588
|
-
# need to explicitly grant permission to your service account to enable
|
589
|
-
# Google Cloud Storage to publish on behalf of your account. (Even if your
|
590
|
-
# current project created and owns the topic.)
|
591
|
-
#
|
592
|
-
# ```ruby
|
593
|
-
# require "google/cloud/pubsub"
|
594
|
-
# require "google/cloud/storage"
|
595
|
-
#
|
596
|
-
# pubsub = Google::Cloud::Pubsub.new
|
597
|
-
# topic = pubsub.create_topic "my-topic"
|
598
|
-
# topic.policy do |p|
|
599
|
-
# p.add "roles/pubsub.publisher",
|
600
|
-
# "serviceAccount:my-project" \
|
601
|
-
# "@gs-project-accounts.iam.gserviceaccount.com"
|
602
|
-
# end
|
603
|
-
#
|
604
|
-
# storage = Google::Cloud::Storage.new
|
605
|
-
# bucket = storage.bucket "my-bucket"
|
606
|
-
#
|
607
|
-
# notification = bucket.create_notification topic.name
|
608
|
-
# ```
|
609
|
-
#
|
610
|
-
# ## Configuring retries and timeout
|
611
|
-
#
|
612
|
-
# You can configure how many times API requests may be automatically
|
613
|
-
# retried. When an API request fails, the response will be inspected to see
|
614
|
-
# if the request meets criteria indicating that it may succeed on retry,
|
615
|
-
# such as `500` and `503` status codes or a specific internal error code
|
616
|
-
# such as `rateLimitExceeded`. If it meets the criteria, the request will be
|
617
|
-
# retried after a delay. If another error occurs, the delay will be
|
618
|
-
# increased before a subsequent attempt, until the `retries` limit is
|
619
|
-
# reached.
|
620
|
-
#
|
621
|
-
# You can also set the request `timeout` value in seconds.
|
622
|
-
#
|
623
|
-
# ```ruby
|
624
|
-
# require "google/cloud/storage"
|
625
|
-
#
|
626
|
-
# storage = Google::Cloud::Storage.new retries: 10, timeout: 120
|
627
|
-
# ```
|
628
|
-
#
|
629
|
-
# See the [Storage status and error
|
630
|
-
# codes](https://cloud.google.com/storage/docs/json_api/v1/status-codes)
|
631
|
-
# for a list of error conditions.
|
32
|
+
# See {file:OVERVIEW.md Storage Overview}.
|
632
33
|
#
|
633
34
|
module Storage
|
634
35
|
##
|
@@ -636,8 +37,7 @@ module Google
|
|
636
37
|
# Each call creates a new connection.
|
637
38
|
#
|
638
39
|
# For more information on connecting to Google Cloud see the
|
639
|
-
#
|
640
|
-
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
40
|
+
# {file:AUTHENTICATION.md Authentication Guide}.
|
641
41
|
#
|
642
42
|
# @param [String] project_id Project identifier for the Storage service
|
643
43
|
# you are connecting to. If not present, the default project for the
|