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
-
#add_custom_header(header_name, header_value) ⇒ Google::Cloud::Storage::Project
Add custom Google extension header to the requests that use the signed URLs.
-
#add_custom_headers(headers) ⇒ Google::Cloud::Storage::Project
Add custom Google extension headers to the requests that use the signed URLs.
-
#bucket(bucket_name, skip_lookup: false, generation: nil, soft_deleted: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil) ⇒ Google::Cloud::Storage::Bucket?
(also: #find_bucket)
Retrieves bucket by name.
-
#buckets(prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil, return_partial_success: 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, 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) {|bucket| ... } ⇒ Google::Cloud::Storage::Bucket
Creates a new bucket with optional attributes.
-
#create_hmac_key(service_account_email, project_id: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Creates a new HMAC key.
-
#hmac_key(access_id, project_id: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Retrieves an HMAC key's metadata; the key's secret is not included in the representation.
-
#hmac_keys(service_account_email: nil, project_id: nil, show_deleted_keys: nil, token: nil, max: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Retrieves a list of HMAC key metadata matching the criteria; the keys' secrets are not included.
-
#project_id ⇒ String
(also: #project)
The Storage project connected to.
-
#restore_bucket(bucket_name, generation, options: {}) ⇒ Google::Cloud::Storage::Bucket?
Restores a soft deleted bucket with bucket name and generation.
-
#service_account_email ⇒ String
The Google Cloud Storage managed service account created for the project used to initialize the client library.
-
#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) ⇒ String
Generates a signed URL.
-
#universe_domain ⇒ String
The universe domain the client is connected to.
Instance Method Details
#add_custom_header(header_name, header_value) ⇒ Google::Cloud::Storage::Project
Add custom Google extension header to the requests that use the signed URLs.
135 136 137 138 |
# File 'lib/google/cloud/storage/project.rb', line 135 def add_custom_header header_name, header_value @service.add_custom_header header_name, header_value self end |
#add_custom_headers(headers) ⇒ Google::Cloud::Storage::Project
Add custom Google extension headers to the requests that use the signed URLs.
118 119 120 121 |
# File 'lib/google/cloud/storage/project.rb', line 118 def add_custom_headers headers @service.add_custom_headers headers self end |
#bucket(bucket_name, skip_lookup: false, generation: nil, soft_deleted: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, user_project: nil) ⇒ Google::Cloud::Storage::Bucket? Also known as: find_bucket
Retrieves bucket by name.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/google/cloud/storage/project.rb', line 295 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_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 |
#buckets(prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil, return_partial_success: nil) ⇒ Array<Google::Cloud::Storage::Bucket> Also known as: find_buckets
Retrieves a list of buckets for the given project.
If true, the response will contain a list of unreachable buckets. If false, ListBuckets will throw an error if there are any unreachable buckets.
217 218 219 220 221 222 223 |
# File 'lib/google/cloud/storage/project.rb', line 217 def buckets prefix: nil, token: nil, max: nil, user_project: nil, soft_deleted: nil, return_partial_success: nil gapi = service.list_buckets \ prefix: prefix, token: token, max: max, user_project: user_project, soft_deleted: soft_deleted, return_partial_success: return_partial_success Bucket::List.from_gapi \ gapi, service, prefix, max, user_project: user_project, soft_deleted: soft_deleted, return_partial_success: return_partial_success end |
#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) {|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.
Before enabling uniform bucket-level access (see Bucket#uniform_bucket_level_access=) please review uniform bucket-level access.
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/google/cloud/storage/project.rb', line 465 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 |
#create_hmac_key(service_account_email, project_id: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Creates a new HMAC key.
528 529 530 531 532 533 534 |
# File 'lib/google/cloud/storage/project.rb', line 528 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 |
#hmac_key(access_id, project_id: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Retrieves an HMAC key's metadata; the key's secret is not included in the representation.
552 553 554 555 556 |
# File 'lib/google/cloud/storage/project.rb', line 552 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. gapi, service, user_project: user_project end |
#hmac_keys(service_account_email: nil, project_id: nil, show_deleted_keys: nil, token: nil, max: nil, user_project: nil) ⇒ Google::Cloud::Storage::HmacKey
Retrieves a list of HMAC key metadata matching the criteria; the keys' secrets are not included.
582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
# File 'lib/google/cloud/storage/project.rb', line 582 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 |
#project_id ⇒ String Also known as: project
The Storage project connected to.
89 90 91 |
# File 'lib/google/cloud/storage/project.rb', line 89 def project_id service.project end |
#restore_bucket(bucket_name, generation, options: {}) ⇒ Google::Cloud::Storage::Bucket?
Restores a soft deleted bucket with bucket name and generation.
615 616 617 618 619 620 621 |
# File 'lib/google/cloud/storage/project.rb', line 615 def restore_bucket bucket_name, generation, options: {} gapi = service.restore_bucket bucket_name, generation, options: Bucket.from_gapi gapi, service end |
#service_account_email ⇒ String
The Google Cloud Storage managed service account created for the project used to initialize the client library. (See also #project_id.)
101 102 103 |
# File 'lib/google/cloud/storage/project.rb', line 101 def service_account_email @service_account_email ||= service.project_service_account.email_address end |
#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) ⇒ String
Generates a signed URL. See Signed URLs for more information.
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.
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 |
# File 'lib/google/cloud/storage/project.rb', line 813 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 |
#universe_domain ⇒ String
The universe domain the client is connected to
70 71 72 |
# File 'lib/google/cloud/storage/project.rb', line 70 def universe_domain service.universe_domain end |