Class: Gcloud::Storage::File::Acl
- Inherits:
-
Object
- Object
- Gcloud::Storage::File::Acl
- Defined in:
- lib/gcloud/storage/file/acl.rb
Overview
# File Access Control List
Represents a File’s 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
-
#add_owner(entity, generation: nil) ⇒ Object
Grants owner permission to the file.
-
#add_reader(entity, generation: nil) ⇒ Object
Grants reader permission to the file.
-
#auth! ⇒ Object
(also: #authenticatedRead!, #auth_read!, #authenticated!, #authenticated_read!)
Convenience method to apply the ‘authenticatedRead` predefined ACL rule to the file.
-
#delete(entity, generation: nil) ⇒ Object
Permanently deletes the entity from the file’s access control list.
-
#initialize(file) ⇒ Acl
constructor
Must provide a valid Bucket object.
-
#owner_full! ⇒ Object
(also: #bucketOwnerFullControl!)
Convenience method to apply the ‘bucketOwnerFullControl` predefined ACL rule to the file.
-
#owner_read! ⇒ Object
(also: #bucketOwnerRead!)
Convenience method to apply the ‘bucketOwnerRead` predefined ACL rule to the file.
-
#owners ⇒ Array<String>
Lists the owners of the file.
-
#private! ⇒ Object
Convenience method to apply the ‘private` predefined ACL rule to the file.
-
#project_private! ⇒ Object
(also: #projectPrivate!)
Convenience method to apply the ‘projectPrivate` predefined ACL rule to the file.
-
#public! ⇒ Object
(also: #publicRead!, #public_read!)
Convenience method to apply the ‘publicRead` predefined ACL rule to the file.
-
#readers ⇒ Array<String>
Lists the readers of the file.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads all Access Control List data for the file.
Constructor Details
#initialize(file) ⇒ Acl
Must provide a valid Bucket object.
56 57 58 59 60 61 62 |
# File 'lib/gcloud/storage/file/acl.rb', line 56 def initialize file @bucket = file.bucket @file = file.name @service = file.service @owners = nil @readers = nil end |
Class Method Details
.predefined_rule_for(rule_name) ⇒ Object
273 274 275 |
# File 'lib/gcloud/storage/file/acl.rb', line 273 def self.predefined_rule_for rule_name RULES[rule_name.to_s] end |
Instance Method Details
#add_owner(entity, generation: nil) ⇒ Object
Grants owner permission to the file.
174 175 176 177 178 179 180 181 |
# File 'lib/gcloud/storage/file/acl.rb', line 174 def add_owner entity, generation: nil = { generation: generation } gapi = @service.insert_file_acl @bucket, @file, entity, "OWNER", entity = gapi.entity @owners.push entity unless @owners.nil? entity end |
#add_reader(entity, generation: nil) ⇒ Object
Grants reader permission to the file.
225 226 227 228 229 230 231 232 |
# File 'lib/gcloud/storage/file/acl.rb', line 225 def add_reader entity, generation: nil = { generation: generation } gapi = @service.insert_file_acl @bucket, @file, entity, "READER", entity = gapi.entity @readers.push entity unless @readers.nil? entity end |
#auth! ⇒ Object Also known as: authenticatedRead!, auth_read!, authenticated!, authenticated_read!
Convenience method to apply the ‘authenticatedRead` predefined ACL rule to the file.
294 295 296 |
# File 'lib/gcloud/storage/file/acl.rb', line 294 def auth! update_predefined_acl! "authenticatedRead" end |
#delete(entity, generation: nil) ⇒ Object
Permanently deletes the entity from the file’s access control list.
264 265 266 267 268 269 270 |
# File 'lib/gcloud/storage/file/acl.rb', line 264 def delete entity, generation: nil = { generation: generation } @service.delete_file_acl @bucket, @file, entity, @owners.delete entity unless @owners.nil? @readers.delete entity unless @readers.nil? true end |
#owner_full! ⇒ Object Also known as: bucketOwnerFullControl!
Convenience method to apply the ‘bucketOwnerFullControl` predefined ACL rule to the file.
317 318 319 |
# File 'lib/gcloud/storage/file/acl.rb', line 317 def owner_full! update_predefined_acl! "bucketOwnerFullControl" end |
#owner_read! ⇒ Object Also known as: bucketOwnerRead!
Convenience method to apply the ‘bucketOwnerRead` predefined ACL rule to the file.
337 338 339 |
# File 'lib/gcloud/storage/file/acl.rb', line 337 def owner_read! update_predefined_acl! "bucketOwnerRead" end |
#owners ⇒ Array<String>
Lists the owners of the file.
106 107 108 109 |
# File 'lib/gcloud/storage/file/acl.rb', line 106 def owners reload! if @owners.nil? @owners end |
#private! ⇒ Object
Convenience method to apply the ‘private` predefined ACL rule to the file.
357 358 359 |
# File 'lib/gcloud/storage/file/acl.rb', line 357 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 file.
376 377 378 |
# File 'lib/gcloud/storage/file/acl.rb', line 376 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 file.
396 397 398 |
# File 'lib/gcloud/storage/file/acl.rb', line 396 def public! update_predefined_acl! "publicRead" end |
#readers ⇒ Array<String>
Lists the readers of the file.
127 128 129 130 |
# File 'lib/gcloud/storage/file/acl.rb', line 127 def readers reload! if @readers.nil? @readers end |
#reload! ⇒ Object Also known as: refresh!
Reloads all Access Control List data for the file.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gcloud/storage/file/acl.rb', line 78 def reload! gapi = @service.list_file_acls @bucket, @file acls = Array(gapi.items).map do |acl| return acl if acl.is_a? Google::Apis::StorageV1::ObjectAccessControl fail "Unknown ACL format: #{acl.class}" unless acl.is_a? Hash Google::Apis::StorageV1::ObjectAccessControl.from_json acl.to_json end @owners = entities_from_acls acls, "OWNER" @readers = entities_from_acls acls, "READER" end |