Class: Gcloud::Storage::Project
- Inherits:
-
Object
- Object
- Gcloud::Storage::Project
- Defined in:
- lib/gcloud/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.
Gcloud::Storage::Project is the main object for interacting with Google Storage. Bucket objects are created, read, updated, and deleted by Gcloud::Storage::Project.
See Gcloud#storage
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#bucket(bucket_name) ⇒ Gcloud::Storage::Bucket?
(also: #find_bucket)
Retrieves bucket by name.
-
#buckets(prefix: nil, token: nil, max: nil) ⇒ Array<Gcloud::Storage::Bucket>
(also: #find_buckets)
Retrieves a list of buckets for the given project.
-
#create_bucket(bucket_name, acl: nil, default_acl: nil, cors: nil, location: nil, logging_bucket: nil, logging_prefix: nil, storage_class: nil, versioning: nil, website_main: nil, website_404: nil) {|cors| ... } ⇒ Gcloud::Storage::Bucket
Creates a new bucket with optional attributes.
-
#initialize(project, credentials) ⇒ Project
constructor
See Gcloud#storage.
-
#project ⇒ Object
The Storage project connected to.
Constructor Details
#initialize(project, credentials) ⇒ Project
See Gcloud#storage
58 59 60 61 62 |
# File 'lib/gcloud/storage/project.rb', line 58 def initialize project, credentials project = project.to_s # Always cast to a string fail ArgumentError, "project is missing" if project.empty? @connection = Connection.new project, credentials end |
Instance Attribute Details
#connection ⇒ Object
52 53 54 |
# File 'lib/gcloud/storage/project.rb', line 52 def connection @connection end |
Class Method Details
.default_project ⇒ Object
82 83 84 85 86 87 |
# File 'lib/gcloud/storage/project.rb', line 82 def self.default_project ENV["STORAGE_PROJECT"] || ENV["GCLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"] || Gcloud::GCE.project_id end |
Instance Method Details
#bucket(bucket_name) ⇒ Gcloud::Storage::Bucket? Also known as: find_bucket
Retrieves bucket by name.
162 163 164 165 166 167 168 169 170 |
# File 'lib/gcloud/storage/project.rb', line 162 def bucket bucket_name resp = connection.get_bucket bucket_name if resp.success? Bucket.from_gapi resp.data, connection else return nil if resp.data["error"]["code"] == 404 fail ApiError.from_response(resp) end end |
#buckets(prefix: nil, token: nil, max: nil) ⇒ Array<Gcloud::Storage::Bucket> Also known as: find_buckets
Retrieves a list of buckets for the given project.
134 135 136 137 138 139 140 141 142 |
# File 'lib/gcloud/storage/project.rb', line 134 def buckets prefix: nil, token: nil, max: nil = { prefix: prefix, token: token, max: max } resp = connection.list_buckets if resp.success? Bucket::List.from_response resp, connection, prefix, max else fail ApiError.from_response(resp) end end |
#create_bucket(bucket_name, acl: nil, default_acl: nil, cors: nil, location: nil, logging_bucket: nil, logging_prefix: nil, storage_class: nil, versioning: nil, website_main: nil, website_404: nil) {|cors| ... } ⇒ Gcloud::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 Backoff to control this behavior.
You can pass [website settings](cloud.google.com/storage/docs/website-configuration) for the bucket, including a block that defines CORS rule. See Bucket::Cors for details.
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/gcloud/storage/project.rb', line 293 def create_bucket bucket_name, acl: nil, default_acl: nil, cors: nil, location: nil, logging_bucket: nil, logging_prefix: nil, storage_class: nil, versioning: nil, website_main: nil, website_404: nil opts = { acl: acl_rule(acl), default_acl: acl_rule(default_acl), cors: cors, location: location, logging_bucket: logging_bucket, logging_prefix: logging_prefix, storage_class: storage_class, versioning: versioning, website_main: website_main, website_404: website_404 } if block_given? cors_builder = Bucket::Cors.new yield cors_builder opts[:cors] = cors_builder if cors_builder.changed? end insert_bucket bucket_name, opts end |
#project ⇒ Object
The Storage project connected to.
76 77 78 |
# File 'lib/gcloud/storage/project.rb', line 76 def project connection.project end |