class Google::Cloud::Storage::Bucket::Acl


bucket.acl.readers.each { |reader| puts reader }
bucket = storage.bucket “my-bucket”
storage = Google::Cloud::Storage.new
require “google/cloud/storage”
@example
Represents a Bucket’s Access Control List.
# Bucket Access Control List
#

def self.predefined_rule_for rule_name

Other tags:
    Private: -
def self.predefined_rule_for rule_name
  RULES[rule_name.to_s]
end

def add_owner entity

Other tags:
    Example: Grant access to a group by prepending `"group-"` to email: -
    Example: Grant access to a user by prepending `"user-"` to an email: -

Returns:
  • (String) - The entity.

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def add_owner entity
  gapi = @service.insert_bucket_acl @bucket, entity, "OWNER",
                                    user_project: user_project
  entity = gapi.entity
  @owners&.push entity
  entity
end

def add_reader entity

Other tags:
    Example: Grant access to a group by prepending `"group-"` to email: -
    Example: Grant access to a user by prepending `"user-"` to an email: -

Returns:
  • (String) - The entity.

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def add_reader entity
  gapi = @service.insert_bucket_acl @bucket, entity, "READER",
                                    user_project: user_project
  entity = gapi.entity
  @readers&.push entity
  entity
end

def add_writer entity

Other tags:
    Example: Grant access to a group by prepending `"group-"` to email: -
    Example: Grant access to a user by prepending `"user-"` to an email: -

Returns:
  • (String) - The entity.

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def add_writer entity
  gapi = @service.insert_bucket_acl @bucket, entity, "WRITER",
                                    user_project: user_project
  entity = gapi.entity
  @writers&.push entity
  entity
end

def auth! if_metageneration_match: nil


bucket.acl.auth!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

rule to the bucket.
Convenience method to apply the `authenticatedRead` predefined ACL
#
def auth! if_metageneration_match: nil
  update_predefined_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
end

def clear!

def clear!
  @owners  = nil
  @writers = nil
  @readers = nil
  self
end

def delete entity

Returns:
  • (Boolean) -

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def delete entity
  @service.delete_bucket_acl @bucket, entity,
                             user_project: user_project
  @owners&.delete entity
  @writers&.delete entity
  @readers&.delete entity
  true
end

def entities_from_acls acls, role

def entities_from_acls acls, role
  selected = acls.select { |acl| acl.role == role }
  selected.map(&:entity)
end

def initialize bucket

Other tags:
    Private: - Initialized a new Acl object.
def initialize bucket
  @bucket = bucket.name
  @service = bucket.service
  @user_project = bucket.user_project
  @owners  = nil
  @writers = nil
  @readers = nil
end

def owners

Returns:
  • (Array) -
def owners
  reload! if @owners.nil?
  @owners
end

def private! if_metageneration_match: nil


bucket.acl.private!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

rule to the bucket.
Convenience method to apply the `private` predefined ACL
#
def private! if_metageneration_match: nil
  update_predefined_acl! "private", if_metageneration_match: if_metageneration_match
end

def project_private! if_metageneration_match: nil


bucket.acl.project_private!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

rule to the bucket.
Convenience method to apply the `projectPrivate` predefined ACL
#
def project_private! if_metageneration_match: nil
  update_predefined_acl! "projectPrivate", if_metageneration_match: if_metageneration_match
end

def public! if_metageneration_match: nil


bucket.acl.public!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

rule to the bucket.
Convenience method to apply the `publicRead` predefined ACL
#
def public! if_metageneration_match: nil
  update_predefined_acl! "publicRead", if_metageneration_match: if_metageneration_match
end

def public_write! if_metageneration_match: nil


bucket.acl.public_write!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

rule to the bucket.
Convenience method to apply the `publicReadWrite` predefined ACL
def public_write! if_metageneration_match: nil
  update_predefined_acl! "publicReadWrite", if_metageneration_match: if_metageneration_match
end

def readers

Returns:
  • (Array) -
def readers
  reload! if @readers.nil?
  @readers
end

def reload!


bucket.acl.reload!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

Reloads all Access Control List data for the bucket.
#
def reload!
  gapi = @service.list_bucket_acls @bucket, user_project: user_project
  acls = Array(gapi.items)
  @owners  = entities_from_acls acls, "OWNER"
  @writers = entities_from_acls acls, "WRITER"
  @readers = entities_from_acls acls, "READER"
end

def update_predefined_acl! acl_role, if_metageneration_match: nil

def update_predefined_acl! acl_role, if_metageneration_match: nil
  @service.patch_bucket @bucket, predefined_acl: acl_role,
                                 user_project: user_project,
                                 if_metageneration_match: if_metageneration_match
  clear!
end

def writers

Returns:
  • (Array) -
def writers
  reload! if @writers.nil?
  @writers
end