class Google::Cloud::Storage::File::Acl


file.acl.readers.each { |reader| puts reader }
file = bucket.file “path/to/my-file.ext”
bucket = storage.bucket “my-bucket”
storage = Google::Cloud::Storage.new
require “google/cloud/storage”
@example
Represents a File’s Access Control List.
# File 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, generation: nil

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:
  • generation (Integer) -- When present, selects a specific
  • entity (String) -- The entity holding the permission, in one of
def add_owner entity, generation: nil
  gapi = @service.insert_file_acl @bucket, @file, entity, "OWNER",
                                  generation: generation,
                                  user_project: user_project
  entity = gapi.entity
  @owners&.push entity
  entity
end

def add_reader entity, generation: nil

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:
  • generation (Integer) -- When present, selects a specific
  • entity (String) -- The entity holding the permission, in one of
def add_reader entity, generation: nil
  gapi = @service.insert_file_acl @bucket, @file, entity, "READER",
                                  generation: generation,
                                  user_project: user_project
  entity = gapi.entity
  @readers&.push entity
  entity
end

def auth! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def auth! generation: nil,
          if_generation_match: nil,
          if_generation_not_match: nil,
          if_metageneration_match: nil,
          if_metageneration_not_match: nil
  update_predefined_acl! "authenticatedRead",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def clear!

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

def delete entity, generation: nil

Returns:
  • (Boolean) - true if the delete operation did not raise an

Parameters:
  • generation (Integer) -- When present, selects a specific
  • entity (String) -- The entity holding the permission, in one of
def delete entity, generation: nil
  @service.delete_file_acl \
    @bucket, @file, entity,
    generation: generation, 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 file

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

def owner_full! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def owner_full! generation: nil,
                if_generation_match: nil,
                if_generation_not_match: nil,
                if_metageneration_match: nil,
                if_metageneration_not_match: nil
  update_predefined_acl! "bucketOwnerFullControl",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def owner_read! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def owner_read! generation: nil,
                if_generation_match: nil,
                if_generation_not_match: nil,
                if_metageneration_match: nil,
                if_metageneration_not_match: nil
  update_predefined_acl! "bucketOwnerRead",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def owners

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

def private! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def private! generation: nil,
             if_generation_match: nil,
             if_generation_not_match: nil,
             if_metageneration_match: nil,
             if_metageneration_not_match: nil
  update_predefined_acl! "private",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def project_private! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def project_private! generation: nil,
                     if_generation_match: nil,
                     if_generation_not_match: nil,
                     if_metageneration_match: nil,
                     if_metageneration_not_match: nil
  update_predefined_acl! "projectPrivate",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def public! generation: nil,

Parameters:
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • if_generation_not_match (Integer) -- Makes the operation conditional
  • if_generation_match (Integer) -- Makes the operation conditional
  • generation (Integer) -- Select a specific revision of the file to
def public! generation: nil,
            if_generation_match: nil,
            if_generation_not_match: nil,
            if_metageneration_match: nil,
            if_metageneration_not_match: nil
  update_predefined_acl! "publicRead",
                         generation: generation,
                         if_generation_match: if_generation_match,
                         if_generation_not_match: if_generation_not_match,
                         if_metageneration_match: if_metageneration_match,
                         if_metageneration_not_match: if_metageneration_not_match
end

def readers

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

def reload!


file.acl.reload!
file = bucket.file "path/to/my-file.ext"

bucket = storage.bucket "my-bucket"

storage = Google::Cloud::Storage.new

require "google/cloud/storage"
@example

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

def update_predefined_acl! acl_role,

def update_predefined_acl! acl_role,
                           generation: nil,
                           if_generation_match: nil,
                           if_generation_not_match: nil,
                           if_metageneration_match: nil,
                           if_metageneration_not_match: nil
  patched_file = Google::Apis::StorageV1::Object.new acl: []
  @service.patch_file @bucket,
                      @file,
                      patched_file,
                      generation: generation,
                      if_generation_match: if_generation_match,
                      if_generation_not_match: if_generation_not_match,
                      if_metageneration_match: if_metageneration_match,
                      if_metageneration_not_match: if_metageneration_not_match,
                      predefined_acl: acl_role,
                      user_project: user_project
  clear!
end