class Google::Cloud::Storage::Bucket::DefaultAcl


bucket.default_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 Default Access Control List.
# Bucket Default 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: -

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def add_owner entity
  gapi = @service.insert_default_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: -

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

def auth! if_metageneration_match: nil


bucket.default_acl.auth!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

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

def clear!

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

def delete entity

Parameters:
  • entity (String) -- The entity holding the permission, in one of
def delete entity
  @service.delete_default_acl @bucket, entity,
                              user_project: user_project
  @owners&.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 DefaultAcl object.
def initialize bucket
  @bucket = bucket.name
  @service = bucket.service
  @user_project = bucket.user_project
  @owners  = nil
  @readers = nil
end

def owner_full! if_metageneration_match: nil


bucket.default_acl.owner_full!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

predefined ACL rule to files in the bucket.
Convenience method to apply the default `bucketOwnerFullControl`
#
def owner_full! if_metageneration_match: nil
  update_predefined_default_acl! "bucketOwnerFullControl", if_metageneration_match: if_metageneration_match
end

def owner_read! if_metageneration_match: nil


bucket.default_acl.owner_read!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

predefined ACL rule to files in the bucket.
Convenience method to apply the default `bucketOwnerRead`
#
def owner_read! if_metageneration_match: nil
  update_predefined_default_acl! "bucketOwnerRead", if_metageneration_match: if_metageneration_match
end

def owners

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

def private! if_metageneration_match: nil


bucket.default_acl.private!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

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

def project_private! if_metageneration_match: nil


bucket.default_acl.project_private!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

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

def public! if_metageneration_match: nil


bucket.default_acl.public!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

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

def readers

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

def reload!


bucket.default_acl.reload!

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

Reloads all Default Access Control List data for the bucket.
#
def reload!
  gapi = @service.list_default_acls @bucket,
                                    user_project: user_project
  acls = Array(gapi.items).map do |acl|
    next acl if acl.is_a? Google::Apis::StorageV1::ObjectAccessControl
    raise "Unknown ACL format: #{acl.class}" unless acl.is_a? Hash
    Google::Apis::StorageV1::ObjectAccessControl.from_json acl.to_json
  end
  @owners  = entities_from_acls acls, "OWNER"
  @readers = entities_from_acls acls, "READER"
end

def update_predefined_default_acl! acl_role, if_metageneration_match: nil

def update_predefined_default_acl! acl_role, if_metageneration_match: nil
  @service.patch_bucket @bucket, predefined_default_acl: acl_role,
                                 user_project: user_project,
                                 if_metageneration_match: if_metageneration_match
  clear!
end