Class: Gcloud::Storage::Bucket::Acl

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

Overview

# Bucket Access Control List

Represents a Bucket’s Access Control List.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.readers.each { |reader| puts reader }

Constant Summary collapse

RULES =
{ "authenticatedRead" => "authenticatedRead",
"auth" => "authenticatedRead",
"auth_read" => "authenticatedRead",
"authenticated" => "authenticatedRead",
"authenticated_read" => "authenticatedRead",
"private" => "private",
"projectPrivate" => "projectPrivate",
"proj_private" => "projectPrivate",
"project_private" => "projectPrivate",
"publicRead" => "publicRead",
"public" => "publicRead",
"public_read" => "publicRead",
"publicReadWrite" => "publicReadWrite",
"public_write" => "publicReadWrite" }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ Acl

Must provide a valid Bucket object.



54
55
56
57
58
59
60
# File 'lib/gcloud/storage/bucket/acl.rb', line 54

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

Class Method Details

.predefined_rule_for(rule_name) ⇒ Object



323
324
325
# File 'lib/gcloud/storage/bucket/acl.rb', line 323

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

Instance Method Details

#add_owner(entity) ⇒ Object

Grants owner permission to the bucket.

Examples:

Grant access to a user by pre-pending ‘“user-”` to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_owner "user-#{email}"

Grant access to a group by pre-pending ‘“group-”` to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_owner "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId

    • user-email

    • group-groupId

    • group-email

    • domain-domain

    • project-team-projectId

    • allUsers

    • allAuthenticatedUsers



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

def add_owner entity
  resp = @connection.insert_bucket_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

Grants reader permission to the bucket.

Examples:

Grant access to a user by pre-pending ‘“user-”` to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_reader "user-#{email}"

Grant access to a group by pre-pending ‘“group-”` to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_reader "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId

    • user-email

    • group-groupId

    • group-email

    • domain-domain

    • project-team-projectId

    • allUsers

    • allAuthenticatedUsers



275
276
277
278
279
280
281
282
283
# File 'lib/gcloud/storage/bucket/acl.rb', line 275

def add_reader entity
  resp = @connection.insert_bucket_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

Grants writer permission to the bucket.

Examples:

Grant access to a user by pre-pending ‘“user-”` to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_writer "user-#{email}"

Grant access to a group by pre-pending ‘“group-”` to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.add_writer "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId

    • user-email

    • group-groupId

    • group-email

    • domain-domain

    • project-team-projectId

    • allUsers

    • allAuthenticatedUsers



228
229
230
231
232
233
234
235
236
# File 'lib/gcloud/storage/bucket/acl.rb', line 228

def add_writer entity
  resp = @connection.insert_bucket_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!

Convenience method to apply the ‘authenticatedRead` predefined ACL rule to the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.auth!


343
344
345
# File 'lib/gcloud/storage/bucket/acl.rb', line 343

def auth!
  update_predefined_acl! "authenticatedRead"
end

#delete(entity) ⇒ Object

Permanently deletes the entity from the bucket’s access control list.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.acl.delete "user-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId

    • user-email

    • group-groupId

    • group-email

    • domain-domain

    • project-team-projectId

    • allUsers

    • allAuthenticatedUsers



311
312
313
314
315
316
317
318
319
320
# File 'lib/gcloud/storage/bucket/acl.rb', line 311

def delete entity
  resp = @connection.delete_bucket_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

#ownersArray<String>

Lists the owners of the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.owners.each { |owner| puts owner }

Returns:

  • (Array<String>)


99
100
101
102
# File 'lib/gcloud/storage/bucket/acl.rb', line 99

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

#private!Object

Convenience method to apply the ‘private` predefined ACL rule to the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.private!


365
366
367
# File 'lib/gcloud/storage/bucket/acl.rb', line 365

def private!
  update_predefined_acl! "private"
end

#project_private!Object Also known as: projectPrivate!

Convenience method to apply the ‘projectPrivate` predefined ACL rule to the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.project_private!


383
384
385
# File 'lib/gcloud/storage/bucket/acl.rb', line 383

def project_private!
  update_predefined_acl! "projectPrivate"
end

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

Convenience method to apply the ‘publicRead` predefined ACL rule to the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.public!


402
403
404
# File 'lib/gcloud/storage/bucket/acl.rb', line 402

def public!
  update_predefined_acl! "publicRead"
end

#public_write!Object Also known as: publicReadWrite!

Convenience method to apply the ‘publicReadWrite` predefined ACL rule to the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.public_write!


421
422
423
# File 'lib/gcloud/storage/bucket/acl.rb', line 421

def public_write!
  update_predefined_acl! "publicReadWrite"
end

#readersArray<String>

Lists the readers of the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.readers.each { |reader| puts reader }

Returns:

  • (Array<String>)


139
140
141
142
# File 'lib/gcloud/storage/bucket/acl.rb', line 139

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

#reload!Object Also known as: refresh!

Reloads all Access Control List data for the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.reload!


75
76
77
78
79
80
81
# File 'lib/gcloud/storage/bucket/acl.rb', line 75

def reload!
  resp = @connection.list_bucket_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

#writersArray<String>

Lists the owners of the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.writers.each { |writer| puts writer }

Returns:

  • (Array<String>)


119
120
121
122
# File 'lib/gcloud/storage/bucket/acl.rb', line 119

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