@@ -752,7 +752,19 @@ def customer_managed_encryption_enforcement_config
752752 # new_config = { restriction_mode: "FullyRestricted" }
753753 # bucket.customer_managed_encryption_enforcement_config = new_config
754754 #
755- # @return [Hash] The updated configuration hash.
755+ # @example Setting via Request Object (Google API Client)
756+ # require "google/apis/storage_v1"
757+ #
758+ # # Create the enforcement config sub-object
759+ # enforcement_config = { restriction_mode: "FullyRestricted" }
760+ #
761+ # # Initialize the parent Encryption request object
762+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
763+ # customer_managed_encryption_enforcement_config: enforcement_config
764+ # )
765+ # bucket.customer_managed_encryption_enforcement_config = request_obj
766+ #
767+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
756768 # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
757769 def customer_managed_encryption_enforcement_config = new_customer_managed_encryption_enforcement_config
758770 @gapi . encryption ||= API ::Bucket ::Encryption . new
@@ -780,31 +792,42 @@ def customer_managed_encryption_enforcement_config= new_customer_managed_encrypt
780792 #
781793 # bucket.update_bucket_encryption_enforcement_config new_config
782794 #
783- # @return [void]
784- # @raise [Google::Cloud::Error] If the API request fails (e.g., insufficient permissions).
795+ # @example Passing a Request Object
796+ # require "google/apis/storage_v1"
797+ # config_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
798+ # google_managed_encryption_enforcement_config: { restriction_mode: "NotRestricted" }
799+ # )
800+ # bucket.update_bucket_encryption_enforcement_config config_obj
801+ # @raise [ArgumentError] If the config is empty, contains invalid keys, or is the wrong type.
785802 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
803+ allowed_keys = [
804+ :google_managed_encryption_enforcement_config ,
805+ :customer_managed_encryption_enforcement_config ,
806+ :customer_supplied_encryption_enforcement_config
807+ ]
808+
809+ if incoming_config . is_a? Hash
810+ input_keys = incoming_config . keys
811+ raise ArgumentError , "Config cannot be empty" if input_keys . empty?
812+
813+ extra_keys = input_keys - allowed_keys
814+ unless extra_keys . empty?
815+ raise ArgumentError , "Invalid config detected: #{ extra_keys . join ( ', ' ) } . " \
816+ "Only #{ allowed_keys . join ( ', ' ) } are allowed."
817+ end
805818
806- patch_gapi! :encryption , bucket_encryption_config : incoming_config
807- end
819+ elsif incoming_config . is_a? Google ::Apis ::StorageV1 ::Bucket ::Encryption
820+ # For objects, ensure at least one of the allowed enforcement configs is present
821+ has_any_config = allowed_keys . any? { |key | !incoming_config . send ( key ) . nil? }
822+ binding . pry
823+ raise ArgumentError , "Encryption request object must have at least one enforcement config set" unless has_any_config
824+
825+ else
826+ raise ArgumentError , "incoming_config must be a Hash or Google::Apis::StorageV1::Bucket::Encryption"
827+ end
828+
829+ patch_gapi! :encryption , bucket_encryption_config : incoming_config
830+ end
808831
809832 ##
810833 # The bucket's encryption configuration for customer-supplied encryption keys.
@@ -838,7 +861,20 @@ def customer_supplied_encryption_enforcement_config
838861 # bucket = storage.bucket "my-bucket"
839862 # new_config = { restriction_mode: "FullyRestricted" }
840863 # bucket.customer_supplied_encryption_enforcement_config = new_config
841- # @return [Hash] The updated configuration hash.
864+ #
865+ # @example Setting via Request Object (Google API Client)
866+ # require "google/apis/storage_v1"
867+ #
868+ # # Create the enforcement config sub-object
869+ # enforcement_config = { restriction_mode: "FullyRestricted" }
870+ #
871+ # # Initialize the parent Encryption request object
872+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
873+ # customer_supplied_encryption_enforcement_config: enforcement_config
874+ # )
875+ # bucket.customer_supplied_encryption_enforcement_config = request_obj
876+ #
877+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
842878 # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
843879
844880 def customer_supplied_encryption_enforcement_config = new_customer_supplied_encryption_enforcement_config
@@ -887,7 +923,19 @@ def google_managed_encryption_enforcement_config
887923 # new_config = { restriction_mode: "FullyRestricted" }
888924 # bucket.new_google_managed_encryption_enforcement_config = new_config
889925 #
890- # @return [Hash] The updated configuration hash.
926+ # @example Setting via Request Object (Google API Client)
927+ # require "google/apis/storage_v1"
928+ #
929+ # # Create the enforcement config sub-object
930+ # enforcement_config = { restriction_mode: "FullyRestricted" }
931+ #
932+ # # Initialize the parent Encryption request object
933+ # request_obj = Google::Apis::StorageV1::Bucket::Encryption.new(
934+ # google_managed_encryption_enforcement_config: enforcement_config
935+ # )
936+ # bucket.google_managed_encryption_enforcement_config = request_obj
937+ #
938+ # @return [Hash, Google::Apis::StorageV1::Bucket::Encryption] The updated configuration.
891939 # @raise [Google::Cloud::Error] If the update fails due to permissions or invalid arguments.
892940
893941 def google_managed_encryption_enforcement_config = new_google_managed_encryption_enforcement_config
0 commit comments