Class: Gcloud::Storage::Bucket::DefaultAcl

Inherits:
Object
  • Object
show all
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 }

Instance Method Summary collapse

Instance Method Details

#add_owner(entity) ⇒ Object

Grants default owner permission to files in the bucket.

Examples:

Grant access to a user by pre-pending "user-" to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_owner "user-#{email}"

Grant access to a group by pre-pending "group-" to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_owner "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers

613
614
615
616
617
618
619
620
621
# File 'lib/gcloud/storage/bucket/acl.rb', line 613

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.

Examples:

Grant access to a user by pre-pending "user-" to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_reader "user-#{email}"

Grant access to a group by pre-pending "group-" to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_reader "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers

707
708
709
710
711
712
713
714
715
# File 'lib/gcloud/storage/bucket/acl.rb', line 707

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.

Examples:

Grant access to a user by pre-pending "user-" to an email:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_writer "user-#{email}"

Grant access to a group by pre-pending "group-" to an email

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.add_writer "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers

660
661
662
663
664
665
666
667
668
# File 'lib/gcloud/storage/bucket/acl.rb', line 660

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.auth!

776
777
778
# File 'lib/gcloud/storage/bucket/acl.rb', line 776

def auth!
  update_predefined_default_acl! "authenticatedRead"
end

#delete(entity) ⇒ Object

Permanently deletes the entity from the bucket's default access control list for files.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

email = "[email protected]"
bucket.default_acl.delete "user-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers

744
745
746
747
748
749
750
751
752
753
# File 'lib/gcloud/storage/bucket/acl.rb', line 744

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.owner_full!

798
799
800
# File 'lib/gcloud/storage/bucket/acl.rb', line 798

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.owner_read!

817
818
819
# File 'lib/gcloud/storage/bucket/acl.rb', line 817

def owner_read!
  update_predefined_default_acl! "bucketOwnerRead"
end

#ownersArray<String>

Lists the default owners for files in the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.default_acl.owners.each { |owner| puts owner }

Returns:

  • (Array<String>)

531
532
533
534
# File 'lib/gcloud/storage/bucket/acl.rb', line 531

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.private!

836
837
838
# File 'lib/gcloud/storage/bucket/acl.rb', line 836

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.project_private!

854
855
856
# File 'lib/gcloud/storage/bucket/acl.rb', line 854

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.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.acl.public!

873
874
875
# File 'lib/gcloud/storage/bucket/acl.rb', line 873

def public!
  update_predefined_default_acl! "publicRead"
end

#readersArray<String>

Lists the default readers for files in the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.default_acl.readers.each { |reader| puts reader }

Returns:

  • (Array<String>)

571
572
573
574
# File 'lib/gcloud/storage/bucket/acl.rb', line 571

def readers
  reload! if @readers.nil?
  @readers
end

#reload!Object Also known as: refresh!

Reloads all Default Access Control List data for the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.default_acl.reload!

507
508
509
510
511
512
513
# File 'lib/gcloud/storage/bucket/acl.rb', line 507

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

#writersArray<String>

Lists the default writers for files in the bucket.

Examples:

require "gcloud"

gcloud = Gcloud.new
storage = gcloud.storage

bucket = storage.bucket "my-bucket"

bucket.default_acl.writers.each { |writer| puts writer }

Returns:

  • (Array<String>)

551
552
553
554
# File 'lib/gcloud/storage/bucket/acl.rb', line 551

def writers
  reload! if @writers.nil?
  @writers
end