Class: Gcloud::Storage::Bucket::Acl
- Inherits:
-
Object
- Object
- Gcloud::Storage::Bucket::Acl
- Defined in:
- lib/gcloud/storage/bucket/acl.rb
Overview
Represents a Bucket’s Access Control List.
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
- #add_reader(entity) ⇒ Object
- #add_writer(entity) ⇒ Object
-
#auth! ⇒ Object
(also: #authenticatedRead!, #auth_read!, #authenticated!, #authenticated_read!)
Predefined ACL helpers.
- #delete(entity) ⇒ Object
-
#initialize(bucket) ⇒ Acl
constructor
Initialized a new Acl object.
- #owners ⇒ Object
- #private! ⇒ Object
- #project_private! ⇒ Object (also: #projectPrivate!)
- #public! ⇒ Object (also: #publicRead!, #public_read!)
- #public_write! ⇒ Object (also: #publicReadWrite!)
- #readers ⇒ Object
- #refresh! ⇒ Object
- #writers ⇒ Object
Constructor Details
#initialize(bucket) ⇒ Acl
Initialized a new Acl object. Must provide a valid Bucket object.
39 40 41 42 43 44 45 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 39 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
111 112 113 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 111 def self.predefined_rule_for rule_name RULES[rule_name.to_s] end |
Instance Method Details
#add_owner(entity) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 70 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
90 91 92 93 94 95 96 97 98 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 90 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
80 81 82 83 84 85 86 87 88 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 80 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!
Predefined ACL helpers
117 118 119 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 117 def auth! update_predefined_acl! "authenticatedRead" end |
#delete(entity) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 100 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
55 56 57 58 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 55 def owners refresh! if @owners.nil? @owners end |
#private! ⇒ Object
125 126 127 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 125 def private! update_predefined_acl! "private" end |
#project_private! ⇒ Object Also known as: projectPrivate!
129 130 131 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 129 def project_private! update_predefined_acl! "projectPrivate" end |
#public! ⇒ Object Also known as: publicRead!, public_read!
134 135 136 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 134 def public! update_predefined_acl! "publicRead" end |
#public_write! ⇒ Object Also known as: publicReadWrite!
140 141 142 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 140 def public_write! update_predefined_acl! "publicReadWrite" end |
#readers ⇒ Object
65 66 67 68 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 65 def readers refresh! if @readers.nil? @readers end |
#refresh! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 47 def refresh! 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
60 61 62 63 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 60 def writers refresh! if @writers.nil? @writers end |