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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -23,7 +22,7 @@ module Mongo
|
|
|
23
22
|
# @api private
|
|
24
23
|
class CredentialsNotFound < Mongo::Error::AuthError
|
|
25
24
|
def initialize
|
|
26
|
-
super(
|
|
25
|
+
super('Could not locate AWS credentials (checked Client URI and Ruby options, environment variables, ECS and EC2 metadata, and Web Identity)')
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
28
|
|
|
@@ -110,7 +109,7 @@ module Mongo
|
|
|
110
109
|
user.password,
|
|
111
110
|
user.auth_mech_properties['aws_session_token']
|
|
112
111
|
)
|
|
113
|
-
|
|
112
|
+
credentials if credentials_valid?(credentials, 'Mongo::Client URI or Ruby options')
|
|
114
113
|
end
|
|
115
114
|
|
|
116
115
|
# Returns credentials from environment variables.
|
|
@@ -138,14 +137,17 @@ module Mongo
|
|
|
138
137
|
#
|
|
139
138
|
# @raise Auth::InvalidConfiguration if a source contains an invalid set
|
|
140
139
|
# of credentials.
|
|
141
|
-
# @
|
|
140
|
+
# @raise Error::TimeoutError if credentials cannot be retrieved within
|
|
142
141
|
# the timeout defined on the operation context.
|
|
143
142
|
def obtain_credentials_from_endpoints(timeout_holder = nil)
|
|
144
|
-
if (credentials = web_identity_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
143
|
+
if (credentials = web_identity_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
144
|
+
'Web identity token')
|
|
145
145
|
credentials
|
|
146
|
-
elsif (credentials = ecs_metadata_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
146
|
+
elsif (credentials = ecs_metadata_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
147
|
+
'ECS task metadata')
|
|
147
148
|
credentials
|
|
148
|
-
elsif (credentials = ec2_metadata_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
149
|
+
elsif (credentials = ec2_metadata_credentials(timeout_holder)) && credentials_valid?(credentials,
|
|
150
|
+
'EC2 instance metadata')
|
|
149
151
|
credentials
|
|
150
152
|
end
|
|
151
153
|
end
|
|
@@ -157,39 +159,35 @@ module Mongo
|
|
|
157
159
|
#
|
|
158
160
|
# @return [ Auth::Aws::Credentials | nil ] A set of credentials, or nil
|
|
159
161
|
# if retrieval failed.
|
|
160
|
-
# @
|
|
162
|
+
# @raise Error::TimeoutError if credentials cannot be retrieved within
|
|
161
163
|
# the timeout.
|
|
162
164
|
def ec2_metadata_credentials(timeout_holder = nil)
|
|
163
165
|
timeout_holder&.check_timeout!
|
|
164
166
|
http = Net::HTTP.new('169.254.169.254')
|
|
165
167
|
req = Net::HTTP::Put.new('/latest/api/token',
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
# The TTL is required in order to obtain the metadata token.
|
|
169
|
+
{ 'x-aws-ec2-metadata-token-ttl-seconds' => '30' })
|
|
168
170
|
resp = with_timeout(timeout_holder) do
|
|
169
171
|
http.request(req)
|
|
170
172
|
end
|
|
171
|
-
if resp.code != '200'
|
|
172
|
-
|
|
173
|
-
end
|
|
173
|
+
return nil if resp.code != '200'
|
|
174
|
+
|
|
174
175
|
metadata_token = resp.body
|
|
175
176
|
resp = with_timeout(timeout_holder) do
|
|
176
177
|
http_get(http, '/latest/meta-data/iam/security-credentials', metadata_token)
|
|
177
178
|
end
|
|
178
|
-
if resp.code != '200'
|
|
179
|
-
|
|
180
|
-
end
|
|
179
|
+
return nil if resp.code != '200'
|
|
180
|
+
|
|
181
181
|
role_name = resp.body
|
|
182
182
|
escaped_role_name = CGI.escape(role_name).gsub('+', '%20')
|
|
183
183
|
resp = with_timeout(timeout_holder) do
|
|
184
184
|
http_get(http, "/latest/meta-data/iam/security-credentials/#{escaped_role_name}", metadata_token)
|
|
185
185
|
end
|
|
186
|
-
if resp.code != '200'
|
|
187
|
-
|
|
188
|
-
end
|
|
186
|
+
return nil if resp.code != '200'
|
|
187
|
+
|
|
189
188
|
payload = JSON.parse(resp.body)
|
|
190
|
-
unless payload['Code'] == 'Success'
|
|
191
|
-
|
|
192
|
-
end
|
|
189
|
+
return nil unless payload['Code'] == 'Success'
|
|
190
|
+
|
|
193
191
|
Credentials.new(
|
|
194
192
|
payload['AccessKeyId'],
|
|
195
193
|
payload['SecretAccessKey'],
|
|
@@ -199,7 +197,7 @@ module Mongo
|
|
|
199
197
|
# When trying to use the EC2 metadata endpoint on ECS:
|
|
200
198
|
# Errno::EINVAL: Failed to open TCP connection to 169.254.169.254:80 (Invalid argument - connect(2) for "169.254.169.254" port 80)
|
|
201
199
|
rescue ::Timeout::Error, IOError, SystemCallError, TypeError
|
|
202
|
-
|
|
200
|
+
nil
|
|
203
201
|
end
|
|
204
202
|
|
|
205
203
|
# Returns credentials from the ECS metadata endpoint. The credentials
|
|
@@ -209,14 +207,12 @@ module Mongo
|
|
|
209
207
|
#
|
|
210
208
|
# @return [ Auth::Aws::Credentials | nil ] A set of credentials, or nil
|
|
211
209
|
# if retrieval failed.
|
|
212
|
-
# @
|
|
210
|
+
# @raise Error::TimeoutError if credentials cannot be retrieved within
|
|
213
211
|
# the timeout defined on the operation context.
|
|
214
212
|
def ecs_metadata_credentials(timeout_holder = nil)
|
|
215
213
|
timeout_holder&.check_timeout!
|
|
216
214
|
relative_uri = ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
|
|
217
|
-
if relative_uri.nil? || relative_uri.empty?
|
|
218
|
-
return nil
|
|
219
|
-
end
|
|
215
|
+
return nil if relative_uri.nil? || relative_uri.empty?
|
|
220
216
|
|
|
221
217
|
http = Net::HTTP.new('169.254.170.2')
|
|
222
218
|
# Per https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
|
|
@@ -229,9 +225,8 @@ module Mongo
|
|
|
229
225
|
resp = with_timeout(timeout_holder) do
|
|
230
226
|
http.request(req)
|
|
231
227
|
end
|
|
232
|
-
if resp.code != '200'
|
|
233
|
-
|
|
234
|
-
end
|
|
228
|
+
return nil if resp.code != '200'
|
|
229
|
+
|
|
235
230
|
payload = JSON.parse(resp.body)
|
|
236
231
|
Credentials.new(
|
|
237
232
|
payload['AccessKeyId'],
|
|
@@ -240,7 +235,7 @@ module Mongo
|
|
|
240
235
|
DateTime.parse(payload['Expiration']).to_time
|
|
241
236
|
)
|
|
242
237
|
rescue ::Timeout::Error, IOError, SystemCallError, TypeError
|
|
243
|
-
|
|
238
|
+
nil
|
|
244
239
|
end
|
|
245
240
|
|
|
246
241
|
# Returns credentials associated with web identity token that is
|
|
@@ -255,10 +250,12 @@ module Mongo
|
|
|
255
250
|
def web_identity_credentials(timeout_holder = nil)
|
|
256
251
|
web_identity_token, role_arn, role_session_name = prepare_web_identity_inputs
|
|
257
252
|
return nil if web_identity_token.nil?
|
|
253
|
+
|
|
258
254
|
response = request_web_identity_credentials(
|
|
259
255
|
web_identity_token, role_arn, role_session_name, timeout_holder
|
|
260
256
|
)
|
|
261
257
|
return if response.nil?
|
|
258
|
+
|
|
262
259
|
credentials_from_web_identity_response(response)
|
|
263
260
|
end
|
|
264
261
|
|
|
@@ -269,15 +266,12 @@ module Mongo
|
|
|
269
266
|
def prepare_web_identity_inputs
|
|
270
267
|
token_file = ENV['AWS_WEB_IDENTITY_TOKEN_FILE']
|
|
271
268
|
role_arn = ENV['AWS_ROLE_ARN']
|
|
272
|
-
if token_file.nil? || role_arn.nil?
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
web_identity_token = File.open(token_file).read
|
|
269
|
+
return nil if token_file.nil? || role_arn.nil?
|
|
270
|
+
|
|
271
|
+
web_identity_token = File.read(token_file)
|
|
276
272
|
role_session_name = ENV['AWS_ROLE_SESSION_NAME']
|
|
277
|
-
if role_session_name.nil?
|
|
278
|
-
|
|
279
|
-
end
|
|
280
|
-
[web_identity_token, role_arn, role_session_name]
|
|
273
|
+
role_session_name = "ruby-app-#{SecureRandom.alphanumeric(50)}" if role_session_name.nil?
|
|
274
|
+
[ web_identity_token, role_arn, role_session_name ]
|
|
281
275
|
rescue Errno::ENOENT, IOError, SystemCallError
|
|
282
276
|
nil
|
|
283
277
|
end
|
|
@@ -296,7 +290,7 @@ module Mongo
|
|
|
296
290
|
# @return [ Net::HTTPResponse | nil ] AWS API response if successful,
|
|
297
291
|
# otherwise nil.
|
|
298
292
|
#
|
|
299
|
-
# @
|
|
293
|
+
# @raise Error::TimeoutError if credentials cannot be retrieved within
|
|
300
294
|
# the timeout defined on the operation context.
|
|
301
295
|
def request_web_identity_credentials(token, role_arn, role_session_name, timeout_holder)
|
|
302
296
|
timeout_holder&.check_timeout!
|
|
@@ -316,9 +310,8 @@ module Mongo
|
|
|
316
310
|
https.request(req)
|
|
317
311
|
end
|
|
318
312
|
end
|
|
319
|
-
if resp.code != '200'
|
|
320
|
-
|
|
321
|
-
end
|
|
313
|
+
return nil if resp.code != '200'
|
|
314
|
+
|
|
322
315
|
resp
|
|
323
316
|
rescue Errno::ENOENT, IOError, SystemCallError
|
|
324
317
|
nil
|
|
@@ -349,7 +342,7 @@ module Mongo
|
|
|
349
342
|
|
|
350
343
|
def http_get(http, uri, metadata_token)
|
|
351
344
|
req = Net::HTTP::Get.new(uri,
|
|
352
|
-
|
|
345
|
+
{ 'x-aws-ec2-metadata-token' => metadata_token })
|
|
353
346
|
http.request(req)
|
|
354
347
|
end
|
|
355
348
|
|
|
@@ -360,25 +353,24 @@ module Mongo
|
|
|
360
353
|
# incomplete (i.e. some of the components are missing).
|
|
361
354
|
def credentials_valid?(credentials, source)
|
|
362
355
|
unless credentials.access_key_id || credentials.secret_access_key ||
|
|
363
|
-
|
|
364
|
-
then
|
|
356
|
+
credentials.session_token
|
|
365
357
|
return false
|
|
366
358
|
end
|
|
367
359
|
|
|
368
360
|
if credentials.access_key_id || credentials.secret_access_key
|
|
369
361
|
if credentials.access_key_id && !credentials.secret_access_key
|
|
370
362
|
raise Auth::InvalidConfiguration,
|
|
371
|
-
|
|
363
|
+
"Access key ID is provided without secret access key (source: #{source})"
|
|
372
364
|
end
|
|
373
365
|
|
|
374
366
|
if credentials.secret_access_key && !credentials.access_key_id
|
|
375
367
|
raise Auth::InvalidConfiguration,
|
|
376
|
-
|
|
368
|
+
"Secret access key is provided without access key ID (source: #{source})"
|
|
377
369
|
end
|
|
378
370
|
|
|
379
371
|
elsif credentials.session_token
|
|
380
372
|
raise Auth::InvalidConfiguration,
|
|
381
|
-
|
|
373
|
+
"Session token is provided without access key ID or secret access key (source: #{source})"
|
|
382
374
|
end
|
|
383
375
|
|
|
384
376
|
true
|
|
@@ -392,17 +384,11 @@ module Mongo
|
|
|
392
384
|
#
|
|
393
385
|
# @param [ CsotTimeoutHolder | nil ] timeout_holder CSOT timeout.
|
|
394
386
|
#
|
|
395
|
-
# @
|
|
396
|
-
def with_timeout(timeout_holder)
|
|
387
|
+
# @raise Error::TimeoutError if deadline exceeded.
|
|
388
|
+
def with_timeout(timeout_holder, &block)
|
|
397
389
|
timeout = timeout_holder&.remaining_timeout_sec! || METADATA_TIMEOUT
|
|
398
|
-
exception_class = if timeout_holder&.csot?
|
|
399
|
-
|
|
400
|
-
else
|
|
401
|
-
nil
|
|
402
|
-
end
|
|
403
|
-
::Timeout.timeout(timeout, exception_class) do
|
|
404
|
-
yield
|
|
405
|
-
end
|
|
390
|
+
exception_class = (Error::TimeoutError if timeout_holder&.csot?)
|
|
391
|
+
::Timeout.timeout(timeout, exception_class, &block)
|
|
406
392
|
end
|
|
407
393
|
end
|
|
408
394
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -22,7 +21,6 @@ end
|
|
|
22
21
|
module Mongo
|
|
23
22
|
module Auth
|
|
24
23
|
class Aws
|
|
25
|
-
|
|
26
24
|
# Helper class for working with AWS requests.
|
|
27
25
|
#
|
|
28
26
|
# The primary purpose of this class is to produce the canonical AWS
|
|
@@ -30,11 +28,10 @@ module Mongo
|
|
|
30
28
|
#
|
|
31
29
|
# @api private
|
|
32
30
|
class Request
|
|
33
|
-
|
|
34
31
|
# The body of the STS GetCallerIdentity request.
|
|
35
32
|
#
|
|
36
33
|
# This is currently the only request that this class supports making.
|
|
37
|
-
STS_REQUEST_BODY =
|
|
34
|
+
STS_REQUEST_BODY = 'Action=GetCallerIdentity&Version=2011-06-15'
|
|
38
35
|
|
|
39
36
|
# The timeout, in seconds, to use for validating credentials via STS.
|
|
40
37
|
VALIDATE_TIMEOUT = 10
|
|
@@ -51,9 +48,7 @@ module Mongo
|
|
|
51
48
|
# @param [ String ] host The value of Host HTTP header to use.
|
|
52
49
|
# @param [ String ] server_nonce The server nonce binary string.
|
|
53
50
|
# @param [ Time ] time The time of the request.
|
|
54
|
-
def initialize(access_key_id:, secret_access_key:, session_token: nil,
|
|
55
|
-
host:, server_nonce:, time: Time.now
|
|
56
|
-
)
|
|
51
|
+
def initialize(access_key_id:, secret_access_key:, host:, server_nonce:, session_token: nil, time: Time.now)
|
|
57
52
|
@access_key_id = access_key_id
|
|
58
53
|
@secret_access_key = secret_access_key
|
|
59
54
|
@session_token = session_token
|
|
@@ -61,16 +56,14 @@ module Mongo
|
|
|
61
56
|
@server_nonce = server_nonce
|
|
62
57
|
@time = time
|
|
63
58
|
|
|
64
|
-
%i
|
|
59
|
+
%i[access_key_id secret_access_key host server_nonce].each do |arg|
|
|
65
60
|
value = instance_variable_get("@#{arg}")
|
|
66
|
-
if value.nil? || value.empty?
|
|
67
|
-
raise Error::InvalidServerAuthResponse, "Value for '#{arg}' is required"
|
|
68
|
-
end
|
|
61
|
+
raise Error::InvalidServerAuthResponse, "Value for '#{arg}' is required" if value.nil? || value.empty?
|
|
69
62
|
end
|
|
70
63
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
return unless host && host.length > 255
|
|
65
|
+
|
|
66
|
+
raise Error::InvalidServerAuthHost, "Value for 'host' is too long: #{@host}"
|
|
74
67
|
end
|
|
75
68
|
|
|
76
69
|
# @return [ String ] access_key_id The access key id.
|
|
@@ -106,16 +99,10 @@ module Mongo
|
|
|
106
99
|
# @return [ String ] region The region of the host, derived from the host.
|
|
107
100
|
def region
|
|
108
101
|
# Common case
|
|
109
|
-
if host == 'sts.amazonaws.com'
|
|
110
|
-
return 'us-east-1'
|
|
111
|
-
end
|
|
102
|
+
return 'us-east-1' if host == 'sts.amazonaws.com'
|
|
112
103
|
|
|
113
|
-
if host.start_with?('.')
|
|
114
|
-
|
|
115
|
-
end
|
|
116
|
-
if host.end_with?('.')
|
|
117
|
-
raise Error::InvalidServerAuthHost, "Host ends with a period: #{host}"
|
|
118
|
-
end
|
|
104
|
+
raise Error::InvalidServerAuthHost, "Host begins with a period: #{host}" if host.start_with?('.')
|
|
105
|
+
raise Error::InvalidServerAuthHost, "Host ends with a period: #{host}" if host.end_with?('.')
|
|
119
106
|
|
|
120
107
|
parts = host.split('.')
|
|
121
108
|
if parts.any? { |part| part.empty? }
|
|
@@ -151,11 +138,9 @@ module Mongo
|
|
|
151
138
|
'host' => host,
|
|
152
139
|
'x-amz-date' => formatted_time,
|
|
153
140
|
'x-mongodb-gs2-cb-flag' => 'n',
|
|
154
|
-
'x-mongodb-server-nonce' => Base64.encode64(server_nonce).
|
|
141
|
+
'x-mongodb-server-nonce' => Base64.encode64(server_nonce).delete("\n"),
|
|
155
142
|
}
|
|
156
|
-
if session_token
|
|
157
|
-
headers['x-amz-security-token'] = session_token
|
|
158
|
-
end
|
|
143
|
+
headers['x-amz-security-token'] = session_token if session_token
|
|
159
144
|
headers
|
|
160
145
|
end
|
|
161
146
|
|
|
@@ -216,9 +201,9 @@ module Mongo
|
|
|
216
201
|
def signature
|
|
217
202
|
hashed_canonical_request = Digest::SHA256.hexdigest(canonical_request)
|
|
218
203
|
string_to_sign = "AWS4-HMAC-SHA256\n" +
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
204
|
+
"#{formatted_time}\n" +
|
|
205
|
+
"#{scope}\n" +
|
|
206
|
+
hashed_canonical_request
|
|
222
207
|
# All of the intermediate HMAC operations are not hex-encoded.
|
|
223
208
|
mac = hmac("AWS4#{secret_access_key}", formatted_date)
|
|
224
209
|
mac = hmac(mac, region)
|
|
@@ -252,7 +237,8 @@ module Mongo
|
|
|
252
237
|
http = Net::HTTP.new(host, 443)
|
|
253
238
|
http.use_ssl = true
|
|
254
239
|
http.start do
|
|
255
|
-
resp = Timeout.timeout(VALIDATE_TIMEOUT, Error::CredentialCheckError,
|
|
240
|
+
resp = Timeout.timeout(VALIDATE_TIMEOUT, Error::CredentialCheckError,
|
|
241
|
+
'GetCallerIdentity request timed out') do
|
|
256
242
|
http.request(sts_request)
|
|
257
243
|
end
|
|
258
244
|
payload = JSON.parse(resp.body)
|
|
@@ -261,7 +247,7 @@ module Mongo
|
|
|
261
247
|
aws_message = payload.fetch('Error').fetch('Message')
|
|
262
248
|
msg = "Credential check for user #{access_key_id} failed with HTTP status code #{resp.code}: #{aws_code}: #{aws_message}"
|
|
263
249
|
msg += '.' unless msg.end_with?('.')
|
|
264
|
-
msg +=
|
|
250
|
+
msg += ' Please check that the credentials are valid, and if they are temporary (i.e. use the session token) that the session token is provided and not expired'
|
|
265
251
|
raise Error::CredentialCheckError, msg
|
|
266
252
|
end
|
|
267
253
|
payload.fetch('GetCallerIdentityResponse').fetch('GetCallerIdentityResult')
|
|
@@ -271,13 +257,12 @@ module Mongo
|
|
|
271
257
|
private
|
|
272
258
|
|
|
273
259
|
def hmac(key, data)
|
|
274
|
-
OpenSSL::HMAC.digest(
|
|
260
|
+
OpenSSL::HMAC.digest('SHA256', key, data)
|
|
275
261
|
end
|
|
276
262
|
|
|
277
263
|
def hmac_hex(key, data)
|
|
278
|
-
OpenSSL::HMAC.hexdigest(
|
|
264
|
+
OpenSSL::HMAC.hexdigest('SHA256', key, data)
|
|
279
265
|
end
|
|
280
|
-
|
|
281
266
|
end
|
|
282
267
|
end
|
|
283
268
|
end
|
data/lib/mongo/auth/aws.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -18,7 +17,7 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Auth
|
|
20
19
|
class Aws < Base
|
|
21
|
-
MECHANISM = 'MONGODB-AWS'
|
|
20
|
+
MECHANISM = 'MONGODB-AWS'
|
|
22
21
|
|
|
23
22
|
# Log the user in on the current connection.
|
|
24
23
|
#
|
data/lib/mongo/auth/base.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,7 +16,6 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Auth
|
|
20
|
-
|
|
21
19
|
# Base class for authenticators.
|
|
22
20
|
#
|
|
23
21
|
# Each authenticator is instantiated for authentication over a particular
|
|
@@ -25,7 +23,6 @@ module Mongo
|
|
|
25
23
|
#
|
|
26
24
|
# @api private
|
|
27
25
|
class Base
|
|
28
|
-
|
|
29
26
|
# @return [ Mongo::Auth::User ] The user to authenticate.
|
|
30
27
|
attr_reader :user
|
|
31
28
|
|
|
@@ -37,7 +34,7 @@ module Mongo
|
|
|
37
34
|
# @param [ Auth::User ] user The user to authenticate.
|
|
38
35
|
# @param [ Mongo::Connection ] connection The connection to authenticate
|
|
39
36
|
# over.
|
|
40
|
-
def initialize(user, connection, **
|
|
37
|
+
def initialize(user, connection, **_opts)
|
|
41
38
|
@user = user
|
|
42
39
|
@connection = connection
|
|
43
40
|
end
|
|
@@ -74,8 +71,7 @@ module Mongo
|
|
|
74
71
|
# value of speculativeAuthenticate field of hello response of
|
|
75
72
|
# the handshake on the specified connection.
|
|
76
73
|
def converse_multi_step(connection, conversation,
|
|
77
|
-
|
|
78
|
-
)
|
|
74
|
+
speculative_auth_result: nil)
|
|
79
75
|
# Although the SASL conversation in theory can have any number of
|
|
80
76
|
# steps, all defined authentication methods have a predefined number
|
|
81
77
|
# of steps, and therefore all of our authenticators have a fixed set
|
|
@@ -97,26 +93,22 @@ module Mongo
|
|
|
97
93
|
end
|
|
98
94
|
unless reply_document[:done]
|
|
99
95
|
raise Error::InvalidServerAuthResponse,
|
|
100
|
-
|
|
96
|
+
'Server did not respond with {done: true} after finalizing the conversation'
|
|
101
97
|
end
|
|
102
98
|
reply_document
|
|
103
99
|
end
|
|
104
100
|
|
|
105
101
|
def dispatch_msg(connection, conversation, msg)
|
|
106
102
|
context = Operation::Context.new(options: {
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
server_api: connection.options[:server_api],
|
|
104
|
+
})
|
|
109
105
|
if server_api = context.server_api
|
|
110
106
|
msg = msg.maybe_add_server_api(server_api)
|
|
111
107
|
end
|
|
112
|
-
reply = connection.dispatch([msg], context)
|
|
108
|
+
reply = connection.dispatch([ msg ], context)
|
|
113
109
|
reply_document = reply.documents.first
|
|
114
110
|
validate_reply!(connection, conversation, reply_document)
|
|
115
|
-
connection_global_id = if connection.respond_to?(:global_id)
|
|
116
|
-
connection.global_id
|
|
117
|
-
else
|
|
118
|
-
nil
|
|
119
|
-
end
|
|
111
|
+
connection_global_id = (connection.global_id if connection.respond_to?(:global_id))
|
|
120
112
|
result = Operation::Result.new(reply, connection.description, connection_global_id, context: context)
|
|
121
113
|
connection.update_cluster_time(result)
|
|
122
114
|
reply_document
|
|
@@ -124,21 +116,20 @@ module Mongo
|
|
|
124
116
|
|
|
125
117
|
# Checks whether reply is successful (i.e. has {ok: 1} set) and
|
|
126
118
|
# raises Unauthorized if not.
|
|
127
|
-
def validate_reply!(connection,
|
|
128
|
-
|
|
129
|
-
message = Error::Parser.build_message(
|
|
130
|
-
code: doc[:code],
|
|
131
|
-
code_name: doc[:codeName],
|
|
132
|
-
message: doc[:errmsg],
|
|
133
|
-
)
|
|
119
|
+
def validate_reply!(connection, _conversation, doc)
|
|
120
|
+
return unless doc[:ok] != 1
|
|
134
121
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
122
|
+
message = Error::Parser.build_message(
|
|
123
|
+
code: doc[:code],
|
|
124
|
+
code_name: doc[:codeName],
|
|
125
|
+
message: doc[:errmsg]
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
raise Unauthorized.new(user,
|
|
129
|
+
used_mechanism: self.class.const_get(:MECHANISM),
|
|
130
|
+
message: message,
|
|
131
|
+
server: connection.server,
|
|
132
|
+
code: doc[:code])
|
|
142
133
|
end
|
|
143
134
|
end
|
|
144
135
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,19 +16,17 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Auth
|
|
20
|
-
|
|
21
19
|
# Defines common behavior around authentication conversations between
|
|
22
20
|
# the client and the server.
|
|
23
21
|
#
|
|
24
22
|
# @api private
|
|
25
23
|
class ConversationBase
|
|
26
|
-
|
|
27
24
|
# Create the new conversation.
|
|
28
25
|
#
|
|
29
26
|
# @param [ Auth::User ] user The user to authenticate.
|
|
30
27
|
# @param [ Mongo::Connection ] connection The connection to authenticate
|
|
31
28
|
# over.
|
|
32
|
-
def initialize(user, connection, **
|
|
29
|
+
def initialize(user, connection, **_opts)
|
|
33
30
|
@user = user
|
|
34
31
|
@connection = connection
|
|
35
32
|
end
|
|
@@ -53,34 +50,33 @@ module Mongo
|
|
|
53
50
|
|
|
54
51
|
# @return [ Protocol::Message ] The message to send.
|
|
55
52
|
def build_message(connection, auth_source, selector)
|
|
56
|
-
if connection
|
|
53
|
+
if connection
|
|
57
54
|
selector = selector.dup
|
|
58
55
|
selector[Protocol::Msg::DATABASE_IDENTIFIER] = auth_source
|
|
59
56
|
cluster_time = connection.mongos? && connection.cluster_time
|
|
60
|
-
if cluster_time
|
|
61
|
-
selector[Operation::CLUSTER_TIME] = cluster_time
|
|
62
|
-
end
|
|
57
|
+
selector[Operation::CLUSTER_TIME] = cluster_time if cluster_time
|
|
63
58
|
Protocol::Msg.new([], {}, selector)
|
|
64
59
|
else
|
|
65
60
|
Protocol::Query.new(
|
|
66
61
|
auth_source,
|
|
67
62
|
Database::COMMAND,
|
|
68
63
|
selector,
|
|
69
|
-
limit: -1
|
|
64
|
+
limit: -1
|
|
70
65
|
)
|
|
71
66
|
end
|
|
72
67
|
end
|
|
73
68
|
|
|
74
69
|
def validate_external_auth_source
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
70
|
+
return unless user.auth_source != '$external'
|
|
71
|
+
|
|
72
|
+
user_name_msg = if user.name
|
|
73
|
+
" #{user.name}"
|
|
74
|
+
else
|
|
75
|
+
''
|
|
76
|
+
end
|
|
77
|
+
mechanism = user.mechanism
|
|
78
|
+
raise Auth::InvalidConfiguration,
|
|
79
|
+
"User#{user_name_msg} specifies auth source '#{user.auth_source}', but the only valid auth source for #{mechanism} is '$external'"
|
|
84
80
|
end
|
|
85
81
|
end
|
|
86
82
|
end
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -18,7 +17,6 @@
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Auth
|
|
20
19
|
class CR
|
|
21
|
-
|
|
22
20
|
# Defines behavior around a single MONGODB-CR conversation between the
|
|
23
21
|
# client and server.
|
|
24
22
|
#
|
|
@@ -28,7 +26,6 @@ module Mongo
|
|
|
28
26
|
# removed in driver version 3.0. Please use SCRAM instead.
|
|
29
27
|
# @api private
|
|
30
28
|
class Conversation < ConversationBase
|
|
31
|
-
|
|
32
29
|
# The login message base.
|
|
33
30
|
#
|
|
34
31
|
# @since 2.0.0
|
data/lib/mongo/auth/cr.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
# Copyright (C) 2014-2020 MongoDB Inc.
|
|
5
4
|
#
|
|
@@ -17,7 +16,6 @@
|
|
|
17
16
|
|
|
18
17
|
module Mongo
|
|
19
18
|
module Auth
|
|
20
|
-
|
|
21
19
|
# Defines behavior for MongoDB-CR authentication.
|
|
22
20
|
#
|
|
23
21
|
# @since 2.0.0
|
|
@@ -26,11 +24,10 @@ module Mongo
|
|
|
26
24
|
# removed in driver version 3.0. Please use SCRAM instead.
|
|
27
25
|
# @api private
|
|
28
26
|
class CR < Base
|
|
29
|
-
|
|
30
27
|
# The authentication mechanism string.
|
|
31
28
|
#
|
|
32
29
|
# @since 2.0.0
|
|
33
|
-
MECHANISM = 'MONGODB-CR'
|
|
30
|
+
MECHANISM = 'MONGODB-CR'
|
|
34
31
|
|
|
35
32
|
# Log the user in on the current connection.
|
|
36
33
|
#
|