Class: Gcloud::Storage::Bucket::Acl
- Inherits:
-
Object
- Object
- Gcloud::Storage::Bucket::Acl
- Defined in:
- lib/gcloud/storage/bucket/acl.rb
Overview
Bucket Access Control List
Represents a Bucket’s Access Control List.
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
-
#add_owner(entity) ⇒ Object
Grants owner permission to the bucket.
-
#add_reader(entity) ⇒ Object
Grants reader permission to the bucket.
-
#add_writer(entity) ⇒ Object
Grants writer permission to the bucket.
-
#auth! ⇒ Object
(also: #authenticatedRead!, #auth_read!, #authenticated!, #authenticated_read!)
Convenience method to apply the
authenticatedReadpredefined ACL rule to the bucket. -
#delete(entity) ⇒ Object
Permenently deletes the entity from the bucket’s access control list.
-
#initialize(bucket) ⇒ Acl
constructor
Initialized a new Acl object.
-
#owners ⇒ Object
Lists the owners of the bucket.
-
#private! ⇒ Object
Convenience method to apply the
privatepredefined ACL rule to the bucket. -
#project_private! ⇒ Object
(also: #projectPrivate!)
Convenience method to apply the
projectPrivatepredefined ACL rule to the bucket. -
#public! ⇒ Object
(also: #publicRead!, #public_read!)
Convenience method to apply the
publicReadpredefined ACL rule to the bucket. -
#public_write! ⇒ Object
(also: #publicReadWrite!)
Convenience method to apply the
publicReadWritepredefined ACL rule to the bucket. -
#readers ⇒ Object
Lists the readers of the bucket.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads all Access Control List data for the bucket.
-
#writers ⇒ Object
Lists the owners of the bucket.
Constructor Details
#initialize(bucket) ⇒ Acl
Initialized a new Acl object. Must provide a valid Bucket object.
52 53 54 55 56 57 58 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 52 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
:nodoc:
361 362 363 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 361 def self.predefined_rule_for rule_name #:nodoc: RULES[rule_name.to_s] end |
Instance Method Details
#add_owner(entity) ⇒ Object
Grants owner permission to the bucket.
Parameters
entity-
The entity holding the permission, in one of the following forms: (
String)-
user-userId
-
user-email
-
group-groupId
-
group-email
-
domain-domain
-
project-team-projectId
-
allUsers
-
allAuthenticatedUsers
-
Examples
Access to a bucket can be granted to a user by appending “user-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_owner "user-#{email}"
Access to a bucket can be granted to a group by appending “group-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_owner "group-#{email}"
198 199 200 201 202 203 204 205 206 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 198 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.
Parameters
entity-
The entity holding the permission, in one of the following forms: (
String)-
user-userId
-
user-email
-
group-groupId
-
group-email
-
domain-domain
-
project-team-projectId
-
allUsers
-
allAuthenticatedUsers
-
Examples
Access to a bucket can be granted to a user by appending “user-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_reader "user-#{email}"
Access to a bucket can be granted to a group by appending “group-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_reader "group-#{email}"
310 311 312 313 314 315 316 317 318 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 310 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.
Parameters
entity-
The entity holding the permission, in one of the following forms: (
String)-
user-userId
-
user-email
-
group-groupId
-
group-email
-
domain-domain
-
project-team-projectId
-
allUsers
-
allAuthenticatedUsers
-
Examples
Access to a bucket can be granted to a user by appending “user-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_writer "user-#{email}"
Access to a bucket can be granted to a group by appending “group-” to the email address:
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.add_writer "group-#{email}"
254 255 256 257 258 259 260 261 262 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 254 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.auth!
382 383 384 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 382 def auth! update_predefined_acl! "authenticatedRead" end |
#delete(entity) ⇒ Object
Permenently deletes the entity from the bucket’s access control list.
Parameters
entity-
The entity holding the permission, in one of the following forms: (
String)-
user-userId
-
user-email
-
group-groupId
-
group-email
-
domain-domain
-
project-team-projectId
-
allUsers
-
allAuthenticatedUsers
-
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
email = "[email protected]"
bucket.acl.delete "user-#{email}"
350 351 352 353 354 355 356 357 358 359 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 350 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 |
#owners ⇒ Object
Lists the owners of the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.owners.each { |owner| puts owner }
101 102 103 104 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 101 def owners reload! if @owners.nil? @owners end |
#private! ⇒ Object
Convenience method to apply the private predefined ACL rule to the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.private!
405 406 407 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 405 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.project_private!
424 425 426 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 424 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.public!
444 445 446 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 444 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.public_write!
464 465 466 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 464 def public_write! update_predefined_acl! "publicReadWrite" end |
#readers ⇒ Object
Lists the readers of the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.readers.each { |reader| puts reader }
147 148 149 150 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 147 def readers reload! if @readers.nil? @readers end |
#reload! ⇒ Object Also known as: refresh!
Reloads all Access Control List data for the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.reload!
74 75 76 77 78 79 80 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 74 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 |
#writers ⇒ Object
Lists the owners of the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.writers.each { |writer| puts writer }
124 125 126 127 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 124 def writers reload! if @writers.nil? @writers end |