@@ -716,6 +716,171 @@ def default_kms_key= new_default_kms_key
716716 default_kms_key_name : new_default_kms_key
717717 patch_gapi! :encryption
718718 end
719+ ##
720+ # The bucket's encryption configuration for customer-managed encryption keys.
721+ # This configuration defines the
722+ # default encryption behavior for the bucket and its files, and it can be used to enforce encryption requirements for the bucket.
723+ # For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption/).
724+ # @return [Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig, nil] The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
725+ # @example
726+ # require "google/cloud/storage"
727+ # #
728+ # storage = Google::Cloud::Storage.new
729+ # bucket = storage.bucket "my-bucket"
730+ # bucket.customer_managed_encryption_enforcement_config
731+ # ==> #<Google::Apis::StorageV1::Bucket::Encryption::CustomerManagedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
732+ # The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted"
733+
734+ def customer_managed_encryption_enforcement_config
735+ @gapi . encryption &.customer_managed_encryption_enforcement_config
736+ end
737+ ##
738+ # Sets the customer-managed encryption enforcement configuration for the bucket.
739+ #
740+ # @param new_customer_managed_encryption_enforcement_config [Hash, nil]
741+ # The configuration hash for encryption enforcement.
742+ # * `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted".
743+ # Pass `nil` to clear the current configuration.
744+ #
745+ # @example Enforcing Customer-Managed Encryption
746+ # require "google/cloud/storage"
747+ #
748+ # storage = Google::Cloud::Storage.new
749+ # bucket = storage.bucket "my-bucket"
750+ #
751+ # # Set restriction mode to FullyRestricted
752+ # restricted_config = { restriction_mode: "FullyRestricted" }
753+ # bucket.customer_managed_encryption_enforcement_config = restricted_config
754+ #
755+ # @example Setting via Request Object (Google API Client)
756+ # require "google/apis/storage_v1"
757+ #
758+ # enforcement_config = { restriction_mode: "FullyRestricted" }
759+ #
760+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
761+ # customer_managed_encryption_enforcement_config: enforcement_config
762+ # )
763+ # bucket.customer_managed_encryption_enforcement_config = request_obj
764+ #
765+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
766+ # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
767+ def customer_managed_encryption_enforcement_config = new_customer_managed_encryption_enforcement_config
768+ @gapi . encryption ||= API ::Bucket ::Encryption . new
769+ @gapi . encryption . customer_managed_encryption_enforcement_config =
770+ new_customer_managed_encryption_enforcement_config || { }
771+ patch_gapi! :encryption
772+ end
773+
774+ ##
775+ # The bucket's encryption configuration for customer-supplied encryption keys.
776+ # For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption/).
777+ # @return [Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig, nil]
778+ # The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
779+ # @example
780+ # require "google/cloud/storage"
781+ #
782+ # storage = Google::Cloud::Storage.new
783+ # bucket = storage.bucket "my-bucket"
784+ #
785+ # bucket.customer_supplied_encryption_enforcement_config
786+ # ==> #<Google::Apis::StorageV1::Bucket::Encryption::CustomerSuppliedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
787+ # The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted".
788+
789+ def customer_supplied_encryption_enforcement_config
790+ @gapi . encryption &.customer_supplied_encryption_enforcement_config
791+ end
792+
793+ ##
794+ # Sets the bucket's encryption configuration for customer-supplied encryption that will be used to protect files.
795+ # @param new_customer_supplied_encryption_enforcement_config [Hash, nil]
796+ # The configuration hash for encryption enforcement.
797+ # * `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted".
798+ # Pass `nil` to clear the current configuration.
799+ # @example
800+ # require "google/cloud/storage"
801+ #
802+ # storage = Google::Cloud::Storage.new
803+ # bucket = storage.bucket "my-bucket"
804+ # restricted_config = { restriction_mode: "FullyRestricted" }
805+ # bucket.customer_supplied_encryption_enforcement_config = restricted_config
806+ #
807+ # @example Setting via Request Object (Google API Client)
808+ # require "google/apis/storage_v1"
809+ #
810+ # enforcement_config = { restriction_mode: "FullyRestricted" }
811+ #
812+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
813+ # customer_supplied_encryption_enforcement_config: enforcement_config
814+ # )
815+ # bucket.customer_supplied_encryption_enforcement_config = request_obj
816+ #
817+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
818+ # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
819+
820+ def customer_supplied_encryption_enforcement_config = new_customer_supplied_encryption_enforcement_config
821+ @gapi . encryption ||= API ::Bucket ::Encryption . new
822+ @gapi . encryption . customer_supplied_encryption_enforcement_config =
823+ new_customer_supplied_encryption_enforcement_config || { }
824+ patch_gapi! :encryption
825+ end
826+
827+ ##
828+ # The bucket's encryption configuration for google-managed encryption keys.
829+ # This configuration defines the
830+ # default encryption behavior for the bucket and its files, and it can be used to enforce encryption
831+ # requirements for the bucket.
832+ # For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption/).
833+ # @return [Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig, nil]
834+ # The bucket's encryption configuration, or `nil` if no encryption configuration has been set.
835+ # @example
836+ # require "google/cloud/storage"
837+ #
838+ # storage = Google::Cloud::Storage.new
839+ # bucket = storage.bucket "my-bucket"
840+ # bucket.google_managed_encryption_enforcement_config
841+ # ==> #<Google::Apis::StorageV1::Bucket::Encryption::GoogleManagedEncryptionEnforcementConfig:0x00007f3b1c102e90 @restriction_mode="NotRestricted">
842+ # The value for `restriction_mode` can be either "NotRestricted" or "FullyRestricted".
843+
844+ def google_managed_encryption_enforcement_config
845+ @gapi . encryption &.google_managed_encryption_enforcement_config
846+ end
847+
848+ ##
849+ # Sets the google-managed encryption enforcement configuration for the bucket.
850+ #
851+ # @param new_google_managed_encryption_enforcement_config [Hash, nil]
852+ # The configuration hash for encryption enforcement.
853+ # * `:restriction_mode` (String) - Can be "NotRestricted" or "FullyRestricted".
854+ # Pass `nil` to clear the current configuration.
855+ #
856+ # @example Enforcing Customer-Managed Encryption
857+ # require "google/cloud/storage"
858+ #
859+ # storage = Google::Cloud::Storage.new
860+ # bucket = storage.bucket "my-bucket"
861+ # # Set restriction mode to FullyRestricted
862+ # restricted_config = { restriction_mode: "FullyRestricted" }
863+ # bucket.google_managed_encryption_enforcement_config = restricted_config
864+ #
865+ # @example Setting via Request Object (Google API Client)
866+ # require "google/apis/storage_v1"
867+ #
868+ # enforcement_config = { restriction_mode: "FullyRestricted" }
869+ #
870+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
871+ # google_managed_encryption_enforcement_config: enforcement_config
872+ # )
873+ # bucket.google_managed_encryption_enforcement_config = request_obj
874+ #
875+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
876+ # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
877+
878+ def google_managed_encryption_enforcement_config = new_google_managed_encryption_enforcement_config
879+ @gapi . encryption ||= API ::Bucket ::Encryption . new
880+ @gapi . encryption . google_managed_encryption_enforcement_config =
881+ new_google_managed_encryption_enforcement_config || { }
882+ patch_gapi! :encryption
883+ end
719884
720885 ##
721886 # The period of time (in seconds) that files in the bucket must be
@@ -1373,6 +1538,7 @@ def update if_metageneration_match: nil, if_metageneration_not_match: nil
13731538 updater . check_for_changed_labels!
13741539 updater . check_for_mutable_cors!
13751540 updater . check_for_mutable_lifecycle!
1541+ updater . check_for_encryption_enforcement_config!
13761542 return if updater . updates . empty?
13771543 update_gapi! updater . updates ,
13781544 if_metageneration_match : if_metageneration_match ,
@@ -3386,6 +3552,26 @@ def check_for_mutable_lifecycle!
33863552 patch_gapi! :lifecycle
33873553 end
33883554
3555+ def check_for_encryption_enforcement_config!
3556+ return unless @gapi . encryption
3557+
3558+ [
3559+ :google_managed_encryption_enforcement_config ,
3560+ :customer_managed_encryption_enforcement_config ,
3561+ :customer_supplied_encryption_enforcement_config
3562+ ] . each do |attr |
3563+ config = @gapi . encryption . send ( attr )
3564+ next unless config
3565+ unless config . respond_to? ( :to_h )
3566+ raise ArgumentError , "Encryption config for #{ attr } must be a Hash or valid Config object"
3567+ end
3568+ clean_config = config . to_h
3569+ clean_config . delete :effective_time
3570+ clean_config . delete "effective_time"
3571+ @gapi . encryption . send "#{ attr } =" , clean_config
3572+ end
3573+ end
3574+
33893575 protected
33903576
33913577 ##
0 commit comments