gcloud 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +13 -5
  2. data/AUTHENTICATION.md +71 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +10 -15
  5. data/lib/gcloud.rb +30 -0
  6. data/lib/gcloud/backoff.rb +3 -0
  7. data/lib/gcloud/credentials.rb +47 -30
  8. data/lib/gcloud/datastore.rb +246 -15
  9. data/lib/gcloud/datastore/connection.rb +4 -2
  10. data/lib/gcloud/datastore/credentials.rb +3 -1
  11. data/lib/gcloud/datastore/dataset.rb +130 -25
  12. data/lib/gcloud/datastore/dataset/lookup_results.rb +1 -0
  13. data/lib/gcloud/datastore/dataset/query_results.rb +7 -5
  14. data/lib/gcloud/datastore/entity.rb +99 -17
  15. data/lib/gcloud/datastore/errors.rb +13 -2
  16. data/lib/gcloud/datastore/key.rb +133 -2
  17. data/lib/gcloud/datastore/properties.rb +6 -1
  18. data/lib/gcloud/datastore/proto.rb +2 -1
  19. data/lib/gcloud/datastore/query.rb +4 -4
  20. data/lib/gcloud/datastore/transaction.rb +3 -0
  21. data/lib/gcloud/storage.rb +280 -13
  22. data/lib/gcloud/storage/bucket.rb +248 -11
  23. data/lib/gcloud/storage/bucket/acl.rb +631 -4
  24. data/lib/gcloud/storage/bucket/list.rb +1 -0
  25. data/lib/gcloud/storage/connection.rb +1 -0
  26. data/lib/gcloud/storage/credentials.rb +3 -1
  27. data/lib/gcloud/storage/errors.rb +9 -1
  28. data/lib/gcloud/storage/file.rb +231 -6
  29. data/lib/gcloud/storage/file/acl.rb +365 -2
  30. data/lib/gcloud/storage/file/list.rb +1 -0
  31. data/lib/gcloud/storage/file/verifier.rb +1 -0
  32. data/lib/gcloud/storage/project.rb +119 -10
  33. data/lib/gcloud/version.rb +18 -3
  34. metadata +33 -80
  35. data/.gemtest +0 -0
  36. data/.rubocop.yml +0 -17
  37. data/Manifest.txt +0 -66
  38. data/Rakefile +0 -35
  39. data/gcloud.gemspec +0 -63
  40. data/rakelib/console.rake +0 -28
  41. data/rakelib/manifest.rake +0 -24
  42. data/rakelib/proto.rake +0 -17
  43. data/rakelib/rubocop.rake +0 -17
  44. data/rakelib/test.rake +0 -144
  45. data/test/gcloud/datastore/proto/test_cursor.rb +0 -36
  46. data/test/gcloud/datastore/proto/test_direction.rb +0 -60
  47. data/test/gcloud/datastore/proto/test_operator.rb +0 -76
  48. data/test/gcloud/datastore/proto/test_value.rb +0 -231
  49. data/test/gcloud/datastore/test_connection.rb +0 -93
  50. data/test/gcloud/datastore/test_credentials.rb +0 -38
  51. data/test/gcloud/datastore/test_dataset.rb +0 -413
  52. data/test/gcloud/datastore/test_entity.rb +0 -161
  53. data/test/gcloud/datastore/test_entity_exclude.rb +0 -225
  54. data/test/gcloud/datastore/test_key.rb +0 -189
  55. data/test/gcloud/datastore/test_query.rb +0 -271
  56. data/test/gcloud/datastore/test_transaction.rb +0 -121
  57. data/test/gcloud/storage/test_backoff.rb +0 -127
  58. data/test/gcloud/storage/test_bucket.rb +0 -270
  59. data/test/gcloud/storage/test_bucket_acl.rb +0 -253
  60. data/test/gcloud/storage/test_default_acl.rb +0 -256
  61. data/test/gcloud/storage/test_file.rb +0 -221
  62. data/test/gcloud/storage/test_file_acl.rb +0 -367
  63. data/test/gcloud/storage/test_project.rb +0 -180
  64. data/test/gcloud/storage/test_storage.rb +0 -29
  65. data/test/gcloud/storage/test_verifier.rb +0 -62
  66. data/test/gcloud/test_version.rb +0 -8
  67. data/test/helper.rb +0 -91
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2015 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2014 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2014 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +21,8 @@ module Gcloud
20
21
  # Represents the Oauth2 signing logic for Storage.
21
22
  class Credentials < Gcloud::Credentials #:nodoc:
22
23
  SCOPE = ["https://www.googleapis.com/auth/devstorage.full_control"]
23
- ENV_VARS = ["STORAGE_KEYFILE"]
24
+ PATH_ENV_VARS = %w(STORAGE_KEYFILE GOOGLE_CLOUD_KEYFILE)
25
+ JSON_ENV_VARS = %w(STORAGE_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON)
24
26
  end
25
27
  end
26
28
  end
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2014 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,11 +16,15 @@
15
16
  module Gcloud
16
17
  module Storage
17
18
  ##
19
+ # = Storage Error
20
+ #
18
21
  # Base Storage exception class.
19
22
  class Error < Gcloud::Error
20
23
  end
21
24
 
22
25
  ##
26
+ # = ApiError
27
+ #
23
28
  # Raised when an API call is not successful.
24
29
  class ApiError < Error
25
30
  ##
@@ -32,7 +37,8 @@ module Gcloud
32
37
 
33
38
  def initialize message, code, errors
34
39
  super message
35
- @code, @errors = code, errors
40
+ @code = code
41
+ @errors = errors
36
42
  end
37
43
 
38
44
  def self.from_response resp #:nodoc:
@@ -43,6 +49,8 @@ module Gcloud
43
49
  end
44
50
 
45
51
  ##
52
+ # = FileVerificationError
53
+ #
46
54
  # Raised when a File download fails the verification.
47
55
  class FileVerificationError < Error
48
56
  ##
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2014 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +20,19 @@ require "gcloud/storage/file/verifier"
19
20
  module Gcloud
20
21
  module Storage
21
22
  ##
23
+ # = File
24
+ #
22
25
  # Represents the File/Object that belong to a Bucket.
26
+ #
27
+ # require "glcoud/storage"
28
+ #
29
+ # storage = Gcloud.storage
30
+ #
31
+ # bucket = storage.find_bucket "my-bucket"
32
+ #
33
+ # file = bucket.find_file "path/to/my-file.ext"
34
+ # file.download "/downloads/#{bucket.name}/#{file.name}"
35
+ #
23
36
  class File
24
37
  ##
25
38
  # The Connection object.
@@ -31,7 +44,7 @@ module Gcloud
31
44
 
32
45
  ##
33
46
  # Create an empty File object.
34
- def initialize
47
+ def initialize #:nodoc:
35
48
  @connection = nil
36
49
  @gapi = {}
37
50
  end
@@ -118,29 +131,78 @@ module Gcloud
118
131
 
119
132
  ##
120
133
  # Download the file's contents to a local file.
121
- # The path provided must be writable.
122
134
  #
135
+ # === Parameters
136
+ #
137
+ # +path+::
138
+ # The path on the local file system to write the data to.
139
+ # The path provided must be writable. (+String+)
140
+ # +options+::
141
+ # An optional Hash for controlling additional behavor. (+Hash+)
142
+ # +options [:verify]+::
143
+ # The verification algoruthm used to ensure the downloaded file contents
144
+ # are correct. Default is +:md5+. (+Symbol+)
145
+ #
146
+ # Acceptable values are:
147
+ # * +md5+:: Verify file content match using the MD5 hash.
148
+ # * +crc32c+:: Verify file content match using the CRC32c hash.
149
+ # * +all+:: Perform all available file content verification.
150
+ # * +none+:: Don't perform file content verification.
151
+ #
152
+ # === Returns
153
+ #
154
+ # +::File+ object on the local file system
155
+ #
156
+ # === Examples
157
+ #
158
+ # require "glcoud/storage"
159
+ #
160
+ # storage = Gcloud.storage
161
+ #
162
+ # bucket = storage.find_bucket "my-bucket"
163
+ #
164
+ # file = bucket.find_file "path/to/my-file.ext"
123
165
  # file.download "path/to/downloaded/file.ext"
124
166
  #
125
167
  # The download is verified by calculating the MD5 digest.
126
168
  # The CRC32c digest can be used by passing :crc32c.
127
169
  #
170
+ # require "glcoud/storage"
171
+ #
172
+ # storage = Gcloud.storage
173
+ #
174
+ # bucket = storage.find_bucket "my-bucket"
175
+ #
176
+ # file = bucket.find_file "path/to/my-file.ext"
128
177
  # file.download "path/to/downloaded/file.ext", verify: :crc32c
129
178
  #
130
179
  # Both the MD5 and CRC32c digest can be used by passing :all.
131
180
  #
181
+ # require "glcoud/storage"
182
+ #
183
+ # storage = Gcloud.storage
184
+ #
185
+ # bucket = storage.find_bucket "my-bucket"
186
+ #
187
+ # file = bucket.find_file "path/to/my-file.ext"
132
188
  # file.download "path/to/downloaded/file.ext", verify: :all
133
189
  #
134
190
  # The download verification can be disabled by passing :none
135
191
  #
192
+ # require "glcoud/storage"
193
+ #
194
+ # storage = Gcloud.storage
195
+ #
196
+ # bucket = storage.find_bucket "my-bucket"
197
+ #
198
+ # file = bucket.find_file "path/to/my-file.ext"
136
199
  # file.download "path/to/downloaded/file.ext", verify: :none
137
200
  #
138
- # If the verification fails FileVerificationError is raised.
139
201
  def download path, options = {}
140
202
  ensure_connection!
141
203
  resp = connection.download_file bucket, name
142
204
  if resp.success?
143
- ::File.open path, "w+" do |f|
205
+ ::File.open path, "wb+" do |f|
144
206
  f.write resp.body
145
207
  end
146
208
  verify_file! ::File.new(path), options
@@ -152,12 +214,63 @@ module Gcloud
152
214
  ##
153
215
  # Copy the file to a new location.
154
216
  #
217
+ # === Parameters
218
+ #
219
+ # +dest_bucket_or_path+::
220
+ # Either the bucket to copy the file to, or the path to copy the file to
221
+ # in the current bucket. (+String+)
222
+ # +dest_path+::
223
+ # If a bucket was provided in the first parameter, this contains the
224
+ # path to copy the file to in the given bucket. (+String+)
225
+ # +options+::
226
+ # An optional Hash for controlling additional behavor. (+Hash+)
227
+ # +options [:acl]+::
228
+ # A predefined set of access controls to apply to new file.
229
+ # (+String+)
230
+ #
231
+ # Acceptable values are:
232
+ # * +auth+, +auth_read+, +authenticated+, +authenticated_read+,
233
+ # +authenticatedRead+:: File owner gets OWNER access, and
234
+ # allAuthenticatedUsers get READER access.
235
+ # * +owner_full+, +bucketOwnerFullControl+:: File owner gets OWNER
236
+ # access, and project team owners get OWNER access.
237
+ # * +owner_read+, +bucketOwnerRead+:: File owner gets OWNER access, and
238
+ # project team owners get READER access.
239
+ # * +private+:: File owner gets OWNER access.
240
+ # * +project_private+, +projectPrivate+:: File owner gets OWNER access,
241
+ # and project team members get access according to their roles.
242
+ # * +public+, +public_read+, +publicRead+:: File owner gets OWNER
243
+ # access, and allUsers get READER access.
244
+ #
245
+ # === Returns
246
+ #
247
+ # +File+ object
248
+ #
249
+ # === Examples
250
+ #
251
+ # The file can also be copied to a new path in the current bucket:
252
+ #
253
+ # require "glcoud/storage"
254
+ #
255
+ # storage = Gcloud.storage
256
+ #
257
+ # bucket = storage.find_bucket "my-bucket"
258
+ #
259
+ # file = bucket.find_file "path/to/my-file.ext"
155
260
  # file.copy "path/to/destination/file.ext"
156
261
  #
157
262
  # The file can also be copied to a different bucket:
158
263
  #
264
+ # require "glcoud/storage"
265
+ #
266
+ # storage = Gcloud.storage
267
+ #
268
+ # bucket = storage.find_bucket "my-bucket"
269
+ #
270
+ # file = bucket.find_file "path/to/my-file.ext"
159
271
  # file.copy "new-destination-bucket",
160
272
  # "path/to/destination/file.ext"
273
+ #
161
274
  def copy dest_bucket_or_path, dest_path = nil, options = {}
162
275
  ensure_connection!
163
276
  dest_bucket, dest_path, options = fix_copy_args dest_bucket_or_path,
@@ -174,6 +287,22 @@ module Gcloud
174
287
 
175
288
  ##
176
289
  # Permenently deletes the file.
290
+ #
291
+ # === Returns
292
+ #
293
+ # +true+ if the file was deleted.
294
+ #
295
+ # === Example
296
+ #
297
+ # require "glcoud/storage"
298
+ #
299
+ # storage = Gcloud.storage
300
+ #
301
+ # bucket = storage.find_bucket "my-bucket"
302
+ #
303
+ # file = bucket.find_file "path/to/my-file.ext"
304
+ # file.delete
305
+ #
177
306
  def delete
178
307
  ensure_connection!
179
308
  resp = connection.delete_file bucket, name
@@ -184,6 +313,54 @@ module Gcloud
184
313
  end
185
314
  end
186
315
 
316
+ ##
317
+ # Access without authentication can be granted to a File for a specified
318
+ # period of time. This URL uses a cryptographic signature
319
+ # of your credentials to access the file. See the
320
+ # {Access Control Signed URLs guide
321
+ # }[https://cloud.google.com/storage/docs/access-control#Signed-URLs]
322
+ # for more.
323
+ #
324
+ # === Parameters
325
+ #
326
+ # +options+::
327
+ # An optional Hash for controlling additional behavor. (+Hash+)
328
+ # +options [:method]+::
329
+ # The HTTP verb to be used with the signed URL. Signed URLs can be used
330
+ # with +GET+, +HEAD+, +PUT+, and +DELETE+ requests. Default is +GET+.
331
+ # (+String+)
332
+ # +options [:expires]+::
333
+ # The number of seconds until the URL expires. Default is 300/5 minutes.
334
+ # (+Integer+)
335
+ # +options [:content_type]+::
336
+ # When provided, the client (browser) must send this value in the
337
+ # HTTP header. e.g. +text/plain+ (+String+)
338
+ # +options [:content_md5]+::
339
+ # The MD5 digest value in base64. If you provide this in the string, the
340
+ # client (usually a browser) must provide this HTTP header with this
341
+ # same value in its request. (+String+)
342
+ #
343
+ # === Examples
344
+ #
345
+ # require "gcloud/storage"
346
+ #
347
+ # storage = Gcloud.storage
348
+ #
349
+ # bucket = storage.find_bucket "my-todo-app"
350
+ # file = bucket.find_file "avatars/heidi/400x400.png"
351
+ # shared_url = file.signed_url
352
+ #
353
+ # Any of the option parameters may be specified:
354
+ #
355
+ # require "gcloud/storage"
356
+ #
357
+ # storage = Gcloud.storage
358
+ #
359
+ # bucket = storage.find_bucket "my-todo-app"
360
+ # file = bucket.find_file "avatars/heidi/400x400.png"
361
+ # shared_url = file.signed_url method: "GET",
362
+ # expires: 300 # 5 minutes from now
363
+ #
187
364
  def signed_url options = {}
188
365
  ensure_connection!
189
366
  signer = File::Signer.new self
@@ -191,7 +368,55 @@ module Gcloud
191
368
  end
192
369
 
193
370
  ##
194
- # Access Control List
371
+ # The File::Acl instance used to control access to the file.
372
+ #
373
+ # A file has owners, writers, and readers. Permissions can be granted to
374
+ # an individual user's email address, a group's email address, as well as
375
+ # many predefined lists. See the
376
+ # {Access Control guide
377
+ # }[https://cloud.google.com/storage/docs/access-control]
378
+ # for more.
379
+ #
380
+ # === Examples
381
+ #
382
+ # Access to a file can be granted to a user by appending +"user-"+ to the
383
+ # email address:
384
+ #
385
+ # require "gcloud/storage"
386
+ #
387
+ # storage = Gcloud.storage
388
+ #
389
+ # bucket = storage.find_bucket "my-todo-app"
390
+ # file = bucket.find_file "avatars/heidi/400x400.png"
391
+ #
392
+ # email = "heidi@example.net"
393
+ # file.acl.add_reader "user-#{email}"
394
+ #
395
+ # Access to a file can be granted to a group by appending +"group-"+ to
396
+ # the email address:
397
+ #
398
+ # require "gcloud/storage"
399
+ #
400
+ # storage = Gcloud.storage
401
+ #
402
+ # bucket = storage.find_bucket "my-todo-app"
403
+ # file = bucket.find_file "avatars/heidi/400x400.png"
404
+ #
405
+ # email = "authors@example.net"
406
+ # file.acl.add_reader "group-#{email}"
407
+ #
408
+ # Access to a file can also be granted to a predefined list of
409
+ # permissions:
410
+ #
411
+ # require "gcloud/storage"
412
+ #
413
+ # storage = Gcloud.storage
414
+ #
415
+ # bucket = storage.find_bucket "my-todo-app"
416
+ # file = bucket.find_file "avatars/heidi/400x400.png"
417
+ #
418
+ # file.acl.public!
419
+ #
195
420
  def acl
196
421
  @acl ||= File::Acl.new self
197
422
  end
@@ -234,7 +459,7 @@ module Gcloud
234
459
 
235
460
  ##
236
461
  # Create a signed_url for a file.
237
- class Signer #:nodoc
462
+ class Signer #:nodoc:
238
463
  def initialize file
239
464
  @file = file
240
465
  end
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright 2015 Google Inc. All rights reserved.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +17,19 @@ module Gcloud
16
17
  module Storage
17
18
  class File
18
19
  ##
20
+ # = File Access Control List
21
+ #
19
22
  # Represents a File's Access Control List.
23
+ #
24
+ # require "glcoud/storage"
25
+ #
26
+ # storage = Gcloud.storage
27
+ #
28
+ # bucket = storage.find_bucket "my-bucket"
29
+ #
30
+ # file = bucket.find_file "path/to/my-file.ext"
31
+ # file.acl.readers.each { |reader| puts reader }
32
+ #
20
33
  class Acl
21
34
  RULES = { "authenticatedRead" => "authenticatedRead",
22
35
  "auth" => "authenticatedRead",
@@ -32,7 +45,7 @@ module Gcloud
32
45
  "project_private" => "projectPrivate",
33
46
  "publicRead" => "publicRead",
34
47
  "public" => "publicRead",
35
- "public_read" => "publicRead" }
48
+ "public_read" => "publicRead" } #:nodoc:
36
49
 
37
50
  ##
38
51
  # Initialized a new Acl object.
@@ -46,6 +59,20 @@ module Gcloud
46
59
  @readers = nil
47
60
  end
48
61
 
62
+ ##
63
+ # Reloads all Access Control List data for the file.
64
+ #
65
+ # === Example
66
+ #
67
+ # require "glcoud/storage"
68
+ #
69
+ # storage = Gcloud.storage
70
+ #
71
+ # bucket = storage.find_bucket "my-bucket"
72
+ #
73
+ # file = bucket.find_file "path/to/my-file.ext"
74
+ # file.acl.refresh!
75
+ #
49
76
  def refresh!
50
77
  resp = @connection.list_file_acls @bucket, @file
51
78
  acls = resp.data["items"]
@@ -54,21 +81,127 @@ module Gcloud
54
81
  @readers = entities_from_acls acls, "READER"
55
82
  end
56
83
 
84
+ ##
85
+ # Lists the owners of the file.
86
+ #
87
+ # === Returns
88
+ #
89
+ # Array of Strings
90
+ #
91
+ # === Example
92
+ #
93
+ # require "glcoud/storage"
94
+ #
95
+ # storage = Gcloud.storage
96
+ #
97
+ # bucket = storage.find_bucket "my-bucket"
98
+ #
99
+ # file = bucket.find_file "path/to/my-file.ext"
100
+ # file.acl.owners.each { |owner| puts owner }
101
+ #
57
102
  def owners
58
103
  refresh! if @owners.nil?
59
104
  @owners
60
105
  end
61
106
 
107
+ ##
108
+ # Lists the owners of the file.
109
+ #
110
+ # === Returns
111
+ #
112
+ # Array of Strings
113
+ #
114
+ # === Example
115
+ #
116
+ # require "glcoud/storage"
117
+ #
118
+ # storage = Gcloud.storage
119
+ #
120
+ # bucket = storage.find_bucket "my-bucket"
121
+ #
122
+ # file = bucket.find_file "path/to/my-file.ext"
123
+ # file.acl.writers.each { |writer| puts writer }
124
+ #
62
125
  def writers
63
126
  refresh! if @writers.nil?
64
127
  @writers
65
128
  end
66
129
 
130
+ ##
131
+ # Lists the readers of the file.
132
+ #
133
+ # === Returns
134
+ #
135
+ # Array of Strings
136
+ #
137
+ # === Example
138
+ #
139
+ # require "glcoud/storage"
140
+ #
141
+ # storage = Gcloud.storage
142
+ #
143
+ # bucket = storage.find_bucket "my-bucket"
144
+ #
145
+ # file = bucket.find_file "path/to/my-file.ext"
146
+ # file.acl.readers.each { |reader| puts reader }
147
+ #
67
148
  def readers
68
149
  refresh! if @readers.nil?
69
150
  @readers
70
151
  end
71
152
 
153
+ ##
154
+ # Grants owner permission to the file.
155
+ #
156
+ # === Parameters
157
+ #
158
+ # +entity+::
159
+ # The entity holding the permission, in one of the following forms:
160
+ # (+String+)
161
+ #
162
+ # * user-userId
163
+ # * user-email
164
+ # * group-groupId
165
+ # * group-email
166
+ # * domain-domain
167
+ # * project-team-projectId
168
+ # * allUsers
169
+ # * allAuthenticatedUsers
170
+ #
171
+ # +options+::
172
+ # An optional Hash for controlling additional behavor. (+Hash+)
173
+ # +options [:generation]+::
174
+ # When present, selects a specific revision of this object.
175
+ # Default is the latest version. (+Integer+)
176
+ #
177
+ # === Examples
178
+ #
179
+ # Access to a file can be granted to a user by appending +"user-"+ to
180
+ # the email address:
181
+ #
182
+ # require "glcoud/storage"
183
+ #
184
+ # storage = Gcloud.storage
185
+ #
186
+ # bucket = storage.find_bucket "my-bucket"
187
+ #
188
+ # file = bucket.find_file "path/to/my-file.ext"
189
+ # email = "heidi@example.net"
190
+ # file.acl.add_owner "user-#{email}"
191
+ #
192
+ # Access to a file can be granted to a group by appending +"group-"+ to
193
+ # the email address:
194
+ #
195
+ # require "glcoud/storage"
196
+ #
197
+ # storage = Gcloud.storage
198
+ #
199
+ # bucket = storage.find_bucket "my-bucket"
200
+ #
201
+ # file = bucket.find_file "path/to/my-file.ext"
202
+ # email = "authors@example.net"
203
+ # file.acl.add_owner "group-#{email}"
204
+ #
72
205
  def add_owner entity, options = {}
73
206
  resp = @connection.insert_file_acl @bucket, @file, entity,
74
207
  "OWNER", options
@@ -80,6 +213,58 @@ module Gcloud
80
213
  nil
81
214
  end
82
215
 
216
+ ##
217
+ # Grants writer permission to the file.
218
+ #
219
+ # === Parameters
220
+ #
221
+ # +entity+::
222
+ # The entity holding the permission, in one of the following forms:
223
+ # (+String+)
224
+ #
225
+ # * user-userId
226
+ # * user-email
227
+ # * group-groupId
228
+ # * group-email
229
+ # * domain-domain
230
+ # * project-team-projectId
231
+ # * allUsers
232
+ # * allAuthenticatedUsers
233
+ #
234
+ # +options+::
235
+ # An optional Hash for controlling additional behavor. (+Hash+)
236
+ # +options [:generation]+::
237
+ # When present, selects a specific revision of this object.
238
+ # Default is the latest version. (+Integer+)
239
+ #
240
+ # === Examples
241
+ #
242
+ # Access to a file can be granted to a user by appending +"user-"+ to
243
+ # the email address:
244
+ #
245
+ # require "glcoud/storage"
246
+ #
247
+ # storage = Gcloud.storage
248
+ #
249
+ # bucket = storage.find_bucket "my-bucket"
250
+ #
251
+ # file = bucket.find_file "path/to/my-file.ext"
252
+ # email = "heidi@example.net"
253
+ # file.acl.add_writer "user-#{email}"
254
+ #
255
+ # Access to a file can be granted to a group by appending +"group-"+ to
256
+ # the email address:
257
+ #
258
+ # require "glcoud/storage"
259
+ #
260
+ # storage = Gcloud.storage
261
+ #
262
+ # bucket = storage.find_bucket "my-bucket"
263
+ #
264
+ # file = bucket.find_file "path/to/my-file.ext"
265
+ # email = "authors@example.net"
266
+ # file.acl.add_writer "group-#{email}"
267
+ #
83
268
  def add_writer entity, options = {}
84
269
  resp = @connection.insert_file_acl @bucket, @file, entity,
85
270
  "WRITER", options
@@ -91,6 +276,58 @@ module Gcloud
91
276
  nil
92
277
  end
93
278
 
279
+ ##
280
+ # Grants reader permission to the file.
281
+ #
282
+ # === Parameters
283
+ #
284
+ # +entity+::
285
+ # The entity holding the permission, in one of the following forms:
286
+ # (+String+)
287
+ #
288
+ # * user-userId
289
+ # * user-email
290
+ # * group-groupId
291
+ # * group-email
292
+ # * domain-domain
293
+ # * project-team-projectId
294
+ # * allUsers
295
+ # * allAuthenticatedUsers
296
+ #
297
+ # +options+::
298
+ # An optional Hash for controlling additional behavor. (+Hash+)
299
+ # +options [:generation]+::
300
+ # When present, selects a specific revision of this object.
301
+ # Default is the latest version. (+Integer+)
302
+ #
303
+ # === Examples
304
+ #
305
+ # Access to a file can be granted to a user by appending +"user-"+ to
306
+ # the email address:
307
+ #
308
+ # require "glcoud/storage"
309
+ #
310
+ # storage = Gcloud.storage
311
+ #
312
+ # bucket = storage.find_bucket "my-bucket"
313
+ #
314
+ # file = bucket.find_file "path/to/my-file.ext"
315
+ # email = "heidi@example.net"
316
+ # file.acl.add_reader "user-#{email}"
317
+ #
318
+ # Access to a file can be granted to a group by appending +"group-"+ to
319
+ # the email address:
320
+ #
321
+ # require "glcoud/storage"
322
+ #
323
+ # storage = Gcloud.storage
324
+ #
325
+ # bucket = storage.find_bucket "my-bucket"
326
+ #
327
+ # file = bucket.find_file "path/to/my-file.ext"
328
+ # email = "authors@example.net"
329
+ # file.acl.add_reader "group-#{email}"
330
+ #
94
331
  def add_reader entity, options = {}
95
332
  resp = @connection.insert_file_acl @bucket, @file, entity,
96
333
  "READER", options
@@ -102,6 +339,42 @@ module Gcloud
102
339
  nil
103
340
  end
104
341
 
342
+ ##
343
+ # Permenently deletes the entity from the file's access control list.
344
+ #
345
+ # === Parameters
346
+ #
347
+ # +entity+::
348
+ # The entity holding the permission, in one of the following forms:
349
+ # (+String+)
350
+ #
351
+ # * user-userId
352
+ # * user-email
353
+ # * group-groupId
354
+ # * group-email
355
+ # * domain-domain
356
+ # * project-team-projectId
357
+ # * allUsers
358
+ # * allAuthenticatedUsers
359
+ #
360
+ # +options+::
361
+ # An optional Hash for controlling additional behavor. (+Hash+)
362
+ # +options [:generation]+::
363
+ # When present, selects a specific revision of this object.
364
+ # Default is the latest version. (+Integer+)
365
+ #
366
+ # === Example
367
+ #
368
+ # require "glcoud/storage"
369
+ #
370
+ # storage = Gcloud.storage
371
+ #
372
+ # bucket = storage.find_bucket "my-bucket"
373
+ #
374
+ # file = bucket.find_file "path/to/my-file.ext"
375
+ # email = "heidi@example.net"
376
+ # file.acl.delete "user-#{email}"
377
+ #
105
378
  def delete entity, options = {}
106
379
  resp = @connection.delete_file_acl @bucket, @file, entity, options
107
380
  if resp.success?
@@ -113,12 +386,27 @@ module Gcloud
113
386
  false
114
387
  end
115
388
 
116
- def self.predefined_rule_for rule_name
389
+ def self.predefined_rule_for rule_name #:nodoc:
117
390
  RULES[rule_name.to_s]
118
391
  end
119
392
 
120
393
  # Predefined ACL helpers
121
394
 
395
+ ##
396
+ # Convenience method to apply the +authenticatedRead+ predefined ACL
397
+ # rule to the file.
398
+ #
399
+ # === Example
400
+ #
401
+ # require "glcoud/storage"
402
+ #
403
+ # storage = Gcloud.storage
404
+ #
405
+ # bucket = storage.find_bucket "my-bucket"
406
+ #
407
+ # file = bucket.find_file "path/to/my-file.ext"
408
+ # file.acl.auth!
409
+ #
122
410
  def auth!
123
411
  update_predefined_acl! "authenticatedRead"
124
412
  end
@@ -127,25 +415,100 @@ module Gcloud
127
415
  alias_method :authenticated!, :auth!
128
416
  alias_method :authenticated_read!, :auth!
129
417
 
418
+ ##
419
+ # Convenience method to apply the +bucketOwnerFullControl+ predefined
420
+ # ACL rule to the file.
421
+ #
422
+ # === Example
423
+ #
424
+ # require "glcoud/storage"
425
+ #
426
+ # storage = Gcloud.storage
427
+ #
428
+ # bucket = storage.find_bucket "my-bucket"
429
+ #
430
+ # file = bucket.find_file "path/to/my-file.ext"
431
+ # file.acl.owner_full!
432
+ #
130
433
  def owner_full!
131
434
  update_predefined_acl! "bucketOwnerFullControl"
132
435
  end
133
436
  alias_method :bucketOwnerFullControl!, :owner_full!
134
437
 
438
+ ##
439
+ # Convenience method to apply the +bucketOwnerRead+ predefined ACL
440
+ # rule to the file.
441
+ #
442
+ # === Example
443
+ #
444
+ # require "glcoud/storage"
445
+ #
446
+ # storage = Gcloud.storage
447
+ #
448
+ # bucket = storage.find_bucket "my-bucket"
449
+ #
450
+ # file = bucket.find_file "path/to/my-file.ext"
451
+ # file.acl.owner_read!
452
+ #
135
453
  def owner_read!
136
454
  update_predefined_acl! "bucketOwnerRead"
137
455
  end
138
456
  alias_method :bucketOwnerRead!, :owner_read!
139
457
 
458
+ ##
459
+ # Convenience method to apply the +private+ predefined ACL
460
+ # rule to the file.
461
+ #
462
+ # === Example
463
+ #
464
+ # require "glcoud/storage"
465
+ #
466
+ # storage = Gcloud.storage
467
+ #
468
+ # bucket = storage.find_bucket "my-bucket"
469
+ #
470
+ # file = bucket.find_file "path/to/my-file.ext"
471
+ # file.acl.private!
472
+ #
140
473
  def private!
141
474
  update_predefined_acl! "private"
142
475
  end
143
476
 
477
+ ##
478
+ # Convenience method to apply the +projectPrivate+ predefined ACL
479
+ # rule to the file.
480
+ #
481
+ # === Example
482
+ #
483
+ # require "glcoud/storage"
484
+ #
485
+ # storage = Gcloud.storage
486
+ #
487
+ # bucket = storage.find_bucket "my-bucket"
488
+ #
489
+ # file = bucket.find_file "path/to/my-file.ext"
490
+ # file.acl.project_private!
491
+ #
144
492
  def project_private!
145
493
  update_predefined_acl! "projectPrivate"
146
494
  end
147
495
  alias_method :projectPrivate!, :project_private!
148
496
 
497
+ ##
498
+ # Convenience method to apply the +publicRead+ predefined ACL
499
+ # rule to the file.
500
+ #
501
+ # === Example
502
+ #
503
+ # require "glcoud/storage"
504
+ #
505
+ # storage = Gcloud.storage
506
+ #
507
+ # bucket = storage.find_bucket "my-bucket"
508
+ #
509
+ # file = bucket.find_file "path/to/my-file.ext"
510
+ # file.acl.public!
511
+ #
149
512
  def public!
150
513
  update_predefined_acl! "publicRead"
151
514
  end