Class: Gcloud::Storage::Bucket::DefaultAcl

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/storage/bucket/acl.rb

Overview

Represents a Bucket’s Default Access Control List.

Constant Summary collapse

RULES =
{ "authenticatedRead" => "authenticatedRead",
"auth" => "authenticatedRead",
"auth_read" => "authenticatedRead",
"authenticated" => "authenticatedRead",
"authenticated_read" => "authenticatedRead",
"bucketOwnerFullControl" => "bucketOwnerFullControl",
"owner_full" => "bucketOwnerFullControl",
"bucketOwnerRead" => "bucketOwnerRead",
"owner_read" => "bucketOwnerRead",
"private" => "private",
"projectPrivate" => "projectPrivate",
"project_private" => "projectPrivate",
"publicRead" => "publicRead",
"public" => "publicRead",
"public_read" => "publicRead" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ DefaultAcl

Initialized a new DefaultAcl object. Must provide a valid Bucket object.



183
184
185
186
187
188
189
# File 'lib/gcloud/storage/bucket/acl.rb', line 183

def initialize bucket #:nodoc:
  @bucket = bucket.name
  @connection = bucket.connection
  @owners  = nil
  @writers = nil
  @readers = nil
end

Class Method Details

.predefined_rule_for(rule_name) ⇒ Object



255
256
257
# File 'lib/gcloud/storage/bucket/acl.rb', line 255

def self.predefined_rule_for rule_name
  RULES[rule_name.to_s]
end

Instance Method Details

#add_owner(entity) ⇒ Object



214
215
216
217
218
219
220
221
222
# File 'lib/gcloud/storage/bucket/acl.rb', line 214

def add_owner entity
  resp = @connection.insert_default_acl @bucket, entity, "OWNER"
  if resp.success?
    entity = resp.data["entity"]
    @owners.push entity unless @owners.nil?
    return entity
  end
  nil
end

#add_reader(entity) ⇒ Object



234
235
236
237
238
239
240
241
242
# File 'lib/gcloud/storage/bucket/acl.rb', line 234

def add_reader entity
  resp = @connection.insert_default_acl @bucket, entity, "READER"
  if resp.success?
    entity = resp.data["entity"]
    @readers.push entity unless @readers.nil?
    return entity
  end
  nil
end

#add_writer(entity) ⇒ Object



224
225
226
227
228
229
230
231
232
# File 'lib/gcloud/storage/bucket/acl.rb', line 224

def add_writer entity
  resp = @connection.insert_default_acl @bucket, entity, "WRITER"
  if resp.success?
    entity = resp.data["entity"]
    @writers.push entity unless @writers.nil?
    return entity
  end
  nil
end

#auth!Object Also known as: authenticatedRead!, auth_read!, authenticated!, authenticated_read!

Predefined ACL helpers



261
262
263
# File 'lib/gcloud/storage/bucket/acl.rb', line 261

def auth!
  update_predefined_default_acl! "authenticatedRead"
end

#delete(entity) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/gcloud/storage/bucket/acl.rb', line 244

def delete entity
  resp = @connection.delete_default_acl @bucket, entity
  if resp.success?
    @owners.delete entity  unless @owners.nil?
    @writers.delete entity unless @writers.nil?
    @readers.delete entity unless @readers.nil?
    return true
  end
  false
end

#owner_full!Object Also known as: bucketOwnerFullControl!



269
270
271
# File 'lib/gcloud/storage/bucket/acl.rb', line 269

def owner_full!
  update_predefined_default_acl! "bucketOwnerFullControl"
end

#owner_read!Object Also known as: bucketOwnerRead!



274
275
276
# File 'lib/gcloud/storage/bucket/acl.rb', line 274

def owner_read!
  update_predefined_default_acl! "bucketOwnerRead"
end

#ownersObject



199
200
201
202
# File 'lib/gcloud/storage/bucket/acl.rb', line 199

def owners
  refresh! if @owners.nil?
  @owners
end

#private!Object



279
280
281
# File 'lib/gcloud/storage/bucket/acl.rb', line 279

def private!
  update_predefined_default_acl! "private"
end

#project_private!Object Also known as: projectPrivate!



283
284
285
# File 'lib/gcloud/storage/bucket/acl.rb', line 283

def project_private!
  update_predefined_default_acl! "projectPrivate"
end

#public!Object Also known as: publicRead!, public_read!



288
289
290
# File 'lib/gcloud/storage/bucket/acl.rb', line 288

def public!
  update_predefined_default_acl! "publicRead"
end

#readersObject



209
210
211
212
# File 'lib/gcloud/storage/bucket/acl.rb', line 209

def readers
  refresh! if @readers.nil?
  @readers
end

#refresh!Object



191
192
193
194
195
196
197
# File 'lib/gcloud/storage/bucket/acl.rb', line 191

def refresh!
  resp = @connection.list_default_acls @bucket
  acls = resp.data["items"]
  @owners  = entities_from_acls acls, "OWNER"
  @writers = entities_from_acls acls, "WRITER"
  @readers = entities_from_acls acls, "READER"
end

#writersObject



204
205
206
207
# File 'lib/gcloud/storage/bucket/acl.rb', line 204

def writers
  refresh! if @writers.nil?
  @writers
end