@@ -761,30 +761,50 @@ def customer_managed_encryption_enforcement_config= new_customer_managed_encrypt
761761 patch_gapi! :encryption
762762 end
763763
764- # Updates the bucket's encryption enforcement configuration.
765- #
766- # This method applies a patch to the bucket's encryption settings using the
767- # provided configuration.
768- #
769- # @param incoming_config [Hash, Google::Apis::StorageV1::Bucket::Encryption]
770- # The encryption configuration to apply. If a Hash is provided, it should
771- # contain keys corresponding to the encryption enforcement types.
772- #
773- # @example Updating to Google-Managed Encryption
774- # storage = Google::Cloud::Storage.new
775- # bucket = storage.bucket "my-bucket"
776- #
777- # new_config = {
778- # google_managed_encryption_enforcement_config: { restriction_mode: "NotRestricted" }
779- # }
780- #
781- # bucket.update_bucket_encryption_enforcement_config new_config
782- #
783- # @return [void]
784- # @raise [Google::Cloud::Error] If the API request fails (e.g., insufficient permissions).
785- def update_bucket_encryption_enforcement_config incoming_config
786- patch_gapi! :encryption , bucket_encryption_config : incoming_config
787- end
764+ # Updates the bucket's encryption enforcement configuration.
765+ #
766+ # This method applies a patch to the bucket's encryption settings using the
767+ # provided configuration.
768+ #
769+ # @param incoming_config [Hash, Google::Apis::StorageV1::Bucket::Encryption]
770+ # The encryption configuration to apply. If a Hash is provided, it should
771+ # contain keys corresponding to the encryption enforcement types.
772+ #
773+ # @example Updating to Google-Managed Encryption
774+ # storage = Google::Cloud::Storage.new
775+ # bucket = storage.bucket "my-bucket"
776+ #
777+ # new_config = {
778+ # google_managed_encryption_enforcement_config: { restriction_mode: "NotRestricted" }
779+ # }
780+ #
781+ # bucket.update_bucket_encryption_enforcement_config new_config
782+ #
783+ # @return [void]
784+ # @raise [Google::Cloud::Error] If the API request fails (e.g., insufficient permissions).
785+ def update_bucket_encryption_enforcement_config incoming_config
786+ allowed_keys = [
787+ :google_managed_encryption_enforcement_config ,
788+ :customer_managed_encryption_enforcement_config ,
789+ :customer_supplied_encryption_enforcement_config
790+ ]
791+ # binding.pry
792+ if incoming_config . is_a? Hash
793+ input_keys = incoming_config . keys
794+
795+ raise ArgumentError , "Config cannot be empty" if input_keys . empty?
796+
797+ extra_keys = input_keys - allowed_keys
798+ unless extra_keys . empty?
799+ raise ArgumentError , "Invalid config detected: #{ extra_keys . join ( ', ' ) } . " \
800+ "Only #{ allowed_keys . join ( ', ' ) } are allowed."
801+ end
802+ else
803+ raise ArgumentError , "incoming_config must be a Hash"
804+ end
805+
806+ patch_gapi! :encryption , bucket_encryption_config : incoming_config
807+ end
788808
789809 ##
790810 # The bucket's encryption configuration for customer-supplied encryption keys.
0 commit comments