Class: Google::Cloud::Storage::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Storage::Project
- Defined in:
- lib/google/cloud/storage/project.rb
Overview
Project
Represents the project that storage buckets and files belong to. All data in Google Cloud Storage belongs inside a project. A project consists of a set of users, a set of APIs, billing, authentication, and monitoring settings for those APIs.
Google::Cloud::Storage::Project is the main object for interacting with Google Storage. Bucket objects are created, read, updated, and deleted by Google::Cloud::Storage::Project.
Instance Method Summary collapse
-
#bucket(bucket_name, user_project: nil) ⇒ Google::Cloud::Storage::Bucket?
(also: #find_bucket)
Retrieves bucket by name.
-
#buckets(prefix: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::Storage::Bucket>
(also: #find_buckets)
Retrieves a list of buckets for the given project.
-
#create_bucket(bucket_name, acl: nil, default_acl: nil, location: nil, storage_class: nil, logging_bucket: nil, logging_prefix: nil, website_main: nil, website_404: nil, versioning: nil) {|bucket| ... } ⇒ Google::Cloud::Storage::Bucket
Creates a new bucket with optional attributes.
-
#project ⇒ Object
The Storage project connected to.
-
#signed_url(bucket, path, method: nil, expires: nil, content_type: nil, content_md5: nil, headers: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, query: nil) ⇒ Object
Access without authentication can be granted to a File for a specified period of time.
Instance Method Details
#bucket(bucket_name, user_project: nil) ⇒ Google::Cloud::Storage::Bucket? Also known as: find_bucket
Retrieves bucket by name.
183 184 185 186 187 188 |
# File 'lib/google/cloud/storage/project.rb', line 183 def bucket bucket_name, user_project: nil gapi = service.get_bucket bucket_name, user_project: user_project Bucket.from_gapi gapi, service, user_project: user_project rescue Google::Cloud::NotFoundError nil end |
#buckets(prefix: nil, token: nil, max: nil) ⇒ Array<Google::Cloud::Storage::Bucket> Also known as: find_buckets
Retrieves a list of buckets for the given project.
130 131 132 133 |
# File 'lib/google/cloud/storage/project.rb', line 130 def buckets prefix: nil, token: nil, max: nil gapi = service.list_buckets prefix: prefix, token: token, max: max Bucket::List.from_gapi gapi, service, prefix, max end |
#create_bucket(bucket_name, acl: nil, default_acl: nil, location: nil, storage_class: nil, logging_bucket: nil, logging_prefix: nil, website_main: nil, website_404: nil, versioning: nil) {|bucket| ... } ⇒ Google::Cloud::Storage::Bucket
Creates a new bucket with optional attributes. Also accepts a block for defining the CORS configuration for a static website served from the bucket. See Bucket::Cors for details.
The API call to create the bucket may be retried under certain conditions. See Google::Cloud#storage to control this behavior.
You can pass website settings for the bucket, including a block that defines CORS rule. See Bucket::Cors for details.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/google/cloud/storage/project.rb', line 310 def create_bucket bucket_name, acl: nil, default_acl: nil, location: nil, storage_class: nil, logging_bucket: nil, logging_prefix: nil, website_main: nil, website_404: nil, versioning: nil new_bucket = Google::Apis::StorageV1::Bucket.new({ name: bucket_name, location: location, storage_class: storage_class_for(storage_class) }.delete_if { |_, v| v.nil? }) 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.website_main = website_main unless website_main.nil? b.website_404 = website_404 unless website_404.nil? b.versioning = versioning unless versioning.nil? end yield updater if block_given? updater.check_for_changed_labels! updater.check_for_mutable_cors! gapi = service.insert_bucket \ new_bucket, acl: acl_rule(acl), default_acl: acl_rule(default_acl) Bucket.from_gapi gapi, service end |
#project ⇒ Object
The Storage project connected to.
75 76 77 |
# File 'lib/google/cloud/storage/project.rb', line 75 def project service.project end |
#signed_url(bucket, path, method: nil, expires: nil, content_type: nil, content_md5: nil, headers: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, query: nil) ⇒ Object
Access without authentication can be granted to a File for a specified
period of time. This URL uses a cryptographic signature of your
credentials to access the file identified by path
. A URL can be
created for paths that do not yet exist. For instance, a URL can be
created to PUT
file contents to.
Generating a URL requires service account credentials, either by
connecting with a service account when calling
Google::Cloud.storage, or by passing in the service account issuer
and signing_key
values. Although the private key can be passed as a
string for convenience, creating and storing an instance of
OpenSSL::PKey::RSA
is more efficient when making multiple calls to
signed_url
.
A SignedUrlUnavailable is raised if the service account credentials are missing. Service account credentials are acquired by following the steps in Service Account Authentication.
434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/google/cloud/storage/project.rb', line 434 def signed_url bucket, path, method: nil, expires: nil, content_type: nil, content_md5: nil, headers: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil, query: nil signer = File::Signer.new bucket, path, service signer.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, query: query end |