Class: Gcloud::Storage::Bucket::DefaultAcl
- Inherits:
-
Object
- Object
- Gcloud::Storage::Bucket::DefaultAcl
- Defined in:
- lib/gcloud/storage/bucket/acl.rb
Overview
Bucket Default Access Control List
Represents a Bucket’s Default Access Control List.
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.default_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) ⇒ Object
Grants default owner permission to files in the bucket.
-
#add_reader(entity) ⇒ Object
Grants default reader permission to files in the bucket.
-
#add_writer(entity) ⇒ Object
Grants default writer permission to files in the bucket.
-
#auth! ⇒ Object
(also: #authenticatedRead!, #auth_read!, #authenticated!, #authenticated_read!)
Convenience method to apply the default
authenticatedReadpredefined ACL rule to files in the bucket. -
#delete(entity) ⇒ Object
Permenently deletes the entity from the bucket’s default access control list for files.
-
#initialize(bucket) ⇒ DefaultAcl
constructor
Initialized a new DefaultAcl object.
-
#owner_full! ⇒ Object
(also: #bucketOwnerFullControl!)
Convenience method to apply the default
bucketOwnerFullControlpredefined ACL rule to files in the bucket. -
#owner_read! ⇒ Object
(also: #bucketOwnerRead!)
Convenience method to apply the default
bucketOwnerReadpredefined ACL rule to files in the bucket. -
#owners ⇒ Object
Lists the default owners for files in the bucket.
-
#private! ⇒ Object
Convenience method to apply the default
privatepredefined ACL rule to files in the bucket. -
#project_private! ⇒ Object
(also: #projectPrivate!)
Convenience method to apply the default
projectPrivatepredefined ACL rule to files in the bucket. -
#public! ⇒ Object
(also: #publicRead!, #public_read!)
Convenience method to apply the default
publicReadpredefined ACL rule to files in the bucket. -
#readers ⇒ Object
Lists the default readers for files in the bucket.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads all Default Access Control List data for the bucket.
-
#writers ⇒ Object
Lists the default writers for files in the bucket.
Constructor Details
#initialize(bucket) ⇒ DefaultAcl
Initialized a new DefaultAcl object. Must provide a valid Bucket object.
519 520 521 522 523 524 525 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 519 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:
829 830 831 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 829 def self.predefined_rule_for rule_name #:nodoc: RULES[rule_name.to_s] end |
Instance Method Details
#add_owner(entity) ⇒ Object
Grants default owner permission to files in 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.default_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.default_acl.add_owner "group-#{email}"
665 666 667 668 669 670 671 672 673 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 665 def add_owner entity resp = @connection.insert_default_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 default reader permission to files in 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.default_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.default_acl.add_reader "group-#{email}"
777 778 779 780 781 782 783 784 785 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 777 def add_reader entity resp = @connection.insert_default_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 default writer permission to files in 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.default_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.default_acl.add_writer "group-#{email}"
721 722 723 724 725 726 727 728 729 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 721 def add_writer entity resp = @connection.insert_default_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 default authenticatedRead predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.auth!
850 851 852 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 850 def auth! update_predefined_default_acl! "authenticatedRead" end |
#delete(entity) ⇒ Object
Permenently deletes the entity from the bucket’s default access control list for files.
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.default_acl.delete "user-#{email}"
818 819 820 821 822 823 824 825 826 827 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 818 def delete entity resp = @connection.delete_default_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 |
#owner_full! ⇒ Object Also known as: bucketOwnerFullControl!
Convenience method to apply the default bucketOwnerFullControl predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.owner_full!
873 874 875 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 873 def owner_full! update_predefined_default_acl! "bucketOwnerFullControl" end |
#owner_read! ⇒ Object Also known as: bucketOwnerRead!
Convenience method to apply the default bucketOwnerRead predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.owner_read!
893 894 895 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 893 def owner_read! update_predefined_default_acl! "bucketOwnerRead" end |
#owners ⇒ Object
Lists the default owners for files in the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.default_acl.owners.each { |owner| puts owner }
568 569 570 571 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 568 def owners reload! if @owners.nil? @owners end |
#private! ⇒ Object
Convenience method to apply the default private predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.private!
913 914 915 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 913 def private! update_predefined_default_acl! "private" end |
#project_private! ⇒ Object Also known as: projectPrivate!
Convenience method to apply the default projectPrivate predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.project_private!
932 933 934 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 932 def project_private! update_predefined_default_acl! "projectPrivate" end |
#public! ⇒ Object Also known as: publicRead!, public_read!
Convenience method to apply the default publicRead predefined ACL rule to files in the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.acl.public!
952 953 954 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 952 def public! update_predefined_default_acl! "publicRead" end |
#readers ⇒ Object
Lists the default readers for files in the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.default_acl.readers.each { |reader| puts reader }
614 615 616 617 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 614 def readers reload! if @readers.nil? @readers end |
#reload! ⇒ Object Also known as: refresh!
Reloads all Default Access Control List data for the bucket.
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.default_acl.reload!
541 542 543 544 545 546 547 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 541 def reload! resp = @connection.list_default_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 default writers for files in the bucket.
Returns
Array of Strings
Example
require "gcloud"
gcloud = Gcloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
bucket.default_acl.writers.each { |writer| puts writer }
591 592 593 594 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 591 def writers reload! if @writers.nil? @writers end |