mongo 2.23.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/mongo_console +0 -1
- data/lib/mongo/active_support.rb +1 -2
- data/lib/mongo/address/ipv4.rb +3 -6
- data/lib/mongo/address/ipv6.rb +6 -10
- data/lib/mongo/address/unix.rb +1 -4
- data/lib/mongo/address/validator.rb +16 -28
- data/lib/mongo/address.rb +30 -40
- data/lib/mongo/auth/aws/conversation.rb +6 -10
- data/lib/mongo/auth/aws/credentials.rb +0 -1
- data/lib/mongo/auth/aws/credentials_cache.rb +0 -1
- data/lib/mongo/auth/aws/credentials_retriever.rb +45 -59
- data/lib/mongo/auth/aws/request.rb +20 -35
- data/lib/mongo/auth/aws.rb +1 -2
- data/lib/mongo/auth/base.rb +20 -29
- data/lib/mongo/auth/conversation_base.rb +14 -18
- data/lib/mongo/auth/cr/conversation.rb +0 -3
- data/lib/mongo/auth/cr.rb +1 -4
- data/lib/mongo/auth/credential_cache.rb +0 -2
- data/lib/mongo/auth/gssapi/conversation.rb +3 -8
- data/lib/mongo/auth/gssapi.rb +1 -4
- data/lib/mongo/auth/ldap/conversation.rb +0 -3
- data/lib/mongo/auth/ldap.rb +1 -4
- data/lib/mongo/auth/roles.rb +16 -19
- data/lib/mongo/auth/sasl_conversation_base.rb +7 -11
- data/lib/mongo/auth/scram/conversation.rb +2 -5
- data/lib/mongo/auth/scram.rb +5 -10
- data/lib/mongo/auth/scram256/conversation.rb +2 -5
- data/lib/mongo/auth/scram256.rb +1 -3
- data/lib/mongo/auth/scram_conversation_base.rb +18 -24
- data/lib/mongo/auth/stringprep/profiles/sasl.rb +17 -18
- data/lib/mongo/auth/stringprep/tables.rb +2209 -2210
- data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +36 -38
- data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1142 -1150
- data/lib/mongo/auth/stringprep.rb +9 -12
- data/lib/mongo/auth/user/view.rb +3 -5
- data/lib/mongo/auth/user.rb +14 -24
- data/lib/mongo/auth/x509/conversation.rb +0 -3
- data/lib/mongo/auth/x509.rb +7 -9
- data/lib/mongo/auth.rb +18 -30
- data/lib/mongo/background_thread.rb +9 -17
- data/lib/mongo/bson.rb +0 -2
- data/lib/mongo/bulk_write/combineable.rb +0 -3
- data/lib/mongo/bulk_write/ordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/result.rb +11 -16
- data/lib/mongo/bulk_write/result_combiner.rb +9 -12
- data/lib/mongo/bulk_write/transformable.rb +16 -19
- data/lib/mongo/bulk_write/unordered_combiner.rb +1 -3
- data/lib/mongo/bulk_write/validatable.rb +11 -18
- data/lib/mongo/bulk_write.rb +76 -91
- data/lib/mongo/caching_cursor.rb +2 -7
- data/lib/mongo/client.rb +230 -275
- data/lib/mongo/client_encryption.rb +4 -5
- data/lib/mongo/cluster/periodic_executor.rb +2 -5
- data/lib/mongo/cluster/reapers/cursor_reaper.rb +21 -29
- data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -6
- data/lib/mongo/cluster/sdam_flow.rb +136 -159
- data/lib/mongo/cluster/topology/base.rb +15 -18
- data/lib/mongo/cluster/topology/load_balanced.rb +24 -14
- data/lib/mongo/cluster/topology/no_replica_set_options.rb +3 -6
- data/lib/mongo/cluster/topology/replica_set_no_primary.rb +20 -23
- data/lib/mongo/cluster/topology/replica_set_with_primary.rb +0 -2
- data/lib/mongo/cluster/topology/sharded.rb +19 -9
- data/lib/mongo/cluster/topology/single.rb +24 -14
- data/lib/mongo/cluster/topology/unknown.rb +20 -10
- data/lib/mongo/cluster/topology.rb +29 -25
- data/lib/mongo/cluster.rb +148 -183
- data/lib/mongo/cluster_time.rb +14 -31
- data/lib/mongo/collection/helpers.rb +5 -8
- data/lib/mongo/collection/view/aggregation.rb +5 -10
- data/lib/mongo/collection/view/builder/aggregation.rb +6 -9
- data/lib/mongo/collection/view/builder/map_reduce.rb +18 -17
- data/lib/mongo/collection/view/builder.rb +0 -1
- data/lib/mongo/collection/view/change_stream/retryable.rb +3 -8
- data/lib/mongo/collection/view/change_stream.rb +59 -58
- data/lib/mongo/collection/view/explainable.rb +11 -20
- data/lib/mongo/collection/view/immutable.rb +1 -3
- data/lib/mongo/collection/view/iterable.rb +35 -28
- data/lib/mongo/collection/view/map_reduce.rb +20 -25
- data/lib/mongo/collection/view/readable.rb +50 -57
- data/lib/mongo/collection/view/writable.rb +56 -72
- data/lib/mongo/collection/view.rb +9 -8
- data/lib/mongo/collection.rb +63 -76
- data/lib/mongo/condition_variable.rb +4 -4
- data/lib/mongo/config/options.rb +0 -3
- data/lib/mongo/config/validators/option.rb +3 -5
- data/lib/mongo/config.rb +2 -4
- data/lib/mongo/crypt/auto_decryption_context.rb +0 -3
- data/lib/mongo/crypt/auto_encrypter.rb +34 -43
- data/lib/mongo/crypt/auto_encryption_context.rb +0 -3
- data/lib/mongo/crypt/binary.rb +5 -9
- data/lib/mongo/crypt/binding.rb +149 -155
- data/lib/mongo/crypt/context.rb +10 -17
- data/lib/mongo/crypt/data_key_context.rb +2 -7
- data/lib/mongo/crypt/encryption_io.rb +29 -39
- data/lib/mongo/crypt/explicit_decryption_context.rb +0 -3
- data/lib/mongo/crypt/explicit_encrypter.rb +1 -1
- data/lib/mongo/crypt/explicit_encryption_context.rb +19 -30
- data/lib/mongo/crypt/explicit_encryption_expression_context.rb +0 -2
- data/lib/mongo/crypt/handle.rb +42 -48
- data/lib/mongo/crypt/hooks.rb +12 -15
- data/lib/mongo/crypt/kms/aws/credentials.rb +12 -16
- data/lib/mongo/crypt/kms/aws/master_document.rb +6 -9
- data/lib/mongo/crypt/kms/aws.rb +0 -2
- data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +2 -7
- data/lib/mongo/crypt/kms/azure/master_document.rb +15 -19
- data/lib/mongo/crypt/kms/azure.rb +0 -1
- data/lib/mongo/crypt/kms/credentials.rb +13 -27
- data/lib/mongo/crypt/kms/gcp/credentials.rb +12 -14
- data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +7 -9
- data/lib/mongo/crypt/kms/gcp/master_document.rb +12 -16
- data/lib/mongo/crypt/kms/gcp.rb +0 -2
- data/lib/mongo/crypt/kms/kmip/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/kmip/master_document.rb +3 -5
- data/lib/mongo/crypt/kms/kmip.rb +0 -1
- data/lib/mongo/crypt/kms/local/credentials.rb +7 -8
- data/lib/mongo/crypt/kms/local/master_document.rb +2 -6
- data/lib/mongo/crypt/kms/local.rb +0 -1
- data/lib/mongo/crypt/kms/master_key_document.rb +11 -15
- data/lib/mongo/crypt/kms.rb +14 -16
- data/lib/mongo/crypt/kms_context.rb +0 -2
- data/lib/mongo/crypt/rewrap_many_data_key_context.rb +2 -7
- data/lib/mongo/crypt/rewrap_many_data_key_result.rb +2 -4
- data/lib/mongo/crypt/status.rb +12 -14
- data/lib/mongo/crypt.rb +0 -1
- data/lib/mongo/csot_timeout_holder.rb +3 -2
- data/lib/mongo/cursor/kill_spec.rb +7 -10
- data/lib/mongo/cursor.rb +74 -64
- data/lib/mongo/cursor_host.rb +8 -10
- data/lib/mongo/database/view.rb +16 -37
- data/lib/mongo/database.rb +52 -56
- data/lib/mongo/dbref.rb +0 -1
- data/lib/mongo/distinguishing_semaphore.rb +0 -1
- data/lib/mongo/error/auth_error.rb +0 -2
- data/lib/mongo/error/bad_load_balancer_target.rb +0 -2
- data/lib/mongo/error/bulk_write_error.rb +7 -10
- data/lib/mongo/error/change_stream_resumable.rb +0 -2
- data/lib/mongo/error/client_closed.rb +0 -2
- data/lib/mongo/error/closed_stream.rb +1 -4
- data/lib/mongo/error/connection_check_out_timeout.rb +3 -6
- data/lib/mongo/error/connection_perished.rb +0 -2
- data/lib/mongo/error/connection_unavailable.rb +0 -2
- data/lib/mongo/error/credential_check_error.rb +0 -2
- data/lib/mongo/error/crypt_error.rb +0 -2
- data/lib/mongo/error/extra_file_chunk.rb +1 -4
- data/lib/mongo/error/failed_string_prep_validation.rb +5 -6
- data/lib/mongo/error/file_not_found.rb +0 -3
- data/lib/mongo/error/handshake_error.rb +0 -2
- data/lib/mongo/error/insufficient_iteration_count.rb +1 -4
- data/lib/mongo/error/internal_driver_error.rb +0 -2
- data/lib/mongo/error/invalid_address.rb +0 -2
- data/lib/mongo/error/invalid_application_name.rb +0 -3
- data/lib/mongo/error/invalid_bulk_operation.rb +1 -4
- data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -4
- data/lib/mongo/error/invalid_collection_name.rb +1 -4
- data/lib/mongo/error/invalid_config_option.rb +0 -3
- data/lib/mongo/error/invalid_cursor_operation.rb +0 -2
- data/lib/mongo/error/invalid_database_name.rb +1 -4
- data/lib/mongo/error/invalid_document.rb +1 -4
- data/lib/mongo/error/invalid_file.rb +0 -3
- data/lib/mongo/error/invalid_file_revision.rb +0 -3
- data/lib/mongo/error/invalid_min_pool_size.rb +0 -3
- data/lib/mongo/error/invalid_nonce.rb +0 -3
- data/lib/mongo/error/invalid_read_concern.rb +2 -4
- data/lib/mongo/error/invalid_read_option.rb +0 -3
- data/lib/mongo/error/invalid_replacement_document.rb +2 -5
- data/lib/mongo/error/invalid_server_auth_host.rb +0 -2
- data/lib/mongo/error/invalid_server_auth_response.rb +0 -2
- data/lib/mongo/error/invalid_server_preference.rb +7 -16
- data/lib/mongo/error/invalid_session.rb +1 -4
- data/lib/mongo/error/invalid_signature.rb +0 -3
- data/lib/mongo/error/invalid_transaction_operation.rb +5 -8
- data/lib/mongo/error/invalid_txt_record.rb +0 -2
- data/lib/mongo/error/invalid_update_document.rb +2 -5
- data/lib/mongo/error/invalid_uri.rb +1 -4
- data/lib/mongo/error/invalid_write_concern.rb +2 -5
- data/lib/mongo/error/kms_error.rb +0 -2
- data/lib/mongo/error/labelable.rb +0 -3
- data/lib/mongo/error/lint_error.rb +0 -2
- data/lib/mongo/error/max_bson_size.rb +8 -11
- data/lib/mongo/error/max_message_size.rb +2 -5
- data/lib/mongo/error/mismatched_domain.rb +0 -2
- data/lib/mongo/error/missing_connection.rb +0 -2
- data/lib/mongo/error/missing_file_chunk.rb +0 -3
- data/lib/mongo/error/missing_password.rb +0 -2
- data/lib/mongo/error/missing_resume_token.rb +1 -4
- data/lib/mongo/error/missing_scram_server_signature.rb +2 -4
- data/lib/mongo/error/missing_service_id.rb +0 -2
- data/lib/mongo/error/mongocryptd_spawn_error.rb +0 -2
- data/lib/mongo/error/multi_index_drop.rb +0 -3
- data/lib/mongo/error/need_primary_server.rb +0 -2
- data/lib/mongo/error/no_server_available.rb +3 -8
- data/lib/mongo/error/no_service_connection_available.rb +1 -3
- data/lib/mongo/error/no_srv_records.rb +0 -2
- data/lib/mongo/error/notable.rb +8 -16
- data/lib/mongo/error/operation_failure.rb +22 -35
- data/lib/mongo/error/parser.rb +33 -75
- data/lib/mongo/error/pool_cleared_error.rb +1 -3
- data/lib/mongo/error/pool_closed_error.rb +0 -3
- data/lib/mongo/error/pool_error.rb +0 -3
- data/lib/mongo/error/pool_paused_error.rb +0 -2
- data/lib/mongo/error/raise_original_error.rb +1 -3
- data/lib/mongo/error/read_write_retryable.rb +14 -17
- data/lib/mongo/error/sdam_error_detection.rb +3 -5
- data/lib/mongo/error/server_api_conflict.rb +0 -2
- data/lib/mongo/error/server_certificate_revoked.rb +0 -2
- data/lib/mongo/error/server_not_usable.rb +0 -2
- data/lib/mongo/error/session_ended.rb +1 -3
- data/lib/mongo/error/session_not_materialized.rb +1 -3
- data/lib/mongo/error/sessions_not_supported.rb +1 -4
- data/lib/mongo/error/snapshot_session_invalid_server_version.rb +1 -4
- data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +1 -4
- data/lib/mongo/error/socket_error.rb +0 -2
- data/lib/mongo/error/socket_timeout_error.rb +0 -2
- data/lib/mongo/error/transactions_not_supported.rb +3 -6
- data/lib/mongo/error/unchangeable_collection_option.rb +1 -4
- data/lib/mongo/error/unexpected_chunk_length.rb +0 -3
- data/lib/mongo/error/unexpected_response.rb +1 -4
- data/lib/mongo/error/unknown_payload_type.rb +0 -3
- data/lib/mongo/error/unmet_dependency.rb +0 -2
- data/lib/mongo/error/unsupported_array_filters.rb +3 -24
- data/lib/mongo/error/unsupported_collation.rb +3 -24
- data/lib/mongo/error/unsupported_features.rb +0 -2
- data/lib/mongo/error/unsupported_message_type.rb +0 -2
- data/lib/mongo/error/unsupported_option.rb +19 -21
- data/lib/mongo/error/write_retryable.rb +0 -2
- data/lib/mongo/error.rb +10 -24
- data/lib/mongo/event/base.rb +0 -2
- data/lib/mongo/event/listeners.rb +0 -3
- data/lib/mongo/event/publisher.rb +0 -3
- data/lib/mongo/event/subscriber.rb +0 -4
- data/lib/mongo/event.rb +4 -6
- data/lib/mongo/grid/file/chunk.rb +7 -10
- data/lib/mongo/grid/file/info.rb +20 -24
- data/lib/mongo/grid/file.rb +7 -8
- data/lib/mongo/grid/fs_bucket.rb +40 -48
- data/lib/mongo/grid/stream/read.rb +25 -35
- data/lib/mongo/grid/stream/write.rb +17 -22
- data/lib/mongo/grid/stream.rb +2 -4
- data/lib/mongo/grid.rb +0 -1
- data/lib/mongo/id.rb +0 -1
- data/lib/mongo/index/view.rb +49 -48
- data/lib/mongo/index.rb +7 -10
- data/lib/mongo/lint.rb +31 -37
- data/lib/mongo/loggable.rb +5 -8
- data/lib/mongo/logger.rb +1 -7
- data/lib/mongo/monitoring/cmap_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/command_log_subscriber.rb +25 -33
- data/lib/mongo/monitoring/event/cmap/base.rb +0 -2
- data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +2 -5
- data/lib/mongo/monitoring/event/cmap/connection_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/connection_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +0 -3
- data/lib/mongo/monitoring/event/cmap/pool_closed.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_created.rb +1 -4
- data/lib/mongo/monitoring/event/cmap/pool_ready.rb +1 -4
- data/lib/mongo/monitoring/event/cmap.rb +0 -1
- data/lib/mongo/monitoring/event/command_failed.rb +5 -9
- data/lib/mongo/monitoring/event/command_started.rb +8 -12
- data/lib/mongo/monitoring/event/command_succeeded.rb +7 -15
- data/lib/mongo/monitoring/event/secure.rb +15 -20
- data/lib/mongo/monitoring/event/server_closed.rb +1 -4
- data/lib/mongo/monitoring/event/server_description_changed.rb +4 -8
- data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +5 -10
- data/lib/mongo/monitoring/event/server_heartbeat_started.rb +1 -4
- data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +3 -8
- data/lib/mongo/monitoring/event/server_opening.rb +1 -4
- data/lib/mongo/monitoring/event/topology_changed.rb +2 -5
- data/lib/mongo/monitoring/event/topology_closed.rb +1 -4
- data/lib/mongo/monitoring/event/topology_opening.rb +1 -4
- data/lib/mongo/monitoring/event.rb +0 -1
- data/lib/mongo/monitoring/publishable.rb +20 -30
- data/lib/mongo/monitoring/sdam_log_subscriber.rb +0 -2
- data/lib/mongo/monitoring/server_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/server_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +5 -8
- data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +0 -3
- data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +1 -3
- data/lib/mongo/monitoring.rb +38 -39
- data/lib/mongo/operation/aggregate/op_msg.rb +0 -2
- data/lib/mongo/operation/aggregate/result.rb +3 -6
- data/lib/mongo/operation/aggregate.rb +0 -2
- data/lib/mongo/operation/collections_info/result.rb +0 -3
- data/lib/mongo/operation/collections_info.rb +0 -2
- data/lib/mongo/operation/command/op_msg.rb +1 -4
- data/lib/mongo/operation/command.rb +0 -2
- data/lib/mongo/operation/context.rb +13 -16
- data/lib/mongo/operation/count/op_msg.rb +2 -4
- data/lib/mongo/operation/count.rb +0 -2
- data/lib/mongo/operation/create/op_msg.rb +2 -5
- data/lib/mongo/operation/create.rb +0 -2
- data/lib/mongo/operation/create_index/op_msg.rb +3 -7
- data/lib/mongo/operation/create_index.rb +0 -2
- data/lib/mongo/operation/create_user/op_msg.rb +2 -4
- data/lib/mongo/operation/create_user.rb +0 -2
- data/lib/mongo/operation/delete/bulk_result.rb +2 -3
- data/lib/mongo/operation/delete/op_msg.rb +3 -10
- data/lib/mongo/operation/delete/result.rb +0 -3
- data/lib/mongo/operation/delete.rb +1 -5
- data/lib/mongo/operation/distinct/op_msg.rb +2 -5
- data/lib/mongo/operation/distinct.rb +0 -2
- data/lib/mongo/operation/drop/op_msg.rb +0 -2
- data/lib/mongo/operation/drop.rb +0 -2
- data/lib/mongo/operation/drop_database/op_msg.rb +0 -2
- data/lib/mongo/operation/drop_database.rb +0 -2
- data/lib/mongo/operation/drop_index/op_msg.rb +4 -6
- data/lib/mongo/operation/drop_index.rb +0 -2
- data/lib/mongo/operation/explain/op_msg.rb +0 -2
- data/lib/mongo/operation/explain/result.rb +0 -3
- data/lib/mongo/operation/explain.rb +0 -2
- data/lib/mongo/operation/find/builder/command.rb +4 -12
- data/lib/mongo/operation/find/builder/flags.rb +9 -15
- data/lib/mongo/operation/find/builder/modifiers.rb +1 -4
- data/lib/mongo/operation/find/builder.rb +0 -1
- data/lib/mongo/operation/find/op_msg.rb +4 -12
- data/lib/mongo/operation/find/result.rb +0 -3
- data/lib/mongo/operation/find.rb +0 -2
- data/lib/mongo/operation/get_more/command_builder.rb +1 -6
- data/lib/mongo/operation/get_more/op_msg.rb +10 -4
- data/lib/mongo/operation/get_more/result.rb +0 -3
- data/lib/mongo/operation/get_more.rb +0 -2
- data/lib/mongo/operation/indexes/op_msg.rb +0 -2
- data/lib/mongo/operation/indexes/result.rb +1 -5
- data/lib/mongo/operation/indexes.rb +0 -2
- data/lib/mongo/operation/insert/bulk_result.rb +2 -6
- data/lib/mongo/operation/insert/op_msg.rb +2 -4
- data/lib/mongo/operation/insert/result.rb +0 -3
- data/lib/mongo/operation/insert.rb +2 -5
- data/lib/mongo/operation/kill_cursors/command_builder.rb +0 -3
- data/lib/mongo/operation/kill_cursors/op_msg.rb +1 -3
- data/lib/mongo/operation/kill_cursors.rb +0 -2
- data/lib/mongo/operation/list_collections/op_msg.rb +4 -6
- data/lib/mongo/operation/list_collections/result.rb +1 -4
- data/lib/mongo/operation/list_collections.rb +0 -2
- data/lib/mongo/operation/map_reduce/op_msg.rb +0 -2
- data/lib/mongo/operation/map_reduce/result.rb +3 -6
- data/lib/mongo/operation/map_reduce.rb +0 -2
- data/lib/mongo/operation/op_msg_base.rb +0 -1
- data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -5
- data/lib/mongo/operation/parallel_scan/result.rb +2 -5
- data/lib/mongo/operation/parallel_scan.rb +0 -2
- data/lib/mongo/operation/remove_user/op_msg.rb +2 -4
- data/lib/mongo/operation/remove_user.rb +0 -2
- data/lib/mongo/operation/result.rb +38 -48
- data/lib/mongo/operation/shared/bypass_document_validation.rb +3 -7
- data/lib/mongo/operation/shared/causal_consistency_supported.rb +0 -3
- data/lib/mongo/operation/shared/executable.rb +19 -28
- data/lib/mongo/operation/shared/executable_no_validate.rb +0 -3
- data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -2
- data/lib/mongo/operation/shared/idable.rb +3 -6
- data/lib/mongo/operation/shared/limited.rb +0 -3
- data/lib/mongo/operation/shared/object_id_generator.rb +0 -3
- data/lib/mongo/operation/shared/op_msg_executable.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_lookup.rb +0 -2
- data/lib/mongo/operation/shared/polymorphic_result.rb +2 -4
- data/lib/mongo/operation/shared/read_preference_supported.rb +10 -15
- data/lib/mongo/operation/shared/response_handling.rb +13 -26
- data/lib/mongo/operation/shared/result/aggregatable.rb +12 -13
- data/lib/mongo/operation/shared/sessions_supported.rb +87 -99
- data/lib/mongo/operation/shared/specifiable.rb +32 -58
- data/lib/mongo/operation/shared/write.rb +12 -17
- data/lib/mongo/operation/shared/write_concern_supported.rb +4 -7
- data/lib/mongo/operation/update/bulk_result.rb +13 -17
- data/lib/mongo/operation/update/op_msg.rb +2 -5
- data/lib/mongo/operation/update/result.rb +5 -5
- data/lib/mongo/operation/update.rb +1 -5
- data/lib/mongo/operation/update_user/op_msg.rb +2 -4
- data/lib/mongo/operation/update_user.rb +0 -2
- data/lib/mongo/operation/users_info/op_msg.rb +2 -4
- data/lib/mongo/operation/users_info/result.rb +1 -4
- data/lib/mongo/operation/users_info.rb +0 -2
- data/lib/mongo/operation/write_command/op_msg.rb +2 -10
- data/lib/mongo/operation/write_command.rb +0 -2
- data/lib/mongo/operation.rb +9 -14
- data/lib/mongo/options/mapper.rb +8 -15
- data/lib/mongo/options/redacted.rb +7 -9
- data/lib/mongo/options.rb +0 -1
- data/lib/mongo/protocol/bit_vector.rb +3 -5
- data/lib/mongo/protocol/caching_hash.rb +2 -7
- data/lib/mongo/protocol/compressed.rb +5 -10
- data/lib/mongo/protocol/get_more.rb +2 -8
- data/lib/mongo/protocol/kill_cursors.rb +2 -8
- data/lib/mongo/protocol/message.rb +103 -105
- data/lib/mongo/protocol/msg.rb +48 -63
- data/lib/mongo/protocol/query.rb +32 -41
- data/lib/mongo/protocol/registry.rb +2 -5
- data/lib/mongo/protocol/reply.rb +10 -16
- data/lib/mongo/protocol/serializers.rb +41 -59
- data/lib/mongo/protocol.rb +0 -1
- data/lib/mongo/query_cache.rb +7 -15
- data/lib/mongo/retryable/backpressure.rb +31 -0
- data/lib/mongo/retryable/base_worker.rb +39 -13
- data/lib/mongo/retryable/read_worker.rb +77 -21
- data/lib/mongo/retryable/retry_policy.rb +59 -0
- data/lib/mongo/retryable/write_worker.rb +155 -56
- data/lib/mongo/retryable.rb +70 -9
- data/lib/mongo/search_index/view.rb +1 -1
- data/lib/mongo/semaphore.rb +0 -1
- data/lib/mongo/server/app_metadata/environment.rb +3 -3
- data/lib/mongo/server/app_metadata.rb +4 -5
- data/lib/mongo/server/connection.rb +61 -61
- data/lib/mongo/server/connection_base.rb +43 -53
- data/lib/mongo/server/connection_common.rb +41 -64
- data/lib/mongo/server/connection_pool/generation_manager.rb +6 -11
- data/lib/mongo/server/connection_pool/populator.rb +1 -4
- data/lib/mongo/server/connection_pool.rb +195 -167
- data/lib/mongo/server/description/features.rb +23 -60
- data/lib/mongo/server/description/load_balancer.rb +0 -2
- data/lib/mongo/server/description.rb +117 -138
- data/lib/mongo/server/monitor/app_metadata.rb +3 -4
- data/lib/mongo/server/monitor/connection.rb +28 -35
- data/lib/mongo/server/monitor.rb +65 -60
- data/lib/mongo/server/pending_connection.rb +70 -71
- data/lib/mongo/server/push_monitor/connection.rb +0 -3
- data/lib/mongo/server/push_monitor.rb +21 -29
- data/lib/mongo/server/round_trip_time_calculator.rb +11 -17
- data/lib/mongo/server.rb +60 -93
- data/lib/mongo/server_selector/base.rb +133 -157
- data/lib/mongo/server_selector/nearest.rb +2 -5
- data/lib/mongo/server_selector/primary.rb +1 -5
- data/lib/mongo/server_selector/primary_preferred.rb +2 -6
- data/lib/mongo/server_selector/secondary.rb +2 -6
- data/lib/mongo/server_selector/secondary_preferred.rb +1 -5
- data/lib/mongo/server_selector.rb +3 -4
- data/lib/mongo/session/server_session.rb +6 -7
- data/lib/mongo/session/session_pool.rb +20 -34
- data/lib/mongo/session.rb +287 -188
- data/lib/mongo/socket/ocsp_cache.rb +8 -13
- data/lib/mongo/socket/ocsp_verifier.rb +69 -70
- data/lib/mongo/socket/ssl.rb +44 -43
- data/lib/mongo/socket/tcp.rb +5 -8
- data/lib/mongo/socket/unix.rb +0 -4
- data/lib/mongo/socket.rb +80 -102
- data/lib/mongo/srv/monitor.rb +6 -11
- data/lib/mongo/srv/resolver.rb +15 -24
- data/lib/mongo/srv/result.rb +18 -24
- data/lib/mongo/srv.rb +0 -1
- data/lib/mongo/timeout.rb +4 -11
- data/lib/mongo/topology_version.rb +8 -13
- data/lib/mongo/tracing/open_telemetry/command_tracer.rb +1 -1
- data/lib/mongo/tracing/open_telemetry/operation_tracer.rb +1 -1
- data/lib/mongo/tracing/open_telemetry/tracer.rb +1 -1
- data/lib/mongo/uri/options_mapper.rb +135 -126
- data/lib/mongo/uri/srv_protocol.rb +25 -38
- data/lib/mongo/uri.rb +95 -139
- data/lib/mongo/utils.rb +5 -12
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern/acknowledged.rb +0 -2
- data/lib/mongo/write_concern/base.rb +6 -6
- data/lib/mongo/write_concern/unacknowledged.rb +0 -2
- data/lib/mongo/write_concern.rb +14 -15
- data/lib/mongo.rb +1 -3
- data/mongo.gemspec +17 -17
- metadata +5 -5
- data/lib/mongo/error/server_api_not_supported.rb +0 -27
- data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +0 -32
- data/lib/mongo/operation/shared/validatable.rb +0 -87
data/lib/mongo/crypt/context.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,9 +16,8 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A wrapper around mongocrypt_ctx_t, which manages the
|
|
22
|
-
# state machine for encryption and
|
|
20
|
+
# state machine for encryption and decryption.
|
|
23
21
|
#
|
|
24
22
|
# This class is a superclass that defines shared methods
|
|
25
23
|
# amongst contexts that are initialized for different purposes
|
|
@@ -150,7 +148,7 @@ module Mongo
|
|
|
150
148
|
end
|
|
151
149
|
|
|
152
150
|
def feed_kms
|
|
153
|
-
while (kms_context = Binding.ctx_next_kms_ctx(self))
|
|
151
|
+
while (kms_context = Binding.ctx_next_kms_ctx(self))
|
|
154
152
|
begin
|
|
155
153
|
delay = Binding.kms_ctx_usleep(kms_context)
|
|
156
154
|
sleep(delay / 1_000_000.0) unless delay.nil?
|
|
@@ -158,15 +156,10 @@ module Mongo
|
|
|
158
156
|
tls_options = @mongocrypt_handle.kms_tls_options(provider)
|
|
159
157
|
@encryption_io.feed_kms(kms_context, tls_options)
|
|
160
158
|
rescue Error::KmsError => e
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
raise
|
|
166
|
-
end
|
|
167
|
-
else
|
|
168
|
-
raise
|
|
169
|
-
end
|
|
159
|
+
raise unless e.network_error?
|
|
160
|
+
next if Binding.kms_ctx_fail(kms_context)
|
|
161
|
+
|
|
162
|
+
raise
|
|
170
163
|
end
|
|
171
164
|
end
|
|
172
165
|
Binding.ctx_kms_done(self)
|
|
@@ -195,20 +188,20 @@ module Mongo
|
|
|
195
188
|
# KMS providers.
|
|
196
189
|
def retrieve_kms_credentials(timeout_holder)
|
|
197
190
|
providers = {}
|
|
198
|
-
if kms_providers.aws
|
|
191
|
+
if kms_providers.aws && kms_providers.aws.empty?
|
|
199
192
|
begin
|
|
200
193
|
aws_credentials = Mongo::Auth::Aws::CredentialsRetriever.new.credentials(timeout_holder)
|
|
201
194
|
rescue Auth::Aws::CredentialsNotFound
|
|
202
195
|
raise Error::CryptError.new(
|
|
203
|
-
|
|
196
|
+
'Could not locate AWS credentials (checked environment variables, ECS and EC2 metadata)'
|
|
204
197
|
)
|
|
205
198
|
end
|
|
206
199
|
providers[:aws] = aws_credentials.to_h
|
|
207
200
|
end
|
|
208
|
-
if kms_providers.gcp
|
|
201
|
+
if kms_providers.gcp && kms_providers.gcp.empty?
|
|
209
202
|
providers[:gcp] = { access_token: gcp_access_token(timeout_holder) }
|
|
210
203
|
end
|
|
211
|
-
if kms_providers.azure
|
|
204
|
+
if kms_providers.azure && kms_providers.azure.empty?
|
|
212
205
|
providers[:azure] = { access_token: azure_access_token(timeout_holder) }
|
|
213
206
|
end
|
|
214
207
|
KMS::Credentials.new(providers)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,13 +16,11 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A Context object initialized specifically for the purpose of creating
|
|
22
20
|
# a data key in the key management system.
|
|
23
21
|
#
|
|
24
22
|
# @api private
|
|
25
23
|
class DataKeyContext < Context
|
|
26
|
-
|
|
27
24
|
# Create a new DataKeyContext object
|
|
28
25
|
#
|
|
29
26
|
# @param [ Mongo::Crypt::Handle ] mongocrypt a Handle that
|
|
@@ -50,14 +47,12 @@ module Mongo
|
|
|
50
47
|
|
|
51
48
|
# Set the alt names option on the context
|
|
52
49
|
def set_key_alt_names(key_alt_names)
|
|
53
|
-
unless key_alt_names.is_a?(Array)
|
|
54
|
-
raise ArgumentError.new, 'The :key_alt_names option must be an Array'
|
|
55
|
-
end
|
|
50
|
+
raise ArgumentError.new, 'The :key_alt_names option must be an Array' unless key_alt_names.is_a?(Array)
|
|
56
51
|
|
|
57
52
|
unless key_alt_names.all? { |key_alt_name| key_alt_name.is_a?(String) }
|
|
58
53
|
raise ArgumentError.new(
|
|
59
54
|
"#{key_alt_names} contains an invalid alternate key name. All " +
|
|
60
|
-
|
|
55
|
+
'values of the :key_alt_names option Array must be Strings'
|
|
61
56
|
)
|
|
62
57
|
end
|
|
63
58
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,13 +16,11 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A class that implements I/O methods between the driver and
|
|
22
20
|
# the MongoDB server or mongocryptd.
|
|
23
21
|
#
|
|
24
22
|
# @api private
|
|
25
23
|
class EncryptionIO
|
|
26
|
-
|
|
27
24
|
# Timeout used for TLS socket connection, reading, and writing.
|
|
28
25
|
# There is no specific timeout written in the spec. See SPEC-1394
|
|
29
26
|
# for a discussion and updates on what this timeout should be.
|
|
@@ -55,8 +52,7 @@ module Mongo
|
|
|
55
52
|
# @note This class expects that the key_vault_client and key_vault_namespace
|
|
56
53
|
# options are not nil and are in the correct format.
|
|
57
54
|
def initialize(
|
|
58
|
-
client: nil, mongocryptd_client: nil,
|
|
59
|
-
key_vault_client:, metadata_client:, mongocryptd_options: {}
|
|
55
|
+
key_vault_namespace:, key_vault_client:, metadata_client:, client: nil, mongocryptd_client: nil, mongocryptd_options: {}
|
|
60
56
|
)
|
|
61
57
|
validate_key_vault_client!(key_vault_client)
|
|
62
58
|
validate_key_vault_namespace!(key_vault_namespace)
|
|
@@ -104,7 +100,8 @@ module Mongo
|
|
|
104
100
|
# @return [ Hash ] The collection information
|
|
105
101
|
def collection_info(db_name, filter, timeout_ms: nil)
|
|
106
102
|
unless @metadata_client
|
|
107
|
-
raise ArgumentError,
|
|
103
|
+
raise ArgumentError,
|
|
104
|
+
'collection_info requires metadata_client to have been passed to the constructor, but it was not'
|
|
108
105
|
end
|
|
109
106
|
|
|
110
107
|
@metadata_client
|
|
@@ -124,7 +121,8 @@ module Mongo
|
|
|
124
121
|
# @return [ Hash ] The marked command
|
|
125
122
|
def mark_command(cmd, timeout_ms: nil)
|
|
126
123
|
unless @mongocryptd_client
|
|
127
|
-
raise ArgumentError,
|
|
124
|
+
raise ArgumentError,
|
|
125
|
+
'mark_command requires mongocryptd_client to have been passed to the constructor, but it was not'
|
|
128
126
|
end
|
|
129
127
|
|
|
130
128
|
# Ensure the response from mongocryptd is deserialized with { mode: :bson }
|
|
@@ -143,7 +141,7 @@ module Mongo
|
|
|
143
141
|
response = @mongocryptd_client.database.command(cmd, options)
|
|
144
142
|
end
|
|
145
143
|
|
|
146
|
-
|
|
144
|
+
response.first
|
|
147
145
|
end
|
|
148
146
|
|
|
149
147
|
# Get information about the remote KMS encryption key and feed it to the the
|
|
@@ -161,16 +159,14 @@ module Mongo
|
|
|
161
159
|
def feed_kms(kms_context, tls_options, timeout_ms: nil)
|
|
162
160
|
with_ssl_socket(kms_context.endpoint, tls_options) do |ssl_socket|
|
|
163
161
|
Timeout.timeout(timeout_ms || SOCKET_TIMEOUT, Error::SocketTimeoutError,
|
|
164
|
-
|
|
165
|
-
) do
|
|
162
|
+
'Socket write operation timed out') do
|
|
166
163
|
ssl_socket.syswrite(kms_context.message)
|
|
167
164
|
end
|
|
168
165
|
|
|
169
166
|
bytes_needed = kms_context.bytes_needed
|
|
170
|
-
while bytes_needed > 0
|
|
167
|
+
while bytes_needed > 0
|
|
171
168
|
bytes = Timeout.timeout(timeout_ms || SOCKET_TIMEOUT, Error::SocketTimeoutError,
|
|
172
|
-
|
|
173
|
-
) do
|
|
169
|
+
'Socket read operation timed out') do
|
|
174
170
|
ssl_socket.sysread(bytes_needed)
|
|
175
171
|
end
|
|
176
172
|
|
|
@@ -227,7 +223,7 @@ module Mongo
|
|
|
227
223
|
{
|
|
228
224
|
'$filter' => {
|
|
229
225
|
input: '$keyAltNames',
|
|
230
|
-
cond: { '$ne' =>
|
|
226
|
+
cond: { '$ne' => [ '$$this', key_alt_name ] }
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
229
|
]
|
|
@@ -251,28 +247,24 @@ module Mongo
|
|
|
251
247
|
private
|
|
252
248
|
|
|
253
249
|
def validate_key_vault_client!(key_vault_client)
|
|
254
|
-
unless key_vault_client
|
|
255
|
-
raise ArgumentError.new('The :key_vault_client option cannot be nil')
|
|
256
|
-
end
|
|
250
|
+
raise ArgumentError.new('The :key_vault_client option cannot be nil') unless key_vault_client
|
|
257
251
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
252
|
+
return if key_vault_client.is_a?(Client)
|
|
253
|
+
|
|
254
|
+
raise ArgumentError.new(
|
|
255
|
+
'The :key_vault_client option must be an instance of Mongo::Client'
|
|
256
|
+
)
|
|
263
257
|
end
|
|
264
258
|
|
|
265
259
|
def validate_key_vault_namespace!(key_vault_namespace)
|
|
266
|
-
unless key_vault_namespace
|
|
267
|
-
raise ArgumentError.new('The :key_vault_namespace option cannot be nil')
|
|
268
|
-
end
|
|
260
|
+
raise ArgumentError.new('The :key_vault_namespace option cannot be nil') unless key_vault_namespace
|
|
269
261
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
262
|
+
return if key_vault_namespace.split('.').length == 2
|
|
263
|
+
|
|
264
|
+
raise ArgumentError.new(
|
|
265
|
+
"#{key_vault_namespace} is an invalid key vault namespace." +
|
|
266
|
+
'The :key_vault_namespace option must be in the format database.collection'
|
|
267
|
+
)
|
|
276
268
|
end
|
|
277
269
|
|
|
278
270
|
# Use the provided key vault client and namespace to construct a
|
|
@@ -309,8 +301,7 @@ module Mongo
|
|
|
309
301
|
end
|
|
310
302
|
|
|
311
303
|
if mongocryptd_spawn_path.nil? ||
|
|
312
|
-
|
|
313
|
-
then
|
|
304
|
+
mongocryptd_spawn_args.nil? || mongocryptd_spawn_args.empty?
|
|
314
305
|
raise ArgumentError.new(
|
|
315
306
|
'Cannot spawn mongocryptd process when no :mongocryptd_spawn_args ' +
|
|
316
307
|
'option is provided. To start mongocryptd without arguments, pass ' +
|
|
@@ -322,7 +313,7 @@ module Mongo
|
|
|
322
313
|
Process.spawn(
|
|
323
314
|
mongocryptd_spawn_path,
|
|
324
315
|
*mongocryptd_spawn_args,
|
|
325
|
-
[
|
|
316
|
+
%i[out err] => '/dev/null'
|
|
326
317
|
)
|
|
327
318
|
rescue Errno::ENOENT => e
|
|
328
319
|
raise Error::MongocryptdSpawnError.new(
|
|
@@ -351,12 +342,10 @@ module Mongo
|
|
|
351
342
|
address = begin
|
|
352
343
|
host, port = endpoint.split(':')
|
|
353
344
|
port ||= 443 # All supported KMS APIs use this port by default.
|
|
354
|
-
Address.new([host, port].join(':'))
|
|
345
|
+
Address.new([ host, port ].join(':'))
|
|
355
346
|
end
|
|
356
347
|
socket_options = { ssl: true, csot: csot }.tap do |opts|
|
|
357
|
-
if csot
|
|
358
|
-
opts[:connect_timeout] = (timeout_ms / 1_000.0)
|
|
359
|
-
end
|
|
348
|
+
opts[:connect_timeout] = (timeout_ms / 1_000.0) if csot
|
|
360
349
|
end
|
|
361
350
|
mongo_socket = address.socket(
|
|
362
351
|
SOCKET_TIMEOUT,
|
|
@@ -366,7 +355,8 @@ module Mongo
|
|
|
366
355
|
rescue Error::KmsError
|
|
367
356
|
raise
|
|
368
357
|
rescue StandardError => e
|
|
369
|
-
raise Error::KmsError.new("Error when connecting to KMS provider: #{e.class}: #{e.message}",
|
|
358
|
+
raise Error::KmsError.new("Error when connecting to KMS provider: #{e.class}: #{e.message}",
|
|
359
|
+
network_error: true)
|
|
370
360
|
ensure
|
|
371
361
|
mongo_socket&.close
|
|
372
362
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,12 +16,10 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A Context object initialized for explicit decryption
|
|
22
20
|
#
|
|
23
21
|
# @api private
|
|
24
22
|
class ExplicitDecryptionContext < Context
|
|
25
|
-
|
|
26
23
|
# Create a new ExplicitDecryptionContext object
|
|
27
24
|
#
|
|
28
25
|
# @param [ Mongo::Crypt::Handle ] mongocrypt a Handle that
|
|
@@ -317,7 +317,7 @@ module Mongo
|
|
|
317
317
|
KMS::MasterKeyDocument.new(provider, options)
|
|
318
318
|
end
|
|
319
319
|
|
|
320
|
-
# Returns the corresponding update document for each
|
|
320
|
+
# Returns the corresponding update document for each of the given
|
|
321
321
|
# data key documents.
|
|
322
322
|
#
|
|
323
323
|
# @param [ Array<Hash> ] documents the data key documents
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,12 +16,10 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Crypt
|
|
20
|
-
|
|
21
19
|
# A Context object initialized for explicit encryption
|
|
22
20
|
#
|
|
23
21
|
# @api private
|
|
24
22
|
class ExplicitEncryptionContext < Context
|
|
25
|
-
|
|
26
23
|
# Create a new ExplicitEncryptionContext object
|
|
27
24
|
#
|
|
28
25
|
# @param [ Mongo::Crypt::Handle ] mongocrypt a Handle that
|
|
@@ -76,6 +73,7 @@ module Mongo
|
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
private
|
|
76
|
+
|
|
79
77
|
def set_key_opts(options)
|
|
80
78
|
if options[:key_id].nil? && options[:key_alt_name].nil?
|
|
81
79
|
raise ArgumentError.new(
|
|
@@ -99,31 +97,26 @@ module Mongo
|
|
|
99
97
|
|
|
100
98
|
def set_key_id(key_id)
|
|
101
99
|
unless key_id.is_a?(BSON::Binary) &&
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
key_id.type == :uuid
|
|
101
|
+
raise ArgumentError.new(
|
|
102
|
+
'Expected the :key_id option to be a BSON::Binary object with ' +
|
|
103
|
+
"type :uuid. #{key_id} is an invalid :key_id option"
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
Binding.ctx_setopt_key_id(self, key_id.data)
|
|
109
107
|
end
|
|
110
108
|
|
|
111
109
|
def set_key_alt_name(key_alt_name)
|
|
112
|
-
unless key_alt_name.is_a?(String)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
Binding.ctx_setopt_key_alt_names(self, [key_alt_name])
|
|
110
|
+
raise ArgumentError.new(':key_alt_name option must be a String') unless key_alt_name.is_a?(String)
|
|
111
|
+
|
|
112
|
+
Binding.ctx_setopt_key_alt_names(self, [ key_alt_name ])
|
|
116
113
|
end
|
|
117
114
|
|
|
118
115
|
def set_algorithm_opts(options)
|
|
119
116
|
Binding.ctx_setopt_algorithm(self, options[:algorithm])
|
|
120
|
-
if %w
|
|
121
|
-
if options[:contention_factor]
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
if options[:query_type]
|
|
125
|
-
Binding.ctx_setopt_query_type(self, options[:query_type])
|
|
126
|
-
end
|
|
117
|
+
if %w[Indexed Range].include?(options[:algorithm])
|
|
118
|
+
Binding.ctx_setopt_contention_factor(self, options[:contention_factor]) if options[:contention_factor]
|
|
119
|
+
Binding.ctx_setopt_query_type(self, options[:query_type]) if options[:query_type]
|
|
127
120
|
else
|
|
128
121
|
if options[:contention_factor]
|
|
129
122
|
raise ArgumentError.new(':contention_factor is allowed only for "Indexed" or "Range" algorithms')
|
|
@@ -132,19 +125,15 @@ module Mongo
|
|
|
132
125
|
raise ArgumentError.new(':query_type is allowed only for "Indexed" or "Range" algorithms')
|
|
133
126
|
end
|
|
134
127
|
end
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
return unless options[:algorithm] == 'Range'
|
|
129
|
+
|
|
130
|
+
Binding.ctx_setopt_algorithm_range(self, convert_range_opts(options[:range_opts]))
|
|
138
131
|
end
|
|
139
132
|
|
|
140
133
|
def convert_range_opts(range_opts)
|
|
141
134
|
range_opts.dup.tap do |opts|
|
|
142
|
-
if opts[:sparsity] && !opts[:sparsity].is_a?(BSON::Int64)
|
|
143
|
-
|
|
144
|
-
end
|
|
145
|
-
if opts[:trim_factor]
|
|
146
|
-
opts[:trimFactor] = opts.delete(:trim_factor)
|
|
147
|
-
end
|
|
135
|
+
opts[:sparsity] = BSON::Int64.new(opts[:sparsity]) if opts[:sparsity] && !opts[:sparsity].is_a?(BSON::Int64)
|
|
136
|
+
opts[:trimFactor] = opts.delete(:trim_factor) if opts[:trim_factor]
|
|
148
137
|
end
|
|
149
138
|
end
|
|
150
139
|
end
|
data/lib/mongo/crypt/handle.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2019-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -20,15 +19,13 @@ require 'base64'
|
|
|
20
19
|
|
|
21
20
|
module Mongo
|
|
22
21
|
module Crypt
|
|
23
|
-
|
|
24
22
|
# A handle to the libmongocrypt library that wraps a mongocrypt_t object,
|
|
25
23
|
# allowing clients to set options on that object or perform operations such
|
|
26
24
|
# as encryption and decryption
|
|
27
25
|
#
|
|
28
26
|
# @api private
|
|
29
27
|
class Handle
|
|
30
|
-
|
|
31
|
-
# @returns [ Crypt::KMS::Credentials ] Credentials for KMS providers.
|
|
28
|
+
# @return [ Crypt::KMS::Credentials ] Credentials for KMS providers.
|
|
32
29
|
attr_reader :kms_providers
|
|
33
30
|
|
|
34
31
|
# Creates a new Handle object and initializes it with options
|
|
@@ -62,9 +59,14 @@ module Mongo
|
|
|
62
59
|
# @option options [ Boolean | nil ] :explicit_encryption_only Whether this
|
|
63
60
|
# handle is going to be used only for explicit encryption. If true,
|
|
64
61
|
# libmongocrypt is instructed not to load crypt shared library.
|
|
62
|
+
# @option options [ Boolean | nil ] :disable_crypt_shared_lib_search When
|
|
63
|
+
# true, suppresses the automatic "$SYSTEM" search for crypt_shared. Use
|
|
64
|
+
# this when a previous Handle in the same process has already loaded the
|
|
65
|
+
# library via a path override and you want to avoid the conflicting-load
|
|
66
|
+
# error that libmongocrypt raises on a subsequent "$SYSTEM" search.
|
|
65
67
|
# @option options [ Logger ] :logger A Logger object to which libmongocrypt logs
|
|
66
68
|
# will be sent
|
|
67
|
-
def initialize(kms_providers, kms_tls_options, options={})
|
|
69
|
+
def initialize(kms_providers, kms_tls_options, options = {})
|
|
68
70
|
# FFI::AutoPointer uses a custom release strategy to automatically free
|
|
69
71
|
# the pointer once this object goes out of scope
|
|
70
72
|
@mongocrypt = FFI::AutoPointer.new(
|
|
@@ -73,7 +75,7 @@ module Mongo
|
|
|
73
75
|
)
|
|
74
76
|
Binding.kms_ctx_setopt_retry_kms(self, true)
|
|
75
77
|
@kms_providers = kms_providers
|
|
76
|
-
@kms_tls_options =
|
|
78
|
+
@kms_tls_options = kms_tls_options
|
|
77
79
|
|
|
78
80
|
maybe_set_schema_map(options)
|
|
79
81
|
|
|
@@ -85,10 +87,11 @@ module Mongo
|
|
|
85
87
|
|
|
86
88
|
@crypt_shared_lib_path = options[:crypt_shared_lib_path]
|
|
87
89
|
@explicit_encryption_only = options[:explicit_encryption_only]
|
|
90
|
+
@disable_crypt_shared_lib_search = options[:disable_crypt_shared_lib_search]
|
|
88
91
|
if @crypt_shared_lib_path
|
|
89
92
|
Binding.setopt_set_crypt_shared_lib_path_override(self, @crypt_shared_lib_path)
|
|
90
|
-
elsif !@bypass_query_analysis && !@explicit_encryption_only
|
|
91
|
-
Binding.setopt_append_crypt_shared_lib_search_path(self,
|
|
93
|
+
elsif !@bypass_query_analysis && !@explicit_encryption_only && !@disable_crypt_shared_lib_search
|
|
94
|
+
Binding.setopt_append_crypt_shared_lib_search_path(self, '$SYSTEM')
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
@logger = options[:logger]
|
|
@@ -105,11 +108,11 @@ module Mongo
|
|
|
105
108
|
initialize_mongocrypt
|
|
106
109
|
|
|
107
110
|
@crypt_shared_lib_required = !!options[:crypt_shared_lib_required]
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
return unless @crypt_shared_lib_required && crypt_shared_lib_version == 0
|
|
112
|
+
|
|
113
|
+
raise Mongo::Error::CryptError.new(
|
|
114
|
+
'Crypt shared library is required, but cannot be loaded according to libmongocrypt'
|
|
115
|
+
)
|
|
113
116
|
end
|
|
114
117
|
|
|
115
118
|
# Return the reference to the underlying @mongocrypt object
|
|
@@ -145,7 +148,7 @@ module Mongo
|
|
|
145
148
|
@schema_map = nil
|
|
146
149
|
elsif options[:schema_map] && options[:schema_map_path]
|
|
147
150
|
raise ArgumentError.new(
|
|
148
|
-
|
|
151
|
+
'Cannot set both schema_map and schema_map_path options.'
|
|
149
152
|
)
|
|
150
153
|
elsif options[:schema_map]
|
|
151
154
|
unless options[:schema_map].is_a?(Hash)
|
|
@@ -176,7 +179,7 @@ module Mongo
|
|
|
176
179
|
end
|
|
177
180
|
|
|
178
181
|
def set_bypass_query_analysis
|
|
179
|
-
unless [true, false].include?(@bypass_query_analysis)
|
|
182
|
+
unless [ true, false ].include?(@bypass_query_analysis)
|
|
180
183
|
raise ArgumentError.new(
|
|
181
184
|
"#{@bypass_query_analysis} is an invalid bypass_query_analysis value; must be a Boolean or nil"
|
|
182
185
|
)
|
|
@@ -187,7 +190,7 @@ module Mongo
|
|
|
187
190
|
|
|
188
191
|
# Send the logs from libmongocrypt to the Mongo::Logger
|
|
189
192
|
def set_logger_callback
|
|
190
|
-
@log_callback =
|
|
193
|
+
@log_callback = proc do |level, msg|
|
|
191
194
|
@logger.send(level, msg)
|
|
192
195
|
end
|
|
193
196
|
|
|
@@ -207,15 +210,13 @@ module Mongo
|
|
|
207
210
|
# @return [ true | false ] Whether block executed without raising
|
|
208
211
|
# exceptions.
|
|
209
212
|
def handle_error(status_p)
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
false
|
|
218
|
-
end
|
|
213
|
+
yield
|
|
214
|
+
|
|
215
|
+
true
|
|
216
|
+
rescue StandardError => e
|
|
217
|
+
status = Status.from_pointer(status_p)
|
|
218
|
+
status.update(:error_client, 1, "#{e.class}: #{e}")
|
|
219
|
+
false
|
|
219
220
|
end
|
|
220
221
|
|
|
221
222
|
# Yields to the provided block and writes the return value of block
|
|
@@ -242,7 +243,7 @@ module Mongo
|
|
|
242
243
|
# Perform AES encryption or decryption and write the output to the
|
|
243
244
|
# provided mongocrypt_binary_t object.
|
|
244
245
|
def do_aes(key_binary_p, iv_binary_p, input_binary_p, output_binary_p,
|
|
245
|
-
|
|
246
|
+
response_length_p, status_p, decrypt: false, mode: :CBC)
|
|
246
247
|
key = Binary.from_pointer(key_binary_p).to_s
|
|
247
248
|
iv = Binary.from_pointer(iv_binary_p).to_s
|
|
248
249
|
input = Binary.from_pointer(input_binary_p).to_s
|
|
@@ -258,7 +259,7 @@ module Mongo
|
|
|
258
259
|
# Perform HMAC SHA encryption and write the output to the provided
|
|
259
260
|
# mongocrypt_binary_t object.
|
|
260
261
|
def do_hmac_sha(digest_name, key_binary_p, input_binary_p,
|
|
261
|
-
|
|
262
|
+
output_binary_p, status_p)
|
|
262
263
|
key = Binary.from_pointer(key_binary_p).to_s
|
|
263
264
|
input = Binary.from_pointer(input_binary_p).to_s
|
|
264
265
|
|
|
@@ -270,7 +271,7 @@ module Mongo
|
|
|
270
271
|
# Perform signing using RSASSA-PKCS1-v1_5 with SHA256 hash and write
|
|
271
272
|
# the output to the provided mongocrypt_binary_t object.
|
|
272
273
|
def do_rsaes_pkcs_signature(key_binary_p, input_binary_p,
|
|
273
|
-
|
|
274
|
+
output_binary_p, status_p)
|
|
274
275
|
key = Binary.from_pointer(key_binary_p).to_s
|
|
275
276
|
input = Binary.from_pointer(input_binary_p).to_s
|
|
276
277
|
|
|
@@ -287,8 +288,7 @@ module Mongo
|
|
|
287
288
|
# Every crypto binding ignores its first argument, which is an option
|
|
288
289
|
# mongocrypt_ctx_t object and is not required to use crypto hooks.
|
|
289
290
|
def set_crypto_hooks
|
|
290
|
-
@aes_encrypt =
|
|
291
|
-
output_binary_p, response_length_p, status_p|
|
|
291
|
+
@aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
|
|
292
292
|
do_aes(
|
|
293
293
|
key_binary_p,
|
|
294
294
|
iv_binary_p,
|
|
@@ -299,8 +299,7 @@ module Mongo
|
|
|
299
299
|
)
|
|
300
300
|
end
|
|
301
301
|
|
|
302
|
-
@aes_decrypt =
|
|
303
|
-
output_binary_p, response_length_p, status_p|
|
|
302
|
+
@aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
|
|
304
303
|
do_aes(
|
|
305
304
|
key_binary_p,
|
|
306
305
|
iv_binary_p,
|
|
@@ -312,23 +311,21 @@ module Mongo
|
|
|
312
311
|
)
|
|
313
312
|
end
|
|
314
313
|
|
|
315
|
-
@random =
|
|
314
|
+
@random = proc do |_, output_binary_p, num_bytes, status_p|
|
|
316
315
|
write_binary_string_and_set_status(output_binary_p, status_p) do
|
|
317
316
|
Hooks.random(num_bytes)
|
|
318
317
|
end
|
|
319
318
|
end
|
|
320
319
|
|
|
321
|
-
@hmac_sha_512 =
|
|
322
|
-
output_binary_p, status_p|
|
|
320
|
+
@hmac_sha_512 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
|
|
323
321
|
do_hmac_sha('SHA512', key_binary_p, input_binary_p, output_binary_p, status_p)
|
|
324
322
|
end
|
|
325
323
|
|
|
326
|
-
@hmac_sha_256 =
|
|
327
|
-
output_binary_p, status_p|
|
|
324
|
+
@hmac_sha_256 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
|
|
328
325
|
do_hmac_sha('SHA256', key_binary_p, input_binary_p, output_binary_p, status_p)
|
|
329
326
|
end
|
|
330
327
|
|
|
331
|
-
@hmac_hash =
|
|
328
|
+
@hmac_hash = proc do |_, input_binary_p, output_binary_p, status_p|
|
|
332
329
|
input = Binary.from_pointer(input_binary_p).to_s
|
|
333
330
|
|
|
334
331
|
write_binary_string_and_set_status(output_binary_p, status_p) do
|
|
@@ -343,11 +340,10 @@ module Mongo
|
|
|
343
340
|
@random,
|
|
344
341
|
@hmac_sha_512,
|
|
345
342
|
@hmac_sha_256,
|
|
346
|
-
@hmac_hash
|
|
343
|
+
@hmac_hash
|
|
347
344
|
)
|
|
348
345
|
|
|
349
|
-
@aes_ctr_encrypt =
|
|
350
|
-
output_binary_p, response_length_p, status_p|
|
|
346
|
+
@aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
|
|
351
347
|
do_aes(
|
|
352
348
|
key_binary_p,
|
|
353
349
|
iv_binary_p,
|
|
@@ -355,12 +351,11 @@ module Mongo
|
|
|
355
351
|
output_binary_p,
|
|
356
352
|
response_length_p,
|
|
357
353
|
status_p,
|
|
358
|
-
mode: :CTR
|
|
354
|
+
mode: :CTR
|
|
359
355
|
)
|
|
360
356
|
end
|
|
361
357
|
|
|
362
|
-
@aes_ctr_decrypt =
|
|
363
|
-
output_binary_p, response_length_p, status_p|
|
|
358
|
+
@aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
|
|
364
359
|
do_aes(
|
|
365
360
|
key_binary_p,
|
|
366
361
|
iv_binary_p,
|
|
@@ -369,18 +364,17 @@ module Mongo
|
|
|
369
364
|
response_length_p,
|
|
370
365
|
status_p,
|
|
371
366
|
decrypt: true,
|
|
372
|
-
mode: :CTR
|
|
367
|
+
mode: :CTR
|
|
373
368
|
)
|
|
374
369
|
end
|
|
375
370
|
|
|
376
371
|
Binding.setopt_aes_256_ctr(
|
|
377
372
|
self,
|
|
378
373
|
@aes_ctr_encrypt,
|
|
379
|
-
@aes_ctr_decrypt
|
|
374
|
+
@aes_ctr_decrypt
|
|
380
375
|
)
|
|
381
376
|
|
|
382
|
-
@rsaes_pkcs_signature_cb =
|
|
383
|
-
output_binary_p, status_p|
|
|
377
|
+
@rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
|
|
384
378
|
do_rsaes_pkcs_signature(key_binary_p, input_binary_p, output_binary_p, status_p)
|
|
385
379
|
end
|
|
386
380
|
|