google-cloud-storage 0.20.2 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/google-cloud-storage.rb +3 -14
- data/lib/google/cloud/storage.rb +97 -61
- data/lib/google/cloud/storage/bucket.rb +120 -55
- data/lib/google/cloud/storage/bucket/acl.rb +65 -99
- data/lib/google/cloud/storage/bucket/cors.rb +4 -6
- data/lib/google/cloud/storage/bucket/list.rb +10 -15
- data/lib/google/cloud/storage/file.rb +48 -54
- data/lib/google/cloud/storage/file/acl.rb +31 -48
- data/lib/google/cloud/storage/file/list.rb +10 -15
- data/lib/google/cloud/storage/project.rb +29 -29
- data/lib/google/cloud/storage/service.rb +1 -2
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94a9b4984ad82c331f96b286defb5fe25cebce12
|
4
|
+
data.tar.gz: 7ed68558c6cb0db8cd0b431657607219482aa056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4361659e81aebc49a2c29e3ac77339835a1e893b0e4ea9029a08b3aa88f9a9313b2e75eadb54c4d6bca6ec2a68dafe99b967d89d7c99361768f48e45d187aad9
|
7
|
+
data.tar.gz: be19d2b6af46f535269f98d7aee9ca3145fd2b7a61d1a8e65529e758aebbb09231a2931b04c2a68f19737cef7171f19b207324543f9add28342827880b76052c
|
data/lib/google-cloud-storage.rb
CHANGED
@@ -105,20 +105,9 @@ module Google
|
|
105
105
|
def self.storage project = nil, keyfile = nil, scope: nil, retries: nil,
|
106
106
|
timeout: nil
|
107
107
|
require "google/cloud/storage"
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if keyfile.nil?
|
113
|
-
credentials = Google::Cloud::Storage::Credentials.default scope: scope
|
114
|
-
else
|
115
|
-
credentials = Google::Cloud::Storage::Credentials.new(
|
116
|
-
keyfile, scope: scope)
|
117
|
-
end
|
118
|
-
|
119
|
-
Google::Cloud::Storage::Project.new(
|
120
|
-
Google::Cloud::Storage::Service.new(
|
121
|
-
project, credentials, retries: retries, timeout: timeout))
|
108
|
+
Google::Cloud::Storage.new project: project, keyfile: keyfile,
|
109
|
+
scope: scope, retries: retries,
|
110
|
+
timeout: timeout
|
122
111
|
end
|
123
112
|
end
|
124
113
|
end
|
data/lib/google/cloud/storage.rb
CHANGED
@@ -34,11 +34,12 @@ module Google
|
|
34
34
|
# is taken care of for you.
|
35
35
|
#
|
36
36
|
# ```ruby
|
37
|
-
# require "google/cloud"
|
37
|
+
# require "google/cloud/storage"
|
38
38
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
39
|
+
# storage = Google::Cloud::Storage.new(
|
40
|
+
# project: "my-todo-project",
|
41
|
+
# keyfile: "/path/to/keyfile.json"
|
42
|
+
# )
|
42
43
|
#
|
43
44
|
# bucket = storage.bucket "my-bucket"
|
44
45
|
# file = bucket.file "path/to/my-file.ext"
|
@@ -61,10 +62,9 @@ module Google
|
|
61
62
|
# {Google::Cloud::Storage::Project#bucket})
|
62
63
|
#
|
63
64
|
# ```ruby
|
64
|
-
# require "google/cloud"
|
65
|
+
# require "google/cloud/storage"
|
65
66
|
#
|
66
|
-
#
|
67
|
-
# storage = gcloud.storage
|
67
|
+
# storage = Google::Cloud::Storage.new
|
68
68
|
#
|
69
69
|
# bucket = storage.bucket "my-todo-app"
|
70
70
|
# ```
|
@@ -73,10 +73,9 @@ module Google
|
|
73
73
|
# {Google::Cloud::Storage::Project#buckets})
|
74
74
|
#
|
75
75
|
# ```ruby
|
76
|
-
# require "google/cloud"
|
76
|
+
# require "google/cloud/storage"
|
77
77
|
#
|
78
|
-
#
|
79
|
-
# storage = gcloud.storage
|
78
|
+
# storage = Google::Cloud::Storage.new
|
80
79
|
#
|
81
80
|
# all_buckets = storage.buckets
|
82
81
|
# ```
|
@@ -85,10 +84,9 @@ module Google
|
|
85
84
|
# through them: (See {Google::Cloud::Storage::Bucket::List#token})
|
86
85
|
#
|
87
86
|
# ```ruby
|
88
|
-
# require "google/cloud"
|
87
|
+
# require "google/cloud/storage"
|
89
88
|
#
|
90
|
-
#
|
91
|
-
# storage = gcloud.storage
|
89
|
+
# storage = Google::Cloud::Storage.new
|
92
90
|
#
|
93
91
|
# all_buckets = []
|
94
92
|
# tmp_buckets = storage.buckets
|
@@ -109,10 +107,9 @@ module Google
|
|
109
107
|
# {Google::Cloud::Storage::Project#create_bucket})
|
110
108
|
#
|
111
109
|
# ```ruby
|
112
|
-
# require "google/cloud"
|
110
|
+
# require "google/cloud/storage"
|
113
111
|
#
|
114
|
-
#
|
115
|
-
# storage = gcloud.storage
|
112
|
+
# storage = Google::Cloud::Storage.new
|
116
113
|
#
|
117
114
|
# bucket = storage.create_bucket "my-todo-app-attachments"
|
118
115
|
# ```
|
@@ -128,10 +125,9 @@ module Google
|
|
128
125
|
# bucket: (See {Google::Cloud::Storage::Bucket#file})
|
129
126
|
#
|
130
127
|
# ```ruby
|
131
|
-
# require "google/cloud"
|
128
|
+
# require "google/cloud/storage"
|
132
129
|
#
|
133
|
-
#
|
134
|
-
# storage = gcloud.storage
|
130
|
+
# storage = Google::Cloud::Storage.new
|
135
131
|
#
|
136
132
|
# bucket = storage.bucket "my-todo-app"
|
137
133
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -140,10 +136,9 @@ module Google
|
|
140
136
|
# You can also retrieve all files in a bucket: (See Bucket#files)
|
141
137
|
#
|
142
138
|
# ```ruby
|
143
|
-
# require "google/cloud"
|
139
|
+
# require "google/cloud/storage"
|
144
140
|
#
|
145
|
-
#
|
146
|
-
# storage = gcloud.storage
|
141
|
+
# storage = Google::Cloud::Storage.new
|
147
142
|
#
|
148
143
|
# bucket = storage.bucket "my-todo-app"
|
149
144
|
# all_files = bucket.files
|
@@ -152,10 +147,9 @@ module Google
|
|
152
147
|
# Or you can retrieve all files in a specified path:
|
153
148
|
#
|
154
149
|
# ```ruby
|
155
|
-
# require "google/cloud"
|
150
|
+
# require "google/cloud/storage"
|
156
151
|
#
|
157
|
-
#
|
158
|
-
# storage = gcloud.storage
|
152
|
+
# storage = Google::Cloud::Storage.new
|
159
153
|
#
|
160
154
|
# bucket = storage.bucket "my-todo-app"
|
161
155
|
# avatar_files = bucket.files prefix: "avatars/"
|
@@ -165,10 +159,9 @@ module Google
|
|
165
159
|
# through them: (See {Google::Cloud::Storage::File::List#token})
|
166
160
|
#
|
167
161
|
# ```ruby
|
168
|
-
# require "google/cloud"
|
162
|
+
# require "google/cloud/storage"
|
169
163
|
#
|
170
|
-
#
|
171
|
-
# storage = gcloud.storage
|
164
|
+
# storage = Google::Cloud::Storage.new
|
172
165
|
#
|
173
166
|
# bucket = storage.bucket "my-todo-app"
|
174
167
|
#
|
@@ -192,10 +185,9 @@ module Google
|
|
192
185
|
# bucket. (See {Google::Cloud::Storage::Bucket#create_file})
|
193
186
|
#
|
194
187
|
# ```ruby
|
195
|
-
# require "google/cloud"
|
188
|
+
# require "google/cloud/storage"
|
196
189
|
#
|
197
|
-
#
|
198
|
-
# storage = gcloud.storage
|
190
|
+
# storage = Google::Cloud::Storage.new
|
199
191
|
#
|
200
192
|
# bucket = storage.bucket "my-todo-app"
|
201
193
|
# bucket.create_file "/var/todo-app/avatars/heidi/400x400.png",
|
@@ -217,11 +209,10 @@ module Google
|
|
217
209
|
# an encrypted file without providing the encryption key.
|
218
210
|
#
|
219
211
|
# ```ruby
|
220
|
-
# require "google/cloud"
|
212
|
+
# require "google/cloud/storage"
|
221
213
|
# require "digest/sha2"
|
222
214
|
#
|
223
|
-
#
|
224
|
-
# storage = gcloud.storage
|
215
|
+
# storage = Google::Cloud::Storage.new
|
225
216
|
# bucket = storage.bucket "my-todo-app"
|
226
217
|
#
|
227
218
|
# # Key generation shown for example purposes only. Write your own.
|
@@ -247,10 +238,9 @@ module Google
|
|
247
238
|
# {Google::Cloud::Storage::File#download})
|
248
239
|
#
|
249
240
|
# ```ruby
|
250
|
-
# require "google/cloud"
|
241
|
+
# require "google/cloud/storage"
|
251
242
|
#
|
252
|
-
#
|
253
|
-
# storage = gcloud.storage
|
243
|
+
# storage = Google::Cloud::Storage.new
|
254
244
|
#
|
255
245
|
# bucket = storage.bucket "my-todo-app"
|
256
246
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -265,10 +255,9 @@ module Google
|
|
265
255
|
# {Google::Cloud::Storage::File#signed_url})
|
266
256
|
#
|
267
257
|
# ```ruby
|
268
|
-
# require "google/cloud"
|
258
|
+
# require "google/cloud/storage"
|
269
259
|
#
|
270
|
-
#
|
271
|
-
# storage = gcloud.storage
|
260
|
+
# storage = Google::Cloud::Storage.new
|
272
261
|
#
|
273
262
|
# bucket = storage.bucket "my-todo-app"
|
274
263
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -289,10 +278,9 @@ module Google
|
|
289
278
|
# email address:
|
290
279
|
#
|
291
280
|
# ```ruby
|
292
|
-
# require "google/cloud"
|
281
|
+
# require "google/cloud/storage"
|
293
282
|
#
|
294
|
-
#
|
295
|
-
# storage = gcloud.storage
|
283
|
+
# storage = Google::Cloud::Storage.new
|
296
284
|
#
|
297
285
|
# bucket = storage.bucket "my-todo-app"
|
298
286
|
#
|
@@ -304,10 +292,9 @@ module Google
|
|
304
292
|
# the email address:
|
305
293
|
#
|
306
294
|
# ```ruby
|
307
|
-
# require "google/cloud"
|
295
|
+
# require "google/cloud/storage"
|
308
296
|
#
|
309
|
-
#
|
310
|
-
# storage = gcloud.storage
|
297
|
+
# storage = Google::Cloud::Storage.new
|
311
298
|
#
|
312
299
|
# bucket = storage.bucket "my-todo-app"
|
313
300
|
#
|
@@ -319,10 +306,9 @@ module Google
|
|
319
306
|
# permissions:
|
320
307
|
#
|
321
308
|
# ```ruby
|
322
|
-
# require "google/cloud"
|
309
|
+
# require "google/cloud/storage"
|
323
310
|
#
|
324
|
-
#
|
325
|
-
# storage = gcloud.storage
|
311
|
+
# storage = Google::Cloud::Storage.new
|
326
312
|
#
|
327
313
|
# bucket = storage.bucket "my-todo-app"
|
328
314
|
#
|
@@ -340,10 +326,9 @@ module Google
|
|
340
326
|
# email address:
|
341
327
|
#
|
342
328
|
# ```ruby
|
343
|
-
# require "google/cloud"
|
329
|
+
# require "google/cloud/storage"
|
344
330
|
#
|
345
|
-
#
|
346
|
-
# storage = gcloud.storage
|
331
|
+
# storage = Google::Cloud::Storage.new
|
347
332
|
#
|
348
333
|
# bucket = storage.bucket "my-todo-app"
|
349
334
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -356,10 +341,9 @@ module Google
|
|
356
341
|
# email address:
|
357
342
|
#
|
358
343
|
# ```ruby
|
359
|
-
# require "google/cloud"
|
344
|
+
# require "google/cloud/storage"
|
360
345
|
#
|
361
|
-
#
|
362
|
-
# storage = gcloud.storage
|
346
|
+
# storage = Google::Cloud::Storage.new
|
363
347
|
#
|
364
348
|
# bucket = storage.bucket "my-todo-app"
|
365
349
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -371,10 +355,9 @@ module Google
|
|
371
355
|
# Access to a file can also be granted to a predefined list of permissions:
|
372
356
|
#
|
373
357
|
# ```ruby
|
374
|
-
# require "google/cloud"
|
358
|
+
# require "google/cloud/storage"
|
375
359
|
#
|
376
|
-
#
|
377
|
-
# storage = gcloud.storage
|
360
|
+
# storage = Google::Cloud::Storage.new
|
378
361
|
#
|
379
362
|
# bucket = storage.bucket "my-todo-app"
|
380
363
|
# file = bucket.file "avatars/heidi/400x400.png"
|
@@ -396,10 +379,9 @@ module Google
|
|
396
379
|
# You can also set the request `timeout` value in seconds.
|
397
380
|
#
|
398
381
|
# ```ruby
|
399
|
-
# require "google/cloud"
|
382
|
+
# require "google/cloud/storage"
|
400
383
|
#
|
401
|
-
#
|
402
|
-
# storage = gcloud.storage retries: 10, timeout: 120
|
384
|
+
# storage = Google::Cloud::Storage.new retries: 10, timeout: 120
|
403
385
|
# ```
|
404
386
|
#
|
405
387
|
# See the [Storage status and error
|
@@ -407,6 +389,60 @@ module Google
|
|
407
389
|
# for a list of error conditions.
|
408
390
|
#
|
409
391
|
module Storage
|
392
|
+
##
|
393
|
+
# Creates a new object for connecting to the Storage service.
|
394
|
+
# Each call creates a new connection.
|
395
|
+
#
|
396
|
+
# For more information on connecting to Google Cloud see the
|
397
|
+
# [Authentication
|
398
|
+
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
399
|
+
#
|
400
|
+
# @param [String] project Project identifier for the Storage service you
|
401
|
+
# are connecting to.
|
402
|
+
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
|
403
|
+
# file path the file must be readable.
|
404
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
405
|
+
# the set of resources and operations that the connection can access.
|
406
|
+
# See [Using OAuth 2.0 to Access Google
|
407
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
408
|
+
#
|
409
|
+
# The default scope is:
|
410
|
+
#
|
411
|
+
# * `https://www.googleapis.com/auth/devstorage.full_control`
|
412
|
+
# @param [Integer] retries Number of times to retry requests on server
|
413
|
+
# error. The default value is `3`. Optional.
|
414
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
415
|
+
#
|
416
|
+
# @return [Google::Cloud::Storage::Project]
|
417
|
+
#
|
418
|
+
# @example
|
419
|
+
# require "google/cloud/storage"
|
420
|
+
#
|
421
|
+
# storage = Google::Cloud::Storage.new(
|
422
|
+
# project: "my-todo-project",
|
423
|
+
# keyfile: "/path/to/keyfile.json"
|
424
|
+
# )
|
425
|
+
#
|
426
|
+
# bucket = storage.bucket "my-bucket"
|
427
|
+
# file = bucket.file "path/to/my-file.ext"
|
428
|
+
#
|
429
|
+
def self.new project: nil, keyfile: nil, scope: nil, retries: nil,
|
430
|
+
timeout: nil
|
431
|
+
project ||= Google::Cloud::Storage::Project.default_project
|
432
|
+
project = project.to_s # Always cast to a string
|
433
|
+
fail ArgumentError, "project is missing" if project.empty?
|
434
|
+
|
435
|
+
if keyfile.nil?
|
436
|
+
credentials = Google::Cloud::Storage::Credentials.default scope: scope
|
437
|
+
else
|
438
|
+
credentials = Google::Cloud::Storage::Credentials.new(
|
439
|
+
keyfile, scope: scope)
|
440
|
+
end
|
441
|
+
|
442
|
+
Google::Cloud::Storage::Project.new(
|
443
|
+
Google::Cloud::Storage::Service.new(
|
444
|
+
project, credentials, retries: retries, timeout: timeout))
|
445
|
+
end
|
410
446
|
end
|
411
447
|
end
|
412
448
|
end
|
@@ -28,10 +28,9 @@ module Google
|
|
28
28
|
# Represents a Storage bucket. Belongs to a Project and has many Files.
|
29
29
|
#
|
30
30
|
# @example
|
31
|
-
# require "google/cloud"
|
31
|
+
# require "google/cloud/storage"
|
32
32
|
#
|
33
|
-
#
|
34
|
-
# storage = gcloud.storage
|
33
|
+
# storage = Google::Cloud::Storage.new
|
35
34
|
#
|
36
35
|
# bucket = storage.bucket "my-bucket"
|
37
36
|
# file = bucket.file "path/to/my-file.ext"
|
@@ -101,10 +100,9 @@ module Google
|
|
101
100
|
# @yieldparam [Bucket::Cors] cors the object accepting CORS rules
|
102
101
|
#
|
103
102
|
# @example Retrieving the bucket's CORS rules.
|
104
|
-
# require "google/cloud"
|
103
|
+
# require "google/cloud/storage"
|
105
104
|
#
|
106
|
-
#
|
107
|
-
# storage = gcloud.storage
|
105
|
+
# storage = Google::Cloud::Storage.new
|
108
106
|
#
|
109
107
|
# bucket = storage.bucket "my-todo-app"
|
110
108
|
# bucket.cors #=> [{"origin"=>["http://example.org"],
|
@@ -113,10 +111,9 @@ module Google
|
|
113
111
|
# # "maxAgeSeconds"=>3600}]
|
114
112
|
#
|
115
113
|
# @example Updating the bucket's CORS rules inside a block.
|
116
|
-
# require "google/cloud"
|
114
|
+
# require "google/cloud/storage"
|
117
115
|
#
|
118
|
-
#
|
119
|
-
# storage = gcloud.storage
|
116
|
+
# storage = Google::Cloud::Storage.new
|
120
117
|
# bucket = storage.bucket "my-todo-app"
|
121
118
|
#
|
122
119
|
# bucket.update do |b|
|
@@ -201,7 +198,8 @@ module Google
|
|
201
198
|
##
|
202
199
|
# The bucket's storage class. This defines how objects in the bucket are
|
203
200
|
# stored and determines the SLA and the cost of storage. Values include
|
204
|
-
# `
|
201
|
+
# `MULTI_REGIONAL`, `REGIONAL`, `NEARLINE`, `COLDLINE`, `STANDARD`,
|
202
|
+
# and `DURABLE_REDUCED_AVAILABILITY`.
|
205
203
|
def storage_class
|
206
204
|
@gapi.storage_class
|
207
205
|
end
|
@@ -287,10 +285,9 @@ module Google
|
|
287
285
|
# file
|
288
286
|
#
|
289
287
|
# @example
|
290
|
-
# require "google/cloud"
|
288
|
+
# require "google/cloud/storage"
|
291
289
|
#
|
292
|
-
#
|
293
|
-
# storage = gcloud.storage
|
290
|
+
# storage = Google::Cloud::Storage.new
|
294
291
|
#
|
295
292
|
# bucket = storage.bucket "my-bucket"
|
296
293
|
# bucket.update do |b|
|
@@ -301,10 +298,9 @@ module Google
|
|
301
298
|
# end
|
302
299
|
#
|
303
300
|
# @example New CORS rules can also be added in a nested block:
|
304
|
-
# require "google/cloud"
|
301
|
+
# require "google/cloud/storage"
|
305
302
|
#
|
306
|
-
#
|
307
|
-
# storage = gcloud.storage
|
303
|
+
# storage = Google::Cloud::Storage.new
|
308
304
|
# bucket = storage.bucket "my-todo-app"
|
309
305
|
#
|
310
306
|
# bucket.update do |b|
|
@@ -334,10 +330,9 @@ module Google
|
|
334
330
|
# @return [Boolean] Returns `true` if the bucket was deleted.
|
335
331
|
#
|
336
332
|
# @example
|
337
|
-
# require "google/cloud"
|
333
|
+
# require "google/cloud/storage"
|
338
334
|
#
|
339
|
-
#
|
340
|
-
# storage = gcloud.storage
|
335
|
+
# storage = Google::Cloud::Storage.new
|
341
336
|
#
|
342
337
|
# bucket = storage.bucket "my-bucket"
|
343
338
|
# bucket.delete
|
@@ -374,10 +369,9 @@ module Google
|
|
374
369
|
# {Google::Cloud::Storage::File::List})
|
375
370
|
#
|
376
371
|
# @example
|
377
|
-
# require "google/cloud"
|
372
|
+
# require "google/cloud/storage"
|
378
373
|
#
|
379
|
-
#
|
380
|
-
# storage = gcloud.storage
|
374
|
+
# storage = Google::Cloud::Storage.new
|
381
375
|
#
|
382
376
|
# bucket = storage.bucket "my-bucket"
|
383
377
|
# files = bucket.files
|
@@ -386,10 +380,9 @@ module Google
|
|
386
380
|
# end
|
387
381
|
#
|
388
382
|
# @example Retrieve all files: (See {File::List#all})
|
389
|
-
# require "google/cloud"
|
383
|
+
# require "google/cloud/storage"
|
390
384
|
#
|
391
|
-
#
|
392
|
-
# storage = gcloud.storage
|
385
|
+
# storage = Google::Cloud::Storage.new
|
393
386
|
#
|
394
387
|
# bucket = storage.bucket "my-bucket"
|
395
388
|
# files = bucket.files
|
@@ -438,10 +431,9 @@ module Google
|
|
438
431
|
# not exist
|
439
432
|
#
|
440
433
|
# @example
|
441
|
-
# require "google/cloud"
|
434
|
+
# require "google/cloud/storage"
|
442
435
|
#
|
443
|
-
#
|
444
|
-
# storage = gcloud.storage
|
436
|
+
# storage = Google::Cloud::Storage.new
|
445
437
|
#
|
446
438
|
# bucket = storage.bucket "my-bucket"
|
447
439
|
#
|
@@ -539,20 +531,18 @@ module Google
|
|
539
531
|
# @return [Google::Cloud::Storage::File]
|
540
532
|
#
|
541
533
|
# @example
|
542
|
-
# require "google/cloud"
|
534
|
+
# require "google/cloud/storage"
|
543
535
|
#
|
544
|
-
#
|
545
|
-
# storage = gcloud.storage
|
536
|
+
# storage = Google::Cloud::Storage.new
|
546
537
|
#
|
547
538
|
# bucket = storage.bucket "my-bucket"
|
548
539
|
#
|
549
540
|
# bucket.create_file "path/to/local.file.ext"
|
550
541
|
#
|
551
542
|
# @example Specifying a destination path:
|
552
|
-
# require "google/cloud"
|
543
|
+
# require "google/cloud/storage"
|
553
544
|
#
|
554
|
-
#
|
555
|
-
# storage = gcloud.storage
|
545
|
+
# storage = Google::Cloud::Storage.new
|
556
546
|
#
|
557
547
|
# bucket = storage.bucket "my-bucket"
|
558
548
|
#
|
@@ -560,11 +550,10 @@ module Google
|
|
560
550
|
# "destination/path/file.ext"
|
561
551
|
#
|
562
552
|
# @example Providing a customer-supplied encryption key:
|
563
|
-
# require "google/cloud"
|
553
|
+
# require "google/cloud/storage"
|
564
554
|
# require "digest/sha2"
|
565
555
|
#
|
566
|
-
#
|
567
|
-
# storage = gcloud.storage
|
556
|
+
# storage = Google::Cloud::Storage.new
|
568
557
|
# bucket = storage.bucket "my-bucket"
|
569
558
|
#
|
570
559
|
# # Key generation shown for example purposes only. Write your own.
|
@@ -604,6 +593,88 @@ module Google
|
|
604
593
|
alias_method :upload_file, :create_file
|
605
594
|
alias_method :new_file, :create_file
|
606
595
|
|
596
|
+
##
|
597
|
+
# Access without authentication can be granted to a File for a specified
|
598
|
+
# period of time. This URL uses a cryptographic signature of your
|
599
|
+
# credentials to access the file identified by `path`. A URL can be
|
600
|
+
# created for paths that do not yet exist. For instance, a URL can be
|
601
|
+
# created to `PUT` file contents to.
|
602
|
+
#
|
603
|
+
# Generating a URL requires service account credentials, either by
|
604
|
+
# connecting with a service account when calling
|
605
|
+
# {Google::Cloud.storage}, or by passing in the service account `issuer`
|
606
|
+
# and `signing_key` values. Although the private key can be passed as a
|
607
|
+
# string for convenience, creating and storing an instance of
|
608
|
+
# `OpenSSL::PKey::RSA` is more efficient when making multiple calls to
|
609
|
+
# `signed_url`.
|
610
|
+
#
|
611
|
+
# A {SignedUrlUnavailable} is raised if the service account credentials
|
612
|
+
# are missing. Service account credentials are acquired by following the
|
613
|
+
# steps in [Service Account Authentication](
|
614
|
+
# https://cloud.google.com/storage/docs/authentication#service_accounts).
|
615
|
+
#
|
616
|
+
# @see https://cloud.google.com/storage/docs/access-control#Signed-URLs
|
617
|
+
# Access Control Signed URLs guide
|
618
|
+
#
|
619
|
+
# @param [String] path Path to of the file in Google Cloud Storage.
|
620
|
+
# @param [String] method The HTTP verb to be used with the signed URL.
|
621
|
+
# Signed URLs can be used
|
622
|
+
# with `GET`, `HEAD`, `PUT`, and `DELETE` requests. Default is `GET`.
|
623
|
+
# @param [Integer] expires The number of seconds until the URL expires.
|
624
|
+
# Default is 300/5 minutes.
|
625
|
+
# @param [String] content_type When provided, the client (browser) must
|
626
|
+
# send this value in the HTTP header. e.g. `text/plain`
|
627
|
+
# @param [String] content_md5 The MD5 digest value in base64. If you
|
628
|
+
# provide this in the string, the client (usually a browser) must
|
629
|
+
# provide this HTTP header with this same value in its request.
|
630
|
+
# @param [String] issuer Service Account's Client Email.
|
631
|
+
# @param [String] client_email Service Account's Client Email.
|
632
|
+
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
633
|
+
# Private Key.
|
634
|
+
# @param [OpenSSL::PKey::RSA, String] private_key Service Account's
|
635
|
+
# Private Key.
|
636
|
+
#
|
637
|
+
# @example
|
638
|
+
# require "google/cloud/storage"
|
639
|
+
#
|
640
|
+
# storage = Google::Cloud::Storage.new
|
641
|
+
#
|
642
|
+
# bucket = storage.bucket "my-todo-app"
|
643
|
+
# shared_url = bucket.signed_url "avatars/heidi/400x400.png",
|
644
|
+
#
|
645
|
+
# @example Any of the option parameters may be specified:
|
646
|
+
# require "google/cloud/storage"
|
647
|
+
#
|
648
|
+
# storage = Google::Cloud::Storage.new
|
649
|
+
#
|
650
|
+
# bucket = storage.bucket "my-todo-app"
|
651
|
+
# shared_url = bucket.signed_url "avatars/heidi/400x400.png",
|
652
|
+
# method: "PUT",
|
653
|
+
# expires: 300 # 5 minutes from now
|
654
|
+
#
|
655
|
+
# @example Using the `issuer` and `signing_key` options:
|
656
|
+
# require "google/cloud/storage"
|
657
|
+
#
|
658
|
+
# storage = Google::Cloud.storage
|
659
|
+
#
|
660
|
+
# bucket = storage.bucket "my-todo-app"
|
661
|
+
# key = OpenSSL::PKey::RSA.new "-----BEGIN PRIVATE KEY-----\n..."
|
662
|
+
# shared_url = bucket.signed_url "avatars/heidi/400x400.png",
|
663
|
+
# issuer: "service-account@gcloud.com",
|
664
|
+
# signing_key: key
|
665
|
+
#
|
666
|
+
def signed_url path, method: nil, expires: nil, content_type: nil,
|
667
|
+
content_md5: nil, issuer: nil, client_email: nil,
|
668
|
+
signing_key: nil, private_key: nil
|
669
|
+
ensure_service!
|
670
|
+
options = { method: method, expires: expires,
|
671
|
+
content_type: content_type, content_md5: content_md5,
|
672
|
+
issuer: issuer, client_email: client_email,
|
673
|
+
signing_key: signing_key, private_key: private_key }
|
674
|
+
signer = File::Signer.from_bucket self, path
|
675
|
+
signer.signed_url options
|
676
|
+
end
|
677
|
+
|
607
678
|
##
|
608
679
|
# The Bucket::Acl instance used to control access to the bucket.
|
609
680
|
#
|
@@ -615,10 +686,9 @@ module Google
|
|
615
686
|
# Control guide
|
616
687
|
#
|
617
688
|
# @example Grant access to a user by prepending `"user-"` to an email:
|
618
|
-
# require "google/cloud"
|
689
|
+
# require "google/cloud/storage"
|
619
690
|
#
|
620
|
-
#
|
621
|
-
# storage = gcloud.storage
|
691
|
+
# storage = Google::Cloud::Storage.new
|
622
692
|
#
|
623
693
|
# bucket = storage.bucket "my-todo-app"
|
624
694
|
#
|
@@ -626,10 +696,9 @@ module Google
|
|
626
696
|
# bucket.acl.add_reader "user-#{email}"
|
627
697
|
#
|
628
698
|
# @example Grant access to a group by prepending `"group-"` to an email:
|
629
|
-
# require "google/cloud"
|
699
|
+
# require "google/cloud/storage"
|
630
700
|
#
|
631
|
-
#
|
632
|
-
# storage = gcloud.storage
|
701
|
+
# storage = Google::Cloud::Storage.new
|
633
702
|
#
|
634
703
|
# bucket = storage.bucket "my-todo-app"
|
635
704
|
#
|
@@ -637,10 +706,9 @@ module Google
|
|
637
706
|
# bucket.acl.add_reader "group-#{email}"
|
638
707
|
#
|
639
708
|
# @example Or, grant access via a predefined permissions list:
|
640
|
-
# require "google/cloud"
|
709
|
+
# require "google/cloud/storage"
|
641
710
|
#
|
642
|
-
#
|
643
|
-
# storage = gcloud.storage
|
711
|
+
# storage = Google::Cloud::Storage.new
|
644
712
|
#
|
645
713
|
# bucket = storage.bucket "my-todo-app"
|
646
714
|
#
|
@@ -662,10 +730,9 @@ module Google
|
|
662
730
|
# Control guide
|
663
731
|
#
|
664
732
|
# @example Grant access to a user by prepending `"user-"` to an email:
|
665
|
-
# require "google/cloud"
|
733
|
+
# require "google/cloud/storage"
|
666
734
|
#
|
667
|
-
#
|
668
|
-
# storage = gcloud.storage
|
735
|
+
# storage = Google::Cloud::Storage.new
|
669
736
|
#
|
670
737
|
# bucket = storage.bucket "my-todo-app"
|
671
738
|
#
|
@@ -673,10 +740,9 @@ module Google
|
|
673
740
|
# bucket.default_acl.add_reader "user-#{email}"
|
674
741
|
#
|
675
742
|
# @example Grant access to a group by prepending `"group-"` to an email
|
676
|
-
# require "google/cloud"
|
743
|
+
# require "google/cloud/storage"
|
677
744
|
#
|
678
|
-
#
|
679
|
-
# storage = gcloud.storage
|
745
|
+
# storage = Google::Cloud::Storage.new
|
680
746
|
#
|
681
747
|
# bucket = storage.bucket "my-todo-app"
|
682
748
|
#
|
@@ -684,10 +750,9 @@ module Google
|
|
684
750
|
# bucket.default_acl.add_reader "group-#{email}"
|
685
751
|
#
|
686
752
|
# @example Or, grant access via a predefined permissions list:
|
687
|
-
# require "google/cloud"
|
753
|
+
# require "google/cloud/storage"
|
688
754
|
#
|
689
|
-
#
|
690
|
-
# storage = gcloud.storage
|
755
|
+
# storage = Google::Cloud::Storage.new
|
691
756
|
#
|
692
757
|
# bucket = storage.bucket "my-todo-app"
|
693
758
|
#
|