Class: Google::Cloud::Storage::Bucket
- Inherits:
-
Object
- Object
- Google::Cloud::Storage::Bucket
- Defined in:
- lib/google/cloud/storage/bucket.rb,
lib/google/cloud/storage/bucket/acl.rb,
lib/google/cloud/storage/bucket/cors.rb,
lib/google/cloud/storage/bucket/list.rb
Overview
Bucket
Represents a Storage bucket. Belongs to a Project and has many Files.
Direct Known Subclasses
Defined Under Namespace
Classes: Acl, Cors, DefaultAcl, List, Updater
Instance Attribute Summary collapse
-
#user_project ⇒ Object
A boolean value or a project ID string to indicate the project to be billed for operations on the bucket and its files.
Instance Method Summary collapse
-
#acl ⇒ Object
The Bucket::Acl instance used to control access to the bucket.
-
#api_url ⇒ Object
A URL that can be used to access the bucket using the REST API.
-
#compose(sources, destination, acl: nil, encryption_key: nil) {|file| ... } ⇒ Google::Cloud::Storage::File
(also: #compose_file, #combine)
Concatenates a list of existing files in the bucket into a new file in the bucket.
-
#cors {|cors| ... } ⇒ Object
Returns the current CORS configuration for a static website served from the bucket.
-
#create_file(file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil) ⇒ Google::Cloud::Storage::File
(also: #upload_file, #new_file)
Creates a new File object by providing a path to a local file (or any File-like object such as StringIO) to upload, along with the path at which to store it in the bucket.
-
#create_notification(topic, custom_attrs: nil, event_types: nil, prefix: nil, payload: nil) ⇒ Google::Cloud::Storage::Notification
(also: #new_notification)
Creates a new Pub/Sub notification subscription for the bucket.
-
#created_at ⇒ Object
Creation time of the bucket.
-
#default_acl ⇒ Object
The Bucket::DefaultAcl instance used to control access to the bucket's files.
-
#default_kms_key ⇒ String?
The Cloud KMS encryption key that will be used to protect files.
-
#default_kms_key=(new_default_kms_key) ⇒ Object
Set the Cloud KMS encryption key that will be used to protect files.
-
#delete ⇒ Boolean
Permanently deletes the bucket.
-
#exists? ⇒ Boolean
Determines whether the bucket exists in the Storage service.
-
#file(path, generation: nil, skip_lookup: nil, encryption_key: nil) ⇒ Google::Cloud::Storage::File?
(also: #find_file)
Retrieves a file matching the path.
-
#files(prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil) ⇒ Array<Google::Cloud::Storage::File>
(also: #find_files)
Retrieves a list of files matching the criteria.
-
#id ⇒ Object
The ID of the bucket.
-
#kind ⇒ Object
The kind of item this is.
-
#labels ⇒ Object
A hash of user-provided labels.
-
#labels=(labels) ⇒ Object
Updates the hash of user-provided labels.
-
#location ⇒ Object
The location of the bucket.
-
#logging_bucket ⇒ Object
The destination bucket name for the bucket's logs.
-
#logging_bucket=(logging_bucket) ⇒ Object
Updates the destination bucket for the bucket's logs.
-
#logging_prefix ⇒ Object
The logging object prefix for the bucket's logs.
-
#logging_prefix=(logging_prefix) ⇒ Object
Updates the logging object prefix.
-
#name ⇒ Object
The name of the bucket.
-
#notification(id) ⇒ Google::Cloud::Storage::Notification?
(also: #find_notification)
Retrieves a Pub/Sub notification subscription for the bucket.
-
#notifications ⇒ Array<Google::Cloud::Storage::Notification>
(also: #find_notifications)
Retrieves the entire list of Pub/Sub notification subscriptions for the bucket.
-
#policy(force: nil) {|policy| ... } ⇒ Policy
Gets and updates the Cloud IAM access control policy for this bucket.
-
#post_object(path, policy: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil) ⇒ PostObject
Generate a PostObject that includes the fields and url to upload objects via html forms.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the bucket with current data from the Storage service.
-
#requester_pays ⇒ Boolean?
(also: #requester_pays?)
Indicates that a client accessing the bucket or a file it contains must assume the transit costs related to the access.
-
#requester_pays=(new_requester_pays) ⇒ Object
Enables requester pays for the bucket.
-
#signed_url(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.
-
#storage_class ⇒ Object
The bucket's storage class.
-
#storage_class=(new_storage_class) ⇒ Object
Updates the bucket's storage class.
-
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
-
#update {|bucket| ... } ⇒ Object
Updates the bucket with changes made in the given block in a single PATCH request.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for this bucket.
-
#versioning=(new_versioning) ⇒ Boolean
Updates whether Object Versioning is enabled for the bucket.
-
#versioning? ⇒ Boolean
Whether Object Versioning is enabled for the bucket.
-
#website_404 ⇒ Object
The page returned from a static website served from the bucket when a site visitor requests a resource that does not exist.
-
#website_404=(website_404) ⇒ Object
Updates the page returned from a static website served from the bucket when a site visitor requests a resource that does not exist.
-
#website_main ⇒ Object
The index page returned from a static website served from the bucket when a site visitor requests the top level directory.
-
#website_main=(website_main) ⇒ Object
Updates the index page returned from a static website served from the bucket when a site visitor requests the top level directory.
Instance Attribute Details
#user_project ⇒ Object
A boolean value or a project ID string to indicate the project to
be billed for operations on the bucket and its files. If this
attribute is set to true
, transit costs for operations on the bucket
will be billed to the current project for this client. (See
Project#project for the ID of the current project.) If this
attribute is set to a project ID, and that project is authorized for
the currently authenticated service account, transit costs will be
billed to that project. This attribute is required with requester
pays-enabled buckets. The default is nil
.
In general, this attribute should be set when first retrieving the
bucket by providing the user_project
option to Project#bucket.
See also #requester_pays= and #requester_pays.
76 77 78 |
# File 'lib/google/cloud/storage/bucket.rb', line 76 def user_project @user_project end |
Instance Method Details
#acl ⇒ Object
The Bucket::Acl instance used to control access to the bucket.
A bucket has owners, writers, and readers. Permissions can be granted to an individual user's email address, a group's email address, as well as many predefined lists.
1177 1178 1179 |
# File 'lib/google/cloud/storage/bucket.rb', line 1177 def acl @acl ||= Bucket::Acl.new self end |
#api_url ⇒ Object
A URL that can be used to access the bucket using the REST API.
107 108 109 |
# File 'lib/google/cloud/storage/bucket.rb', line 107 def api_url @gapi.self_link end |
#compose(sources, destination, acl: nil, encryption_key: nil) {|file| ... } ⇒ Google::Cloud::Storage::File Also known as: compose_file, combine
Concatenates a list of existing files in the bucket into a new file in the bucket. There is a limit (currently 32) to the number of files that can be composed in a single operation.
To compose files encrypted with a customer-supplied encryption key,
use the encryption_key
option. All source files must have been
encrypted with the same key, and the resulting destination file will
also be encrypted with the same key.
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/google/cloud/storage/bucket.rb', line 899 def compose sources, destination, acl: nil, encryption_key: nil ensure_service! sources = Array sources if sources.size < 2 raise ArgumentError, "must provide at least two source files" end = { acl: File::Acl.predefined_rule_for(acl), key: encryption_key, user_project: user_project } destination_gapi = nil if block_given? destination_gapi = Google::Apis::StorageV1::Object.new updater = File::Updater.new destination_gapi yield updater updater. end gapi = service.compose_file name, sources, destination, destination_gapi, File.from_gapi gapi, service, user_project: user_project end |
#cors {|cors| ... } ⇒ Object
Returns the current CORS configuration for a static website served from the bucket.
The return value is a frozen (unmodifiable) array of hashes containing the attributes specified for the Bucket resource field cors.
This method also accepts a block for updating the bucket's CORS rules. See Cors for details.
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/google/cloud/storage/bucket.rb', line 162 def cors cors_builder = Bucket::Cors.from_gapi @gapi.cors_configurations if block_given? yield cors_builder if cors_builder.changed? @gapi.cors_configurations = cors_builder.to_gapi patch_gapi! :cors_configurations end end cors_builder.freeze # always return frozen objects end |
#create_file(file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil) ⇒ Google::Cloud::Storage::File Also known as: upload_file, new_file
Creates a new File object by providing a path to a local file (or any File-like object such as StringIO) to upload, along with the path at which to store it in the bucket.
Customer-supplied encryption keys
By default, Google Cloud Storage manages server-side encryption keys
on your behalf. However, a customer-supplied encryption key
can be provided with the encryption_key
option. If given, the same
key must be provided to subsequently download or copy the file. If you
use customer-supplied encryption keys, you must securely manage your
keys and ensure that they are not lost. Also, please note that file
metadata is not encrypted, with the exception of the CRC32C checksum
and MD5 hash. The names of files and buckets are also not encrypted,
and you can read or update the metadata of an encrypted file without
providing the encryption key.
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 |
# File 'lib/google/cloud/storage/bucket.rb', line 788 def create_file file, path = nil, acl: nil, cache_control: nil, content_disposition: nil, content_encoding: nil, content_language: nil, content_type: nil, crc32c: nil, md5: nil, metadata: nil, storage_class: nil, encryption_key: nil, kms_key: nil ensure_service! = { acl: File::Acl.predefined_rule_for(acl), md5: md5, cache_control: cache_control, content_type: content_type, content_disposition: content_disposition, crc32c: crc32c, content_encoding: content_encoding, metadata: , content_language: content_language, key: encryption_key, kms_key: kms_key, storage_class: storage_class_for(storage_class), user_project: user_project } ensure_io_or_file_exists! file path ||= file.path if file.respond_to? :path path ||= file if file.is_a? String raise ArgumentError, "must provide path" if path.nil? gapi = service.insert_file name, file, path, File.from_gapi gapi, service, user_project: user_project end |
#create_notification(topic, custom_attrs: nil, event_types: nil, prefix: nil, payload: nil) ⇒ Google::Cloud::Storage::Notification Also known as: new_notification
Creates a new Pub/Sub notification subscription for the bucket.
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 |
# File 'lib/google/cloud/storage/bucket.rb', line 1479 def create_notification topic, custom_attrs: nil, event_types: nil, prefix: nil, payload: nil ensure_service! = { custom_attrs: custom_attrs, event_types: event_types, prefix: prefix, payload: payload, user_project: user_project } gapi = service.insert_notification name, topic, Notification.from_gapi name, gapi, service, user_project: user_project end |
#created_at ⇒ Object
Creation time of the bucket.
113 114 115 |
# File 'lib/google/cloud/storage/bucket.rb', line 113 def created_at @gapi.time_created end |
#default_acl ⇒ Object
The Bucket::DefaultAcl instance used to control access to the bucket's files.
A bucket's files have owners, writers, and readers. Permissions can be granted to an individual user's email address, a group's email address, as well as many predefined lists.
1221 1222 1223 |
# File 'lib/google/cloud/storage/bucket.rb', line 1221 def default_acl @default_acl ||= Bucket::DefaultAcl.new self end |
#default_kms_key ⇒ String?
The Cloud KMS encryption key that will be used to protect files.
For example: projects/a/locations/b/keyRings/c/cryptoKeys/d
401 402 403 |
# File 'lib/google/cloud/storage/bucket.rb', line 401 def default_kms_key @gapi.encryption && @gapi.encryption.default_kms_key_name end |
#default_kms_key=(new_default_kms_key) ⇒ Object
Set the Cloud KMS encryption key that will be used to protect files.
For example: projects/a/locations/b/keyRings/c/cryptoKeys/d
423 424 425 426 427 |
# File 'lib/google/cloud/storage/bucket.rb', line 423 def default_kms_key= new_default_kms_key @gapi.encryption = Google::Apis::StorageV1::Bucket::Encryption.new \ default_kms_key_name: new_default_kms_key patch_gapi! :encryption end |
#delete ⇒ Boolean
Permanently deletes the bucket. The bucket must be empty before it can be deleted.
The API call to delete the bucket may be retried under certain conditions. See Google::Cloud#storage to control this behavior.
496 497 498 499 500 |
# File 'lib/google/cloud/storage/bucket.rb', line 496 def delete ensure_service! service.delete_bucket name, user_project: user_project true end |
#exists? ⇒ Boolean
Determines whether the bucket exists in the Storage service.
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 |
# File 'lib/google/cloud/storage/bucket.rb', line 1504 def exists? # Always true if we have a grpc object return true unless lazy? # If we have a value, return it return @exists unless @exists.nil? ensure_gapi! @exists = true rescue Google::Cloud::NotFoundError @exists = false end |
#file(path, generation: nil, skip_lookup: nil, encryption_key: nil) ⇒ Google::Cloud::Storage::File? Also known as: find_file
Retrieves a file matching the path.
If a customer-supplied encryption
key
was used with #create_file, the encryption_key
option must be
provided or else the file's CRC32C checksum and MD5 hash will not be
returned.
594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/google/cloud/storage/bucket.rb', line 594 def file path, generation: nil, skip_lookup: nil, encryption_key: nil ensure_service! if skip_lookup return File.new_lazy name, path, service, generation: generation, user_project: user_project end gapi = service.get_file name, path, generation: generation, key: encryption_key, user_project: user_project File.from_gapi gapi, service, user_project: user_project rescue Google::Cloud::NotFoundError nil end |
#files(prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil) ⇒ Array<Google::Cloud::Storage::File> Also known as: find_files
Retrieves a list of files matching the criteria.
549 550 551 552 553 554 555 556 557 558 |
# File 'lib/google/cloud/storage/bucket.rb', line 549 def files prefix: nil, delimiter: nil, token: nil, max: nil, versions: nil ensure_service! gapi = service.list_files name, prefix: prefix, delimiter: delimiter, token: token, max: max, versions: versions, user_project: user_project File::List.from_gapi gapi, service, name, prefix, delimiter, max, versions, user_project: user_project end |
#id ⇒ Object
The ID of the bucket.
95 96 97 |
# File 'lib/google/cloud/storage/bucket.rb', line 95 def id @gapi.id end |
#kind ⇒ Object
The kind of item this is.
For buckets, this is always storage#bucket
.
89 90 91 |
# File 'lib/google/cloud/storage/bucket.rb', line 89 def kind @gapi.kind end |
#labels ⇒ Object
A hash of user-provided labels. The hash is frozen and changes are not allowed.
313 314 315 316 317 |
# File 'lib/google/cloud/storage/bucket.rb', line 313 def labels m = @gapi.labels m = m.to_h if m.respond_to? :to_h m.dup.freeze end |
#labels=(labels) ⇒ Object
Updates the hash of user-provided labels.
321 322 323 324 |
# File 'lib/google/cloud/storage/bucket.rb', line 321 def labels= labels @gapi.labels = labels patch_gapi! :labels end |
#location ⇒ Object
The location of the bucket. Object data for objects in the bucket resides in physical storage within this region. Defaults to US. See the developer's guide for the authoritative list.
181 182 183 |
# File 'lib/google/cloud/storage/bucket.rb', line 181 def location @gapi.location end |
#logging_bucket ⇒ Object
The destination bucket name for the bucket's logs.
190 191 192 |
# File 'lib/google/cloud/storage/bucket.rb', line 190 def logging_bucket @gapi.logging.log_bucket if @gapi.logging end |
#logging_bucket=(logging_bucket) ⇒ Object
Updates the destination bucket for the bucket's logs.
201 202 203 204 205 |
# File 'lib/google/cloud/storage/bucket.rb', line 201 def logging_bucket= logging_bucket @gapi.logging ||= Google::Apis::StorageV1::Bucket::Logging.new @gapi.logging.log_bucket = logging_bucket patch_gapi! :logging end |
#logging_prefix ⇒ Object
The logging object prefix for the bucket's logs. For more information,
212 213 214 |
# File 'lib/google/cloud/storage/bucket.rb', line 212 def logging_prefix @gapi.logging.log_object_prefix if @gapi.logging end |
#logging_prefix=(logging_prefix) ⇒ Object
Updates the logging object prefix. This prefix will be used to create log object names for the bucket. It can be at most 900 characters and must be a valid object name. By default, the object prefix is the name of the bucket for which the logs are enabled.
226 227 228 229 230 |
# File 'lib/google/cloud/storage/bucket.rb', line 226 def logging_prefix= logging_prefix @gapi.logging ||= Google::Apis::StorageV1::Bucket::Logging.new @gapi.logging.log_object_prefix = logging_prefix patch_gapi! :logging end |
#name ⇒ Object
The name of the bucket.
101 102 103 |
# File 'lib/google/cloud/storage/bucket.rb', line 101 def name @gapi.name end |
#notification(id) ⇒ Google::Cloud::Storage::Notification? Also known as: find_notification
Retrieves a Pub/Sub notification subscription for the bucket.
1401 1402 1403 1404 1405 1406 1407 |
# File 'lib/google/cloud/storage/bucket.rb', line 1401 def notification id ensure_service! gapi = service.get_notification name, id, user_project: user_project Notification.from_gapi name, gapi, service, user_project: user_project rescue Google::Cloud::NotFoundError nil end |
#notifications ⇒ Array<Google::Cloud::Storage::Notification> Also known as: find_notifications
Retrieves the entire list of Pub/Sub notification subscriptions for the bucket.
1370 1371 1372 1373 1374 1375 1376 1377 |
# File 'lib/google/cloud/storage/bucket.rb', line 1370 def notifications ensure_service! gapi = service.list_notifications name, user_project: user_project Array(gapi.items).map do |gapi_object| Notification.from_gapi name, gapi_object, service, user_project: user_project end end |
#policy(force: nil) {|policy| ... } ⇒ Policy
Gets and updates the Cloud IAM access control policy for this bucket.
1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/google/cloud/storage/bucket.rb', line 1266 def policy force: nil warn "DEPRECATED: 'force' in Bucket#policy" unless force.nil? ensure_service! gapi = service.get_bucket_policy name, user_project: user_project policy = Policy.from_gapi gapi return policy unless block_given? yield policy update_policy policy end |
#post_object(path, policy: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil) ⇒ PostObject
Generate a PostObject that includes the fields and url to upload objects via html forms.
Generating a PostObject 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 post_object
.
A SignedUrlUnavailable is raised if the service account credentials are missing. Service account credentials are acquired by following the steps in Service Account Authentication.
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
# File 'lib/google/cloud/storage/bucket.rb', line 1127 def post_object path, policy: nil, issuer: nil, client_email: nil, signing_key: nil, private_key: nil ensure_service! signer = File::Signer.from_bucket self, path signer.post_object issuer: issuer, client_email: client_email, signing_key: signing_key, private_key: private_key, policy: policy end |
#reload! ⇒ Object Also known as: refresh!
Reloads the bucket with current data from the Storage service.
1493 1494 1495 1496 1497 1498 1499 |
# File 'lib/google/cloud/storage/bucket.rb', line 1493 def reload! ensure_service! @gapi = service.get_bucket name, user_project: user_project # If NotFound then lazy will never be unset @lazy = nil self end |
#requester_pays ⇒ Boolean? Also known as: requester_pays?
Indicates that a client accessing the bucket or a file it contains
must assume the transit costs related to the access. The requester
must pass the user_project
option to Project#bucket and
Project#buckets to indicate the project to which the access costs
should be billed.
349 350 351 |
# File 'lib/google/cloud/storage/bucket.rb', line 349 def requester_pays @gapi.billing.requester_pays if @gapi.billing end |
#requester_pays=(new_requester_pays) ⇒ Object
Enables requester pays for the bucket. If enabled, a client accessing
the bucket or a file it contains must assume the transit costs related
to the access. The requester must pass the user_project
option to
Project#bucket and Project#buckets to indicate the project to
which the access costs should be billed.
375 376 377 378 379 |
# File 'lib/google/cloud/storage/bucket.rb', line 375 def requester_pays= new_requester_pays @gapi.billing ||= Google::Apis::StorageV1::Bucket::Billing.new @gapi.billing.requester_pays = new_requester_pays patch_gapi! :billing end |
#signed_url(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.
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
# File 'lib/google/cloud/storage/bucket.rb', line 1017 def signed_url 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 ensure_service! signer = File::Signer.from_bucket self, path 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 |
#storage_class ⇒ Object
The bucket's storage class. This defines how objects in the bucket are
stored and determines the SLA and the cost of storage. Values include
MULTI_REGIONAL
, REGIONAL
, NEARLINE
, COLDLINE
, and
DURABLE_REDUCED_AVAILABILITY
.
237 238 239 |
# File 'lib/google/cloud/storage/bucket.rb', line 237 def storage_class @gapi.storage_class end |
#storage_class=(new_storage_class) ⇒ Object
Updates the bucket's storage class. This defines how objects in the
bucket are stored and determines the SLA and the cost of storage.
Accepted values include :multi_regional
, :regional
, :nearline
,
and :coldline
, as well as the equivalent strings returned by
#storage_class. For more information, see Storage
Classes.
249 250 251 252 |
# File 'lib/google/cloud/storage/bucket.rb', line 249 def storage_class= new_storage_class @gapi.storage_class = storage_class_for(new_storage_class) patch_gapi! :storage_class end |
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
1342 1343 1344 1345 1346 1347 1348 |
# File 'lib/google/cloud/storage/bucket.rb', line 1342 def * = Array().flatten ensure_service! gapi = service. name, , user_project: user_project gapi. end |
#update {|bucket| ... } ⇒ Object
Updates the bucket with changes made in the given block in a single PATCH request. The following attributes may be set: #cors, #logging_bucket=, #logging_prefix=, #versioning=, #website_main=, #website_404=, and #requester_pays=.
In addition, the #cors configuration accessible in the block is completely mutable and will be included in the request. (See Cors)
470 471 472 473 474 475 476 477 |
# File 'lib/google/cloud/storage/bucket.rb', line 470 def update updater = Updater.new @gapi yield updater # Add check for mutable cors updater.check_for_changed_labels! updater.check_for_mutable_cors! patch_gapi! updater.updates unless updater.updates.empty? end |
#update_policy(new_policy) ⇒ Policy Also known as: policy=
Updates the Cloud IAM access control
policy for this bucket. The policy should be read from #policy. See
Policy for an explanation of the
policy etag
property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
1308 1309 1310 1311 1312 1313 |
# File 'lib/google/cloud/storage/bucket.rb', line 1308 def update_policy new_policy ensure_service! gapi = service.set_bucket_policy name, new_policy.to_gapi, user_project: user_project Policy.from_gapi gapi end |
#versioning=(new_versioning) ⇒ Boolean
Updates whether Object Versioning is enabled for the bucket.
269 270 271 272 273 |
# File 'lib/google/cloud/storage/bucket.rb', line 269 def versioning= new_versioning @gapi.versioning ||= Google::Apis::StorageV1::Bucket::Versioning.new @gapi.versioning.enabled = new_versioning patch_gapi! :versioning end |
#versioning? ⇒ Boolean
Whether Object Versioning is enabled for the bucket.
258 259 260 |
# File 'lib/google/cloud/storage/bucket.rb', line 258 def versioning? @gapi.versioning.enabled? unless @gapi.versioning.nil? end |
#website_404 ⇒ Object
The page returned from a static website served from the bucket when a site visitor requests a resource that does not exist.
306 307 308 |
# File 'lib/google/cloud/storage/bucket.rb', line 306 def website_404 @gapi.website.not_found_page if @gapi.website end |
#website_404=(website_404) ⇒ Object
Updates the page returned from a static website served from the bucket when a site visitor requests a resource that does not exist.
333 334 335 336 337 |
# File 'lib/google/cloud/storage/bucket.rb', line 333 def website_404= website_404 @gapi.website ||= Google::Apis::StorageV1::Bucket::Website.new @gapi.website.not_found_page = website_404 patch_gapi! :website end |
#website_main ⇒ Object
The index page returned from a static website served from the bucket when a site visitor requests the top level directory.
282 283 284 |
# File 'lib/google/cloud/storage/bucket.rb', line 282 def website_main @gapi.website.main_page_suffix if @gapi.website end |
#website_main=(website_main) ⇒ Object
Updates the index page returned from a static website served from the bucket when a site visitor requests the top level directory.
293 294 295 296 297 |
# File 'lib/google/cloud/storage/bucket.rb', line 293 def website_main= website_main @gapi.website ||= Google::Apis::StorageV1::Bucket::Website.new @gapi.website.main_page_suffix = website_main patch_gapi! :website end |