class Google::Cloud::Storage::Project


file = bucket.file “path/to/my-file.ext”
bucket = storage.bucket “my-bucket”
storage = Google::Cloud::Storage.new
require “google/cloud/storage”
@example
See {Google::Cloud#storage}
read, updated, and deleted by Google::Cloud::Storage::Project.
Google Storage. {Google::Cloud::Storage::Bucket} objects are created,
Google::Cloud::Storage::Project is the main object for interacting with
authentication, and monitoring settings for those APIs.
A project consists of a set of users, a set of APIs, billing,
All data in Google Cloud Storage belongs inside a project.
Represents the project that storage buckets and files belong to.
# Project
#

def acl_rule option_name

def acl_rule option_name
  Bucket::Acl.predefined_rule_for option_name
end

def add_custom_header header_name, header_value

Returns:
  • (Google::Cloud::Storage::Project) - Returns the Project for method chaining

Parameters:
  • header_value (Object) -- Valid value of the Google extension header being added.
  • header_name (String) -- Name of Google extension header (custom HTTP header that
def add_custom_header header_name, header_value
  @service.add_custom_header header_name, header_value
  self
end

def add_custom_headers headers

Returns:
  • (Google::Cloud::Storage::Project) - Returns the Project for method chaining

Parameters:
  • headers (Hash) -- Google extension headers (custom HTTP headers that
def add_custom_headers headers
  @service.add_custom_headers headers
  self
end

def bucket bucket_name,

Other tags:
    Example: With `soft_deleted` set to true and generation specified: -
    Example: With `user_project` set to a project other than the default: -
    Example: With `user_project` set to bill costs to the default project: -

Returns:
  • (Google::Cloud::Storage::Bucket, nil) - Returns nil if bucket

Parameters:
  • soft_deleted (Boolean) -- If true, returns the soft-deleted bucket.
  • generation (Integer) -- generation no of bucket
  • user_project (Boolean, String) -- If this parameter is set to
  • if_metageneration_not_match (Integer) -- Makes the operation
  • if_metageneration_match (Integer) -- Makes the operation conditional
  • skip_lookup (Boolean) -- Optionally create a Bucket object
  • bucket_name (String) -- Name of a bucket.
def bucket bucket_name,
           skip_lookup: false,
           generation: nil,
           soft_deleted: nil,
           if_metageneration_match: nil,
           if_metageneration_not_match: nil,
           user_project: nil
  if skip_lookup
    return Bucket.new_lazy bucket_name, service,
                           user_project: user_project
  end
  gapi = service.get_bucket bucket_name,
                            if_metageneration_match: if_metageneration_match,
                            if_metageneration_not_match: if_metageneration_not_match,
                            user_project: user_project,
                            soft_deleted: soft_deleted,
                            generation: generation
  Bucket.from_gapi gapi, service, user_project: user_project
rescue Google::Cloud::NotFoundError
  nil
end

def buckets prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil

Other tags:
    Example: Retrieve soft deleted buckets -
    Example: Retrieve all buckets: (See {Bucket::List#all}) -
    Example: Retrieve buckets with names that begin with a given prefix: -

Returns:
  • (Array) - (See

Parameters:
  • user_project (Boolean, String) -- If this parameter is set to
  • max (Integer) -- Maximum number of buckets to return.
  • token (String) -- A previously-returned page token representing
  • prefix (String) -- Filter results to buckets whose names begin
def buckets prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil
  gapi = service.list_buckets \
    prefix: prefix, token: token, max: max, user_project: user_project, soft_deleted: soft_deleted
  Bucket::List.from_gapi \
    gapi, service, prefix, max, user_project: user_project, soft_deleted: soft_deleted
end

def create_bucket bucket_name,

Other tags:
    Example: Configure the bucket in a block: -

Returns:
  • (Google::Cloud::Storage::Bucket) -

Other tags:
    Yieldparam: bucket - the bucket object to be configured

Other tags:
    Yield: - a block for configuring the bucket before it is

Parameters:
  • enable_object_retention (Boolean) --
  • autoclass_enabled (Boolean) -- The bucket's autoclass configuration.
  • user_project (String) -- If this parameter is set to a project ID
  • website_404 (String) -- The page returned from a static website
  • website_main (String) -- The index page returned from a static
  • versioning (Boolean) -- Whether [Object
  • storage_class (Symbol, String) -- Defines how objects in the
  • logging_prefix (String) -- The prefix used to create log object
  • logging_bucket (String) -- The destination bucket for the bucket's
  • location (String) -- The location of the bucket. Optional.
  • default_acl (String) -- Apply a predefined set of default object
  • acl (String) -- Apply a predefined set of access controls to this
  • bucket_name (String) -- Name of a bucket.

Other tags:
    See: https://cloud.google.com/storage/docs/website-configuration - How
    See: https://cloud.google.com/storage/docs/cross-origin - Cross-Origin
def create_bucket bucket_name,
                  acl: nil,
                  default_acl: nil,
                  location: nil,
                  custom_placement_config: nil,
                  storage_class: nil,
                  logging_bucket: nil,
                  logging_prefix: nil,
                  website_main: nil,
                  website_404: nil,
                  versioning: nil,
                  requester_pays: nil,
                  user_project: nil,
                  autoclass_enabled: false,
                  enable_object_retention: nil,
                  hierarchical_namespace: nil
  params = {
    name: bucket_name,
    location: location,
    custom_placement_config: custom_placement_config,
    hierarchical_namespace: hierarchical_namespace
  }.delete_if { |_, v| v.nil? }
  new_bucket = Google::Apis::StorageV1::Bucket.new(**params)
  storage_class = storage_class_for storage_class
  updater = Bucket::Updater.new(new_bucket).tap do |b|
    b.logging_bucket = logging_bucket unless logging_bucket.nil?
    b.logging_prefix = logging_prefix unless logging_prefix.nil?
    b.autoclass_enabled = autoclass_enabled
    b.storage_class = storage_class unless storage_class.nil?
    b.website_main = website_main unless website_main.nil?
    b.website_404 = website_404 unless website_404.nil?
    b.versioning = versioning unless versioning.nil?
    b.requester_pays = requester_pays unless requester_pays.nil?
    b.hierarchical_namespace = hierarchical_namespace unless hierarchical_namespace.nil?
  end
  yield updater if block_given?
  updater.check_for_changed_labels!
  updater.check_for_mutable_cors!
  updater.check_for_mutable_lifecycle!
  gapi = service.insert_bucket \
    new_bucket, acl: acl_rule(acl), default_acl: acl_rule(default_acl),
                user_project: user_project,
                enable_object_retention: enable_object_retention
  Bucket.from_gapi gapi, service, user_project: user_project
end

def create_hmac_key service_account_email, project_id: nil,

Returns:
  • (Google::Cloud::Storage::HmacKey) -

Parameters:
  • user_project (String) -- If this parameter is set to a project ID
  • project_id (String) -- The project ID associated with
  • service_account_email (String) -- The email address of the service
def create_hmac_key service_account_email, project_id: nil,
                    user_project: nil
  gapi = service.create_hmac_key service_account_email,
                                 project_id: project_id,
                                 user_project: user_project
  HmacKey.from_gapi gapi, service, user_project: user_project
end

def hmac_key access_id, project_id: nil, user_project: nil

Returns:
  • (Google::Cloud::Storage::HmacKey) -

Parameters:
  • user_project (String) -- If this parameter is set to a project ID
  • project_id (String) -- The project ID associated with the
def hmac_key access_id, project_id: nil, user_project: nil
  gapi = service.get_hmac_key \
    access_id, project_id: project_id, user_project: user_project
  HmacKey.from_gapi_metadata gapi, service, user_project: user_project
end

def hmac_keys service_account_email: nil, project_id: nil,

Returns:
  • (Google::Cloud::Storage::HmacKey) -

Parameters:
  • user_project (String) -- If this parameter is set to a project ID
  • max (Integer) -- Maximum number of keys to return.
  • token (String) -- A previously-returned page token representing
  • show_deleted_keys (Boolean) --
  • project_id (String) -- The project ID associated with the
  • service_account_email (String) --
def hmac_keys service_account_email: nil, project_id: nil,
              show_deleted_keys: nil, token: nil, max: nil,
              user_project: nil
  gapi = service.list_hmac_keys \
    max: max, token: token,
    service_account_email: service_account_email,
    project_id: project_id, show_deleted_keys: show_deleted_keys,
    user_project: user_project
  HmacKey::List.from_gapi \
    gapi, service,
    service_account_email: nil, show_deleted_keys: nil,
    max: max, user_project: user_project
end

def initialize service

Other tags:
    Private: - Creates a new Project instance.
def initialize service
  @service = service
end

def project_id

Returns:
  • (String) -
def project_id
  service.project
end

def restore_bucket bucket_name,

Returns:
  • (Google::Cloud::Storage::Bucket, nil) - Returns nil if bucket

Parameters:
  • generation (Fixnum) -- Generation of the bucket.
  • bucket_name (String) -- Name of the bucket.
def restore_bucket bucket_name,
                   generation,
                   options: {}
  gapi = service.restore_bucket bucket_name, generation,
                                options: options
  Bucket.from_gapi gapi, service
end

def service_account_email

Returns:
  • (String) - The service account email address.
def service_account_email
  @service_account_email ||= service.project_service_account.email_address
end

def signed_url bucket,

Other tags:
    Example: Generating a signed URL for resumable upload: -
    Example: Using the `headers` option: -
    Example: Using Cloud IAMCredentials signBlob to create the signature: -
    Example: Using the `issuer` and `signing_key` options: -
    Example: Using the `expires` and `version` options: -

Raises:
  • (SignedUrlUnavailable) - If the service account credentials

Returns:
  • (String) - The signed URL.

Parameters:
  • version (Symbol, String) -- The version of the signed credential
  • bucket_bound_hostname (String) -- Use a bucket-bound hostname, which
  • virtual_hosted_style (Boolean) -- Whether to use a virtual hosted-style
  • scheme (String) -- The URL scheme. The default value is `HTTPS`.
  • query (Hash) -- Query string parameters to include in the signed
  • signer (OpenSSL::PKey::RSA, String, Proc) -- Service Account's
  • private_key (OpenSSL::PKey::RSA, String, Proc) -- Service Account's
  • signing_key (OpenSSL::PKey::RSA, String, Proc) -- Service Account's
  • client_email (String) -- Service Account's Client Email.
  • issuer (String) -- Service Account's Client Email.
  • headers (Hash) -- Google extension headers (custom HTTP headers
  • content_md5 (String) -- The MD5 digest value in base64. If you
  • content_type (String) -- When provided, the client (browser) must
  • expires (Integer) -- The number of seconds until the URL expires.
  • method (String) -- The HTTP verb to be used with the signed URL.
  • path (String) -- Path to the file in Google Cloud Storage.
  • bucket (String, nil) -- Name of the bucket, or nil if URL for all

Other tags:
    See: https://cloud.google.com/storage/docs/access-control/signed-urls#signing-resumable -
    See: https://cloud.google.com/storage/docs/access-control/signed-urls -
def signed_url bucket,
               path,
               method: "GET",
               expires: nil,
               content_type: nil,
               content_md5: nil,
               headers: nil,
               issuer: nil,
               client_email: nil,
               signing_key: nil,
               private_key: nil,
               signer: nil,
               query: nil,
               scheme: "HTTPS",
               virtual_hosted_style: nil,
               bucket_bound_hostname: nil,
               version: nil
  version ||= :v2
  case version.to_sym
  when :v2
    sign = File::SignerV2.new bucket, path, service
    sign.signed_url method: method,
                    expires: expires,
                    headers: headers,
                    content_type: content_type,
                    content_md5: content_md5,
                    issuer: issuer,
                    client_email: client_email,
                    signing_key: signing_key,
                    private_key: private_key,
                    signer: signer,
                    query: query
  when :v4
    sign = File::SignerV4.new bucket, path, service
    sign.signed_url method: method,
                    expires: expires,
                    headers: headers,
                    issuer: issuer,
                    client_email: client_email,
                    signing_key: signing_key,
                    private_key: private_key,
                    signer: signer,
                    query: query,
                    scheme: scheme,
                    virtual_hosted_style: virtual_hosted_style,
                    bucket_bound_hostname: bucket_bound_hostname
  else
    raise ArgumentError, "version '#{version}' not supported"
  end
end

def universe_domain

Returns:
  • (String) -
def universe_domain
  service.universe_domain
end