@@ -771,62 +771,6 @@ def customer_managed_encryption_enforcement_config= new_customer_managed_encrypt
771771 patch_gapi! :encryption
772772 end
773773
774- # Updates the bucket's encryption enforcement configuration.
775- #
776- # This method applies a patch to the bucket's encryption settings using the
777- # provided configuration.
778- #
779- # @param incoming_config [Hash, Google::Apis::StorageV1::Bucket::Encryption]
780- # The encryption configuration to apply. If a Hash is provided, it should
781- # contain keys corresponding to the encryption enforcement types.
782- #
783- # @example Updating to Google-Managed Encryption
784- # storage = Google::Cloud::Storage.new
785- # bucket = storage.bucket "my-bucket"
786- #
787- # new_config = {
788- # google_managed_encryption_enforcement_config: { restriction_mode: "NotRestricted" }
789- # }
790- #
791- # bucket.update_bucket_encryption_enforcement_config new_config
792- #
793- # @example Passing a Request Object
794- # require "google/apis/storage_v1"
795- # config_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
796- # google_managed_encryption_enforcement_config: { restriction_mode: "NotRestricted" }
797- # )
798- # bucket.update_bucket_encryption_enforcement_config config_obj
799- # @raise [ArgumentError] If the config is empty, contains invalid keys, or is the wrong type.
800- def update_bucket_encryption_enforcement_config incoming_config
801- allowed_keys = [
802- :google_managed_encryption_enforcement_config ,
803- :customer_managed_encryption_enforcement_config ,
804- :customer_supplied_encryption_enforcement_config
805- ]
806-
807- if incoming_config . is_a? Hash
808- input_keys = incoming_config . keys
809- raise ArgumentError , "Config cannot be empty" if input_keys . empty?
810-
811- extra_keys = input_keys - allowed_keys
812- unless extra_keys . empty?
813- raise ArgumentError , "Invalid config detected: #{ extra_keys . join ( ', ' ) } . " \
814- "Only #{ allowed_keys . join ( ', ' ) } are allowed."
815- end
816-
817- elsif incoming_config . is_a? Google ::Apis ::StorageV1 ::Bucket ::Encryption
818- # For objects, ensure at least one of the allowed enforcement configs is present
819- has_any_config = allowed_keys . any? { |key | !incoming_config . send ( key ) . nil? }
820- binding . pry
821- raise ArgumentError , "Encryption request object must have at least one enforcement config set" unless has_any_config
822-
823- else
824- raise ArgumentError , "incoming_config must be a Hash or Google::Apis::StorageV1::Bucket::Encryption"
825- end
826-
827- patch_gapi! :encryption , bucket_encryption_config : incoming_config
828- end
829-
830774 ##
831775 # The bucket's encryption configuration for customer-supplied encryption keys.
832776 # For more information, see [Bucket encryption](https://docs.cloud.google.com/storage/docs/encryption/).
@@ -1595,6 +1539,7 @@ def update if_metageneration_match: nil, if_metageneration_not_match: nil
15951539 updater . check_for_changed_labels!
15961540 updater . check_for_mutable_cors!
15971541 updater . check_for_mutable_lifecycle!
1542+ updater . check_for_encryption_enforcement_config!
15981543 return if updater . updates . empty?
15991544 update_gapi! updater . updates ,
16001545 if_metageneration_match : if_metageneration_match ,
@@ -3474,18 +3419,13 @@ def ensure_gapi!
34743419
34753420 def patch_gapi! attributes ,
34763421 if_metageneration_match : nil ,
3477- if_metageneration_not_match : nil ,
3478- bucket_encryption_config : nil
3422+ if_metageneration_not_match : nil
34793423 attributes = Array ( attributes )
34803424 attributes . flatten!
34813425 return if attributes . empty?
34823426 ensure_service!
34833427 patch_args = attributes . to_h do |attr |
3484- if bucket_encryption_config
3485- [ attr , bucket_encryption_config ]
3486- else
3487- [ attr , @gapi . send ( attr ) ]
3488- end
3428+ [ attr , @gapi . send ( attr ) ]
34893429 end
34903430 patch_gapi = API ::Bucket . new ( **patch_args )
34913431 @gapi = service . patch_bucket name ,
@@ -3613,6 +3553,26 @@ def check_for_mutable_lifecycle!
36133553 patch_gapi! :lifecycle
36143554 end
36153555
3556+ def check_for_encryption_enforcement_config!
3557+ return unless @gapi . encryption
3558+
3559+ [
3560+ :google_managed_encryption_enforcement_config ,
3561+ :customer_managed_encryption_enforcement_config ,
3562+ :customer_supplied_encryption_enforcement_config
3563+ ] . each do |attr |
3564+ config = @gapi . encryption . send ( attr )
3565+ next unless config
3566+ unless config . respond_to? ( :to_h )
3567+ raise ArgumentError , "Encryption config for #{ attr } must be a Hash or valid Config object"
3568+ end
3569+ clean_config = config . to_h
3570+ clean_config . delete :effective_time
3571+ clean_config . delete "effective_time"
3572+ @gapi . encryption . send "#{ attr } =" , clean_config
3573+ end
3574+ end
3575+
36163576 protected
36173577
36183578 ##
0 commit comments