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.
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.readers.each { |reader| puts reader }
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.
-
#add_writer(entity, generation: nil) ⇒ Object
Grants writer permission to the file.
-
#auth! ⇒ Object
(also: #authenticatedRead!, #auth_read!, #authenticated!, #authenticated_read!)
Convenience method to apply the
authenticatedReadpredefined 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
Initialized a new Acl object.
-
#owner_full! ⇒ Object
(also: #bucketOwnerFullControl!)
Convenience method to apply the
bucketOwnerFullControlpredefined ACL rule to the file. -
#owner_read! ⇒ Object
(also: #bucketOwnerRead!)
Convenience method to apply the
bucketOwnerReadpredefined ACL rule to the file. -
#owners ⇒ Object
Lists the owners of the file.
-
#private! ⇒ Object
Convenience method to apply the
privatepredefined ACL rule to the file. -
#project_private! ⇒ Object
(also: #projectPrivate!)
Convenience method to apply the
projectPrivatepredefined ACL rule to the file. -
#public! ⇒ Object
(also: #publicRead!, #public_read!)
Convenience method to apply the
publicReadpredefined ACL rule to the file. -
#readers ⇒ Object
Lists the readers of the file.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads all Access Control List data for the file.
-
#writers ⇒ Object
Lists the owners of the file.
Constructor Details
#initialize(file) ⇒ Acl
Initialized a new Acl object. Must provide a valid Bucket object.
54 55 56 57 58 59 60 61 |
# File 'lib/gcloud/storage/file/acl.rb', line 54 def initialize file #:nodoc: @bucket = file.bucket @file = file.name @connection = file.connection @owners = nil @writers = nil @readers = nil end |
Class Method Details
.predefined_rule_for(rule_name) ⇒ Object
:nodoc:
398 399 400 |
# File 'lib/gcloud/storage/file/acl.rb', line 398 def self.predefined_rule_for rule_name #:nodoc: RULES[rule_name.to_s] end |
Instance Method Details
#add_owner(entity, generation: nil) ⇒ Object
Grants owner permission to the file.
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
-
generation-
When present, selects a specific revision of this object. Default is the latest version. (
Integer)
Examples
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_owner "user-#{email}"
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_owner "group-#{email}"
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/gcloud/storage/file/acl.rb', line 211 def add_owner entity, generation: nil = { generation: generation } resp = @connection.insert_file_acl @bucket, @file, entity, "OWNER", if resp.success? entity = resp.data["entity"] @owners.push entity unless @owners.nil? return entity end nil end |
#add_reader(entity, generation: nil) ⇒ Object
Grants reader permission to the file.
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
-
generation-
When present, selects a specific revision of this object. Default is the latest version. (
Integer)
Examples
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_reader "user-#{email}"
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_reader "group-#{email}"
339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/gcloud/storage/file/acl.rb', line 339 def add_reader entity, generation: nil = { generation: generation } resp = @connection.insert_file_acl @bucket, @file, entity, "READER", if resp.success? entity = resp.data["entity"] @readers.push entity unless @readers.nil? return entity end nil end |
#add_writer(entity, generation: nil) ⇒ Object
Grants writer permission to the file.
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
-
generation-
When present, selects a specific revision of this object. Default is the latest version. (
Integer)
Examples
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_writer "user-#{email}"
Access to a file 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"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.add_writer "group-#{email}"
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/gcloud/storage/file/acl.rb', line 275 def add_writer entity, generation: nil = { generation: generation } resp = @connection.insert_file_acl @bucket, @file, 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 file.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.auth!
420 421 422 |
# File 'lib/gcloud/storage/file/acl.rb', line 420 def auth! update_predefined_acl! "authenticatedRead" end |
#delete(entity, generation: nil) ⇒ Object
Permanently deletes the entity from the file’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
-
generation-
When present, selects a specific revision of this object. Default is the latest version. (
Integer)
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
email = "[email protected]"
file.acl.delete "user-#{email}"
386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/gcloud/storage/file/acl.rb', line 386 def delete entity, generation: nil = { generation: generation } resp = @connection.delete_file_acl @bucket, @file, 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!
Convenience method to apply the bucketOwnerFullControl predefined ACL rule to the file.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.owner_full!
444 445 446 |
# File 'lib/gcloud/storage/file/acl.rb', line 444 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.owner_read!
465 466 467 |
# File 'lib/gcloud/storage/file/acl.rb', line 465 def owner_read! update_predefined_acl! "bucketOwnerRead" end |
#owners ⇒ Object
Lists the owners of the file.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.owners.each { |owner| puts owner }
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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.private!
486 487 488 |
# File 'lib/gcloud/storage/file/acl.rb', line 486 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.project_private!
506 507 508 |
# File 'lib/gcloud/storage/file/acl.rb', line 506 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.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.public!
527 528 529 |
# File 'lib/gcloud/storage/file/acl.rb', line 527 def public! update_predefined_acl! "publicRead" end |
#readers ⇒ Object
Lists the readers of the file.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.readers.each { |reader| puts reader }
154 155 156 157 |
# File 'lib/gcloud/storage/file/acl.rb', line 154 def readers reload! if @readers.nil? @readers end |
#reload! ⇒ Object Also known as: refresh!
Reloads all Access Control List data for the file.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.reload!
78 79 80 81 82 83 84 |
# File 'lib/gcloud/storage/file/acl.rb', line 78 def reload! resp = @connection.list_file_acls @bucket, @file 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 file.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"
file.acl.writers.each { |writer| puts writer }
130 131 132 133 |
# File 'lib/gcloud/storage/file/acl.rb', line 130 def writers reload! if @writers.nil? @writers end |