Class: Gcloud::Storage::Bucket::DefaultAcl
- Inherits:
-
Object
- Object
- Gcloud::Storage::Bucket::DefaultAcl
- Defined in:
- lib/gcloud/storage/bucket/acl.rb
Overview
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
authenticatedRead
predefined 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
bucketOwnerFullControl
predefined ACL rule to files in the bucket. -
#owner_read! ⇒ Object
(also: #bucketOwnerRead!)
Convenience method to apply the default
bucketOwnerRead
predefined 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
private
predefined ACL rule to files in the bucket. -
#project_private! ⇒ Object
(also: #projectPrivate!)
Convenience method to apply the default
projectPrivate
predefined ACL rule to files in the bucket. -
#public! ⇒ Object
(also: #publicRead!, #public_read!)
Convenience method to apply the default
publicRead
predefined ACL rule to files in the bucket. -
#readers ⇒ Object
Lists the default readers for files in the bucket.
-
#refresh! ⇒ Object
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.
518 519 520 521 522 523 524 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 518 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:
827 828 829 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 827 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}"
663 664 665 666 667 668 669 670 671 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 663 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}"
775 776 777 778 779 780 781 782 783 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 775 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}"
719 720 721 722 723 724 725 726 727 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 719 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!
848 849 850 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 848 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}"
816 817 818 819 820 821 822 823 824 825 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 816 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!
871 872 873 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 871 def owner_full! update_predefined_default_acl! "bucketOwnerFullControl" end |
#owner_read! ⇒ Object Also known as: bucketOwnerRead!
891 892 893 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 891 def owner_read! update_predefined_default_acl! "bucketOwnerRead" end |
#owners ⇒ Object
566 567 568 569 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 566 def owners refresh! if @owners.nil? @owners end |
#private! ⇒ Object
911 912 913 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 911 def private! update_predefined_default_acl! "private" end |
#project_private! ⇒ Object Also known as: projectPrivate!
930 931 932 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 930 def project_private! update_predefined_default_acl! "projectPrivate" end |
#public! ⇒ Object Also known as: publicRead!, public_read!
950 951 952 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 950 def public! update_predefined_default_acl! "publicRead" end |
#readers ⇒ Object
612 613 614 615 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 612 def readers refresh! if @readers.nil? @readers end |
#refresh! ⇒ Object
540 541 542 543 544 545 546 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 540 def refresh! 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
589 590 591 592 |
# File 'lib/gcloud/storage/bucket/acl.rb', line 589 def writers refresh! if @writers.nil? @writers end |