mongo 2.22.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.
Files changed (467) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mongo_console +0 -1
  3. data/lib/mongo/active_support.rb +1 -2
  4. data/lib/mongo/address/ipv4.rb +3 -6
  5. data/lib/mongo/address/ipv6.rb +6 -10
  6. data/lib/mongo/address/unix.rb +1 -4
  7. data/lib/mongo/address/validator.rb +16 -28
  8. data/lib/mongo/address.rb +30 -40
  9. data/lib/mongo/auth/aws/conversation.rb +6 -10
  10. data/lib/mongo/auth/aws/credentials.rb +0 -1
  11. data/lib/mongo/auth/aws/credentials_cache.rb +0 -1
  12. data/lib/mongo/auth/aws/credentials_retriever.rb +45 -59
  13. data/lib/mongo/auth/aws/request.rb +20 -35
  14. data/lib/mongo/auth/aws.rb +1 -2
  15. data/lib/mongo/auth/base.rb +20 -29
  16. data/lib/mongo/auth/conversation_base.rb +14 -18
  17. data/lib/mongo/auth/cr/conversation.rb +0 -3
  18. data/lib/mongo/auth/cr.rb +1 -4
  19. data/lib/mongo/auth/credential_cache.rb +0 -2
  20. data/lib/mongo/auth/gssapi/conversation.rb +3 -8
  21. data/lib/mongo/auth/gssapi.rb +1 -4
  22. data/lib/mongo/auth/ldap/conversation.rb +0 -3
  23. data/lib/mongo/auth/ldap.rb +1 -4
  24. data/lib/mongo/auth/roles.rb +16 -19
  25. data/lib/mongo/auth/sasl_conversation_base.rb +7 -11
  26. data/lib/mongo/auth/scram/conversation.rb +2 -5
  27. data/lib/mongo/auth/scram.rb +5 -10
  28. data/lib/mongo/auth/scram256/conversation.rb +2 -5
  29. data/lib/mongo/auth/scram256.rb +1 -3
  30. data/lib/mongo/auth/scram_conversation_base.rb +18 -24
  31. data/lib/mongo/auth/stringprep/profiles/sasl.rb +17 -18
  32. data/lib/mongo/auth/stringprep/tables.rb +2209 -2210
  33. data/lib/mongo/auth/stringprep/unicode_normalize/normalize.rb +36 -38
  34. data/lib/mongo/auth/stringprep/unicode_normalize/tables.rb +1142 -1150
  35. data/lib/mongo/auth/stringprep.rb +9 -12
  36. data/lib/mongo/auth/user/view.rb +3 -5
  37. data/lib/mongo/auth/user.rb +14 -24
  38. data/lib/mongo/auth/x509/conversation.rb +0 -3
  39. data/lib/mongo/auth/x509.rb +7 -9
  40. data/lib/mongo/auth.rb +18 -30
  41. data/lib/mongo/background_thread.rb +9 -17
  42. data/lib/mongo/bson.rb +0 -2
  43. data/lib/mongo/bulk_write/combineable.rb +0 -3
  44. data/lib/mongo/bulk_write/ordered_combiner.rb +1 -3
  45. data/lib/mongo/bulk_write/result.rb +11 -16
  46. data/lib/mongo/bulk_write/result_combiner.rb +9 -12
  47. data/lib/mongo/bulk_write/transformable.rb +16 -19
  48. data/lib/mongo/bulk_write/unordered_combiner.rb +1 -3
  49. data/lib/mongo/bulk_write/validatable.rb +11 -18
  50. data/lib/mongo/bulk_write.rb +76 -91
  51. data/lib/mongo/caching_cursor.rb +2 -7
  52. data/lib/mongo/client.rb +267 -276
  53. data/lib/mongo/client_encryption.rb +4 -5
  54. data/lib/mongo/cluster/periodic_executor.rb +2 -5
  55. data/lib/mongo/cluster/reapers/cursor_reaper.rb +21 -29
  56. data/lib/mongo/cluster/reapers/socket_reaper.rb +1 -6
  57. data/lib/mongo/cluster/sdam_flow.rb +136 -159
  58. data/lib/mongo/cluster/topology/base.rb +15 -18
  59. data/lib/mongo/cluster/topology/load_balanced.rb +24 -14
  60. data/lib/mongo/cluster/topology/no_replica_set_options.rb +3 -6
  61. data/lib/mongo/cluster/topology/replica_set_no_primary.rb +20 -23
  62. data/lib/mongo/cluster/topology/replica_set_with_primary.rb +0 -2
  63. data/lib/mongo/cluster/topology/sharded.rb +19 -9
  64. data/lib/mongo/cluster/topology/single.rb +24 -14
  65. data/lib/mongo/cluster/topology/unknown.rb +20 -10
  66. data/lib/mongo/cluster/topology.rb +29 -25
  67. data/lib/mongo/cluster.rb +152 -184
  68. data/lib/mongo/cluster_time.rb +14 -31
  69. data/lib/mongo/collection/helpers.rb +5 -8
  70. data/lib/mongo/collection/view/aggregation/behavior.rb +1 -1
  71. data/lib/mongo/collection/view/aggregation.rb +10 -12
  72. data/lib/mongo/collection/view/builder/aggregation.rb +6 -9
  73. data/lib/mongo/collection/view/builder/map_reduce.rb +18 -17
  74. data/lib/mongo/collection/view/builder.rb +0 -1
  75. data/lib/mongo/collection/view/change_stream/retryable.rb +3 -8
  76. data/lib/mongo/collection/view/change_stream.rb +59 -58
  77. data/lib/mongo/collection/view/explainable.rb +11 -20
  78. data/lib/mongo/collection/view/immutable.rb +1 -3
  79. data/lib/mongo/collection/view/iterable.rb +44 -35
  80. data/lib/mongo/collection/view/map_reduce.rb +20 -25
  81. data/lib/mongo/collection/view/readable.rb +96 -94
  82. data/lib/mongo/collection/view/writable.rb +104 -114
  83. data/lib/mongo/collection/view.rb +11 -8
  84. data/lib/mongo/collection.rb +103 -106
  85. data/lib/mongo/condition_variable.rb +4 -4
  86. data/lib/mongo/config/options.rb +0 -3
  87. data/lib/mongo/config/validators/option.rb +3 -5
  88. data/lib/mongo/config.rb +6 -4
  89. data/lib/mongo/crypt/auto_decryption_context.rb +9 -3
  90. data/lib/mongo/crypt/auto_encrypter.rb +34 -43
  91. data/lib/mongo/crypt/auto_encryption_context.rb +0 -3
  92. data/lib/mongo/crypt/binary.rb +5 -9
  93. data/lib/mongo/crypt/binding.rb +150 -156
  94. data/lib/mongo/crypt/context.rb +20 -17
  95. data/lib/mongo/crypt/data_key_context.rb +2 -7
  96. data/lib/mongo/crypt/encryption_io.rb +29 -39
  97. data/lib/mongo/crypt/explicit_decryption_context.rb +9 -3
  98. data/lib/mongo/crypt/explicit_encrypter.rb +1 -1
  99. data/lib/mongo/crypt/explicit_encryption_context.rb +19 -30
  100. data/lib/mongo/crypt/explicit_encryption_expression_context.rb +0 -2
  101. data/lib/mongo/crypt/handle.rb +42 -48
  102. data/lib/mongo/crypt/hooks.rb +12 -15
  103. data/lib/mongo/crypt/kms/aws/credentials.rb +12 -16
  104. data/lib/mongo/crypt/kms/aws/master_document.rb +6 -9
  105. data/lib/mongo/crypt/kms/aws.rb +0 -2
  106. data/lib/mongo/crypt/kms/azure/credentials_retriever.rb +2 -7
  107. data/lib/mongo/crypt/kms/azure/master_document.rb +15 -19
  108. data/lib/mongo/crypt/kms/azure.rb +0 -1
  109. data/lib/mongo/crypt/kms/credentials.rb +13 -27
  110. data/lib/mongo/crypt/kms/gcp/credentials.rb +12 -14
  111. data/lib/mongo/crypt/kms/gcp/credentials_retriever.rb +7 -9
  112. data/lib/mongo/crypt/kms/gcp/master_document.rb +12 -16
  113. data/lib/mongo/crypt/kms/gcp.rb +0 -2
  114. data/lib/mongo/crypt/kms/kmip/credentials.rb +7 -8
  115. data/lib/mongo/crypt/kms/kmip/master_document.rb +3 -5
  116. data/lib/mongo/crypt/kms/kmip.rb +0 -1
  117. data/lib/mongo/crypt/kms/local/credentials.rb +7 -8
  118. data/lib/mongo/crypt/kms/local/master_document.rb +2 -6
  119. data/lib/mongo/crypt/kms/local.rb +0 -1
  120. data/lib/mongo/crypt/kms/master_key_document.rb +11 -15
  121. data/lib/mongo/crypt/kms.rb +14 -16
  122. data/lib/mongo/crypt/kms_context.rb +0 -2
  123. data/lib/mongo/crypt/rewrap_many_data_key_context.rb +2 -7
  124. data/lib/mongo/crypt/rewrap_many_data_key_result.rb +2 -4
  125. data/lib/mongo/crypt/status.rb +12 -14
  126. data/lib/mongo/crypt.rb +0 -1
  127. data/lib/mongo/csot_timeout_holder.rb +3 -2
  128. data/lib/mongo/cursor/kill_spec.rb +7 -10
  129. data/lib/mongo/cursor.rb +74 -64
  130. data/lib/mongo/cursor_host.rb +8 -10
  131. data/lib/mongo/database/view.rb +23 -39
  132. data/lib/mongo/database.rb +68 -65
  133. data/lib/mongo/dbref.rb +0 -1
  134. data/lib/mongo/deprecations.rb +98 -0
  135. data/lib/mongo/distinguishing_semaphore.rb +0 -1
  136. data/lib/mongo/error/auth_error.rb +0 -2
  137. data/lib/mongo/error/bad_load_balancer_target.rb +0 -2
  138. data/lib/mongo/error/bulk_write_error.rb +7 -10
  139. data/lib/mongo/error/change_stream_resumable.rb +0 -2
  140. data/lib/mongo/error/client_closed.rb +0 -2
  141. data/lib/mongo/error/closed_stream.rb +1 -4
  142. data/lib/mongo/error/connection_check_out_timeout.rb +3 -6
  143. data/lib/mongo/error/connection_perished.rb +0 -2
  144. data/lib/mongo/error/connection_unavailable.rb +0 -2
  145. data/lib/mongo/error/credential_check_error.rb +0 -2
  146. data/lib/mongo/error/crypt_error.rb +0 -2
  147. data/lib/mongo/error/extra_file_chunk.rb +1 -4
  148. data/lib/mongo/error/failed_string_prep_validation.rb +5 -6
  149. data/lib/mongo/error/file_not_found.rb +0 -3
  150. data/lib/mongo/error/handshake_error.rb +0 -2
  151. data/lib/mongo/error/insufficient_iteration_count.rb +1 -4
  152. data/lib/mongo/error/internal_driver_error.rb +0 -2
  153. data/lib/mongo/error/invalid_address.rb +0 -2
  154. data/lib/mongo/error/invalid_application_name.rb +0 -3
  155. data/lib/mongo/error/invalid_bulk_operation.rb +1 -4
  156. data/lib/mongo/error/invalid_bulk_operation_type.rb +1 -4
  157. data/lib/mongo/error/invalid_collection_name.rb +1 -4
  158. data/lib/mongo/error/invalid_config_option.rb +0 -3
  159. data/lib/mongo/error/invalid_cursor_operation.rb +0 -2
  160. data/lib/mongo/error/invalid_database_name.rb +1 -4
  161. data/lib/mongo/error/invalid_document.rb +1 -4
  162. data/lib/mongo/error/invalid_file.rb +0 -3
  163. data/lib/mongo/error/invalid_file_revision.rb +0 -3
  164. data/lib/mongo/error/invalid_min_pool_size.rb +0 -3
  165. data/lib/mongo/error/invalid_nonce.rb +0 -3
  166. data/lib/mongo/error/invalid_read_concern.rb +2 -4
  167. data/lib/mongo/error/invalid_read_option.rb +0 -3
  168. data/lib/mongo/error/invalid_replacement_document.rb +2 -5
  169. data/lib/mongo/error/invalid_server_auth_host.rb +0 -2
  170. data/lib/mongo/error/invalid_server_auth_response.rb +0 -2
  171. data/lib/mongo/error/invalid_server_preference.rb +7 -16
  172. data/lib/mongo/error/invalid_session.rb +1 -4
  173. data/lib/mongo/error/invalid_signature.rb +0 -3
  174. data/lib/mongo/error/invalid_transaction_operation.rb +5 -8
  175. data/lib/mongo/error/invalid_txt_record.rb +0 -2
  176. data/lib/mongo/error/invalid_update_document.rb +2 -5
  177. data/lib/mongo/error/invalid_uri.rb +1 -4
  178. data/lib/mongo/error/invalid_write_concern.rb +2 -5
  179. data/lib/mongo/error/kms_error.rb +0 -2
  180. data/lib/mongo/error/labelable.rb +0 -3
  181. data/lib/mongo/error/lint_error.rb +0 -2
  182. data/lib/mongo/error/max_bson_size.rb +8 -11
  183. data/lib/mongo/error/max_message_size.rb +2 -5
  184. data/lib/mongo/error/mismatched_domain.rb +0 -2
  185. data/lib/mongo/error/missing_connection.rb +0 -2
  186. data/lib/mongo/error/missing_file_chunk.rb +0 -3
  187. data/lib/mongo/error/missing_password.rb +0 -2
  188. data/lib/mongo/error/missing_resume_token.rb +1 -4
  189. data/lib/mongo/error/missing_scram_server_signature.rb +2 -4
  190. data/lib/mongo/error/missing_service_id.rb +0 -2
  191. data/lib/mongo/error/mongocryptd_spawn_error.rb +0 -2
  192. data/lib/mongo/error/multi_index_drop.rb +0 -3
  193. data/lib/mongo/error/need_primary_server.rb +0 -2
  194. data/lib/mongo/error/no_server_available.rb +3 -8
  195. data/lib/mongo/error/no_service_connection_available.rb +1 -3
  196. data/lib/mongo/error/no_srv_records.rb +0 -2
  197. data/lib/mongo/error/notable.rb +8 -16
  198. data/lib/mongo/error/operation_failure.rb +22 -35
  199. data/lib/mongo/error/parser.rb +33 -75
  200. data/lib/mongo/error/pool_cleared_error.rb +1 -3
  201. data/lib/mongo/error/pool_closed_error.rb +0 -3
  202. data/lib/mongo/error/pool_error.rb +0 -3
  203. data/lib/mongo/error/pool_paused_error.rb +0 -2
  204. data/lib/mongo/error/raise_original_error.rb +1 -3
  205. data/lib/mongo/error/read_write_retryable.rb +14 -17
  206. data/lib/mongo/error/sdam_error_detection.rb +3 -5
  207. data/lib/mongo/error/server_api_conflict.rb +0 -2
  208. data/lib/mongo/error/server_certificate_revoked.rb +0 -2
  209. data/lib/mongo/error/server_not_usable.rb +0 -2
  210. data/lib/mongo/error/session_ended.rb +1 -3
  211. data/lib/mongo/error/session_not_materialized.rb +1 -3
  212. data/lib/mongo/error/sessions_not_supported.rb +1 -4
  213. data/lib/mongo/error/snapshot_session_invalid_server_version.rb +1 -4
  214. data/lib/mongo/error/snapshot_session_transaction_prohibited.rb +1 -4
  215. data/lib/mongo/error/socket_error.rb +0 -2
  216. data/lib/mongo/error/socket_timeout_error.rb +0 -2
  217. data/lib/mongo/error/transactions_not_supported.rb +3 -6
  218. data/lib/mongo/error/unchangeable_collection_option.rb +1 -4
  219. data/lib/mongo/error/unexpected_chunk_length.rb +0 -3
  220. data/lib/mongo/error/unexpected_response.rb +1 -4
  221. data/lib/mongo/error/unknown_payload_type.rb +0 -3
  222. data/lib/mongo/error/unmet_dependency.rb +0 -2
  223. data/lib/mongo/error/unsupported_array_filters.rb +3 -24
  224. data/lib/mongo/error/unsupported_collation.rb +3 -24
  225. data/lib/mongo/error/unsupported_features.rb +0 -2
  226. data/lib/mongo/error/unsupported_message_type.rb +0 -2
  227. data/lib/mongo/error/unsupported_option.rb +19 -21
  228. data/lib/mongo/error/write_retryable.rb +0 -2
  229. data/lib/mongo/error.rb +10 -24
  230. data/lib/mongo/event/base.rb +0 -2
  231. data/lib/mongo/event/listeners.rb +0 -3
  232. data/lib/mongo/event/publisher.rb +0 -3
  233. data/lib/mongo/event/subscriber.rb +0 -4
  234. data/lib/mongo/event.rb +4 -6
  235. data/lib/mongo/grid/file/chunk.rb +7 -10
  236. data/lib/mongo/grid/file/info.rb +20 -24
  237. data/lib/mongo/grid/file.rb +7 -8
  238. data/lib/mongo/grid/fs_bucket.rb +40 -48
  239. data/lib/mongo/grid/stream/read.rb +25 -35
  240. data/lib/mongo/grid/stream/write.rb +17 -22
  241. data/lib/mongo/grid/stream.rb +2 -4
  242. data/lib/mongo/grid.rb +0 -1
  243. data/lib/mongo/id.rb +0 -1
  244. data/lib/mongo/index/view.rb +68 -58
  245. data/lib/mongo/index.rb +7 -10
  246. data/lib/mongo/lint.rb +31 -37
  247. data/lib/mongo/loggable.rb +5 -8
  248. data/lib/mongo/logger.rb +1 -7
  249. data/lib/mongo/monitoring/cmap_log_subscriber.rb +0 -2
  250. data/lib/mongo/monitoring/command_log_subscriber.rb +25 -33
  251. data/lib/mongo/monitoring/event/cmap/base.rb +0 -2
  252. data/lib/mongo/monitoring/event/cmap/connection_check_out_failed.rb +1 -4
  253. data/lib/mongo/monitoring/event/cmap/connection_check_out_started.rb +0 -3
  254. data/lib/mongo/monitoring/event/cmap/connection_checked_in.rb +1 -4
  255. data/lib/mongo/monitoring/event/cmap/connection_checked_out.rb +2 -5
  256. data/lib/mongo/monitoring/event/cmap/connection_closed.rb +1 -4
  257. data/lib/mongo/monitoring/event/cmap/connection_created.rb +1 -4
  258. data/lib/mongo/monitoring/event/cmap/connection_ready.rb +1 -4
  259. data/lib/mongo/monitoring/event/cmap/pool_cleared.rb +0 -3
  260. data/lib/mongo/monitoring/event/cmap/pool_closed.rb +1 -4
  261. data/lib/mongo/monitoring/event/cmap/pool_created.rb +1 -4
  262. data/lib/mongo/monitoring/event/cmap/pool_ready.rb +1 -4
  263. data/lib/mongo/monitoring/event/cmap.rb +0 -1
  264. data/lib/mongo/monitoring/event/command_failed.rb +5 -9
  265. data/lib/mongo/monitoring/event/command_started.rb +8 -12
  266. data/lib/mongo/monitoring/event/command_succeeded.rb +7 -15
  267. data/lib/mongo/monitoring/event/secure.rb +15 -20
  268. data/lib/mongo/monitoring/event/server_closed.rb +1 -4
  269. data/lib/mongo/monitoring/event/server_description_changed.rb +4 -8
  270. data/lib/mongo/monitoring/event/server_heartbeat_failed.rb +5 -10
  271. data/lib/mongo/monitoring/event/server_heartbeat_started.rb +1 -4
  272. data/lib/mongo/monitoring/event/server_heartbeat_succeeded.rb +3 -8
  273. data/lib/mongo/monitoring/event/server_opening.rb +1 -4
  274. data/lib/mongo/monitoring/event/topology_changed.rb +2 -5
  275. data/lib/mongo/monitoring/event/topology_closed.rb +1 -4
  276. data/lib/mongo/monitoring/event/topology_opening.rb +1 -4
  277. data/lib/mongo/monitoring/event.rb +0 -1
  278. data/lib/mongo/monitoring/publishable.rb +20 -30
  279. data/lib/mongo/monitoring/sdam_log_subscriber.rb +0 -2
  280. data/lib/mongo/monitoring/server_closed_log_subscriber.rb +0 -3
  281. data/lib/mongo/monitoring/server_description_changed_log_subscriber.rb +0 -3
  282. data/lib/mongo/monitoring/server_opening_log_subscriber.rb +0 -3
  283. data/lib/mongo/monitoring/topology_changed_log_subscriber.rb +5 -8
  284. data/lib/mongo/monitoring/topology_closed_log_subscriber.rb +0 -3
  285. data/lib/mongo/monitoring/topology_opening_log_subscriber.rb +0 -3
  286. data/lib/mongo/monitoring/unified_sdam_log_subscriber.rb +1 -3
  287. data/lib/mongo/monitoring.rb +38 -39
  288. data/lib/mongo/operation/aggregate/op_msg.rb +0 -2
  289. data/lib/mongo/operation/aggregate/result.rb +3 -6
  290. data/lib/mongo/operation/aggregate.rb +0 -2
  291. data/lib/mongo/operation/collections_info/result.rb +0 -3
  292. data/lib/mongo/operation/collections_info.rb +0 -2
  293. data/lib/mongo/operation/command/op_msg.rb +1 -4
  294. data/lib/mongo/operation/command.rb +0 -2
  295. data/lib/mongo/operation/context.rb +13 -16
  296. data/lib/mongo/operation/count/op_msg.rb +2 -4
  297. data/lib/mongo/operation/count.rb +0 -2
  298. data/lib/mongo/operation/create/op_msg.rb +2 -5
  299. data/lib/mongo/operation/create.rb +4 -2
  300. data/lib/mongo/operation/create_index/op_msg.rb +3 -7
  301. data/lib/mongo/operation/create_index.rb +0 -2
  302. data/lib/mongo/operation/create_user/op_msg.rb +2 -4
  303. data/lib/mongo/operation/create_user.rb +0 -2
  304. data/lib/mongo/operation/delete/bulk_result.rb +2 -3
  305. data/lib/mongo/operation/delete/op_msg.rb +3 -10
  306. data/lib/mongo/operation/delete/result.rb +0 -3
  307. data/lib/mongo/operation/delete.rb +1 -5
  308. data/lib/mongo/operation/distinct/op_msg.rb +2 -5
  309. data/lib/mongo/operation/distinct.rb +0 -2
  310. data/lib/mongo/operation/drop/op_msg.rb +0 -2
  311. data/lib/mongo/operation/drop.rb +0 -2
  312. data/lib/mongo/operation/drop_database/op_msg.rb +0 -2
  313. data/lib/mongo/operation/drop_database.rb +0 -2
  314. data/lib/mongo/operation/drop_index/op_msg.rb +4 -6
  315. data/lib/mongo/operation/drop_index.rb +0 -2
  316. data/lib/mongo/operation/explain/op_msg.rb +0 -2
  317. data/lib/mongo/operation/explain/result.rb +0 -3
  318. data/lib/mongo/operation/explain.rb +0 -2
  319. data/lib/mongo/operation/find/builder/command.rb +4 -12
  320. data/lib/mongo/operation/find/builder/flags.rb +9 -15
  321. data/lib/mongo/operation/find/builder/modifiers.rb +1 -4
  322. data/lib/mongo/operation/find/builder.rb +0 -1
  323. data/lib/mongo/operation/find/op_msg.rb +4 -12
  324. data/lib/mongo/operation/find/result.rb +0 -3
  325. data/lib/mongo/operation/find.rb +0 -2
  326. data/lib/mongo/operation/get_more/command_builder.rb +1 -6
  327. data/lib/mongo/operation/get_more/op_msg.rb +10 -4
  328. data/lib/mongo/operation/get_more/result.rb +0 -3
  329. data/lib/mongo/operation/get_more.rb +0 -2
  330. data/lib/mongo/operation/indexes/op_msg.rb +0 -2
  331. data/lib/mongo/operation/indexes/result.rb +1 -5
  332. data/lib/mongo/operation/indexes.rb +0 -2
  333. data/lib/mongo/operation/insert/bulk_result.rb +2 -6
  334. data/lib/mongo/operation/insert/op_msg.rb +7 -6
  335. data/lib/mongo/operation/insert/result.rb +0 -3
  336. data/lib/mongo/operation/insert.rb +2 -5
  337. data/lib/mongo/operation/kill_cursors/command_builder.rb +0 -3
  338. data/lib/mongo/operation/kill_cursors/op_msg.rb +1 -3
  339. data/lib/mongo/operation/kill_cursors.rb +0 -2
  340. data/lib/mongo/operation/list_collections/op_msg.rb +4 -6
  341. data/lib/mongo/operation/list_collections/result.rb +1 -4
  342. data/lib/mongo/operation/list_collections.rb +0 -2
  343. data/lib/mongo/operation/map_reduce/op_msg.rb +0 -2
  344. data/lib/mongo/operation/map_reduce/result.rb +3 -6
  345. data/lib/mongo/operation/map_reduce.rb +0 -2
  346. data/lib/mongo/operation/op_msg_base.rb +0 -1
  347. data/lib/mongo/operation/parallel_scan/op_msg.rb +4 -5
  348. data/lib/mongo/operation/parallel_scan/result.rb +2 -5
  349. data/lib/mongo/operation/parallel_scan.rb +0 -2
  350. data/lib/mongo/operation/remove_user/op_msg.rb +2 -4
  351. data/lib/mongo/operation/remove_user.rb +0 -2
  352. data/lib/mongo/operation/result.rb +38 -48
  353. data/lib/mongo/operation/shared/bypass_document_validation.rb +3 -7
  354. data/lib/mongo/operation/shared/causal_consistency_supported.rb +0 -3
  355. data/lib/mongo/operation/shared/executable.rb +29 -31
  356. data/lib/mongo/operation/shared/executable_no_validate.rb +0 -3
  357. data/lib/mongo/operation/shared/executable_transaction_label.rb +0 -2
  358. data/lib/mongo/operation/shared/idable.rb +3 -6
  359. data/lib/mongo/operation/shared/limited.rb +0 -3
  360. data/lib/mongo/operation/shared/object_id_generator.rb +0 -3
  361. data/lib/mongo/operation/shared/op_msg_executable.rb +0 -2
  362. data/lib/mongo/operation/shared/polymorphic_lookup.rb +0 -2
  363. data/lib/mongo/operation/shared/polymorphic_result.rb +2 -4
  364. data/lib/mongo/operation/shared/read_preference_supported.rb +10 -15
  365. data/lib/mongo/operation/shared/response_handling.rb +13 -26
  366. data/lib/mongo/operation/shared/result/aggregatable.rb +12 -13
  367. data/lib/mongo/operation/shared/sessions_supported.rb +87 -99
  368. data/lib/mongo/operation/shared/specifiable.rb +37 -59
  369. data/lib/mongo/operation/shared/write.rb +12 -17
  370. data/lib/mongo/operation/shared/write_concern_supported.rb +4 -7
  371. data/lib/mongo/operation/update/bulk_result.rb +13 -17
  372. data/lib/mongo/operation/update/op_msg.rb +2 -5
  373. data/lib/mongo/operation/update/result.rb +5 -5
  374. data/lib/mongo/operation/update.rb +1 -5
  375. data/lib/mongo/operation/update_user/op_msg.rb +2 -4
  376. data/lib/mongo/operation/update_user.rb +0 -2
  377. data/lib/mongo/operation/users_info/op_msg.rb +2 -4
  378. data/lib/mongo/operation/users_info/result.rb +1 -4
  379. data/lib/mongo/operation/users_info.rb +0 -2
  380. data/lib/mongo/operation/write_command/op_msg.rb +2 -10
  381. data/lib/mongo/operation/write_command.rb +0 -2
  382. data/lib/mongo/operation.rb +9 -14
  383. data/lib/mongo/options/mapper.rb +8 -15
  384. data/lib/mongo/options/redacted.rb +7 -9
  385. data/lib/mongo/options.rb +0 -1
  386. data/lib/mongo/protocol/bit_vector.rb +3 -5
  387. data/lib/mongo/protocol/caching_hash.rb +2 -7
  388. data/lib/mongo/protocol/compressed.rb +5 -10
  389. data/lib/mongo/protocol/get_more.rb +2 -8
  390. data/lib/mongo/protocol/kill_cursors.rb +2 -8
  391. data/lib/mongo/protocol/message.rb +103 -105
  392. data/lib/mongo/protocol/msg.rb +48 -63
  393. data/lib/mongo/protocol/query.rb +32 -41
  394. data/lib/mongo/protocol/registry.rb +2 -5
  395. data/lib/mongo/protocol/reply.rb +10 -16
  396. data/lib/mongo/protocol/serializers.rb +41 -59
  397. data/lib/mongo/protocol.rb +0 -1
  398. data/lib/mongo/query_cache.rb +7 -15
  399. data/lib/mongo/retryable/backpressure.rb +31 -0
  400. data/lib/mongo/retryable/base_worker.rb +39 -13
  401. data/lib/mongo/retryable/read_worker.rb +77 -21
  402. data/lib/mongo/retryable/retry_policy.rb +59 -0
  403. data/lib/mongo/retryable/write_worker.rb +155 -56
  404. data/lib/mongo/retryable.rb +70 -9
  405. data/lib/mongo/search_index/view.rb +30 -10
  406. data/lib/mongo/semaphore.rb +0 -1
  407. data/lib/mongo/server/app_metadata/environment.rb +3 -3
  408. data/lib/mongo/server/app_metadata/platform.rb +17 -4
  409. data/lib/mongo/server/app_metadata.rb +4 -5
  410. data/lib/mongo/server/connection.rb +79 -61
  411. data/lib/mongo/server/connection_base.rb +43 -53
  412. data/lib/mongo/server/connection_common.rb +41 -64
  413. data/lib/mongo/server/connection_pool/generation_manager.rb +6 -11
  414. data/lib/mongo/server/connection_pool/populator.rb +1 -4
  415. data/lib/mongo/server/connection_pool.rb +195 -167
  416. data/lib/mongo/server/description/features.rb +51 -59
  417. data/lib/mongo/server/description/load_balancer.rb +0 -2
  418. data/lib/mongo/server/description.rb +117 -138
  419. data/lib/mongo/server/monitor/app_metadata.rb +3 -4
  420. data/lib/mongo/server/monitor/connection.rb +28 -35
  421. data/lib/mongo/server/monitor.rb +65 -60
  422. data/lib/mongo/server/pending_connection.rb +70 -71
  423. data/lib/mongo/server/push_monitor/connection.rb +0 -3
  424. data/lib/mongo/server/push_monitor.rb +21 -29
  425. data/lib/mongo/server/round_trip_time_calculator.rb +11 -17
  426. data/lib/mongo/server.rb +62 -94
  427. data/lib/mongo/server_selector/base.rb +133 -157
  428. data/lib/mongo/server_selector/nearest.rb +2 -5
  429. data/lib/mongo/server_selector/primary.rb +1 -5
  430. data/lib/mongo/server_selector/primary_preferred.rb +2 -6
  431. data/lib/mongo/server_selector/secondary.rb +2 -6
  432. data/lib/mongo/server_selector/secondary_preferred.rb +1 -5
  433. data/lib/mongo/server_selector.rb +3 -4
  434. data/lib/mongo/session/server_session.rb +6 -7
  435. data/lib/mongo/session/session_pool.rb +20 -34
  436. data/lib/mongo/session.rb +334 -199
  437. data/lib/mongo/socket/ocsp_cache.rb +8 -13
  438. data/lib/mongo/socket/ocsp_verifier.rb +69 -70
  439. data/lib/mongo/socket/ssl.rb +44 -43
  440. data/lib/mongo/socket/tcp.rb +5 -8
  441. data/lib/mongo/socket/unix.rb +0 -4
  442. data/lib/mongo/socket.rb +80 -102
  443. data/lib/mongo/srv/monitor.rb +10 -11
  444. data/lib/mongo/srv/resolver.rb +15 -24
  445. data/lib/mongo/srv/result.rb +25 -21
  446. data/lib/mongo/srv.rb +0 -1
  447. data/lib/mongo/timeout.rb +4 -11
  448. data/lib/mongo/topology_version.rb +8 -13
  449. data/lib/mongo/tracing/open_telemetry/command_tracer.rb +320 -0
  450. data/lib/mongo/tracing/open_telemetry/operation_tracer.rb +227 -0
  451. data/lib/mongo/tracing/open_telemetry/tracer.rb +236 -0
  452. data/lib/mongo/{error/server_api_not_supported.rb → tracing/open_telemetry.rb} +10 -10
  453. data/lib/mongo/tracing.rb +42 -0
  454. data/lib/mongo/uri/options_mapper.rb +135 -126
  455. data/lib/mongo/uri/srv_protocol.rb +34 -42
  456. data/lib/mongo/uri.rb +95 -139
  457. data/lib/mongo/utils.rb +5 -12
  458. data/lib/mongo/version.rb +1 -1
  459. data/lib/mongo/write_concern/acknowledged.rb +0 -2
  460. data/lib/mongo/write_concern/base.rb +6 -6
  461. data/lib/mongo/write_concern/unacknowledged.rb +0 -2
  462. data/lib/mongo/write_concern.rb +14 -15
  463. data/lib/mongo.rb +4 -3
  464. data/mongo.gemspec +17 -17
  465. metadata +11 -5
  466. data/lib/mongo/operation/shared/result/use_legacy_error_parser.rb +0 -32
  467. data/lib/mongo/operation/shared/validatable.rb +0 -87
data/lib/mongo/uri.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
  #
@@ -16,7 +15,6 @@
16
15
  # limitations under the License.
17
16
 
18
17
  module Mongo
19
-
20
18
  # The URI class provides a way for users to parse the MongoDB uri as
21
19
  # defined in the connection string format spec.
22
20
  #
@@ -53,44 +51,44 @@ module Mongo
53
51
  # @deprecated Will be removed in 3.0.
54
52
  #
55
53
  # @since 2.0.0
56
- SCHEME = 'mongodb://'.freeze
54
+ SCHEME = 'mongodb://'
57
55
 
58
56
  # The mongodb connection string scheme root.
59
57
  #
60
58
  # @since 2.5.0
61
- MONGODB_SCHEME = 'mongodb'.freeze
59
+ MONGODB_SCHEME = 'mongodb'
62
60
 
63
61
  # The mongodb srv protocol connection string scheme root.
64
62
  #
65
63
  # @since 2.5.0
66
- MONGODB_SRV_SCHEME = 'mongodb+srv'.freeze
64
+ MONGODB_SRV_SCHEME = 'mongodb+srv'
67
65
 
68
66
  # Error details for an invalid scheme.
69
67
  #
70
68
  # @since 2.1.0
71
69
  # @deprecated
72
- INVALID_SCHEME = "Invalid scheme. Scheme must be '#{MONGODB_SCHEME}' or '#{MONGODB_SRV_SCHEME}'".freeze
70
+ INVALID_SCHEME = "Invalid scheme. Scheme must be '#{MONGODB_SCHEME}' or '#{MONGODB_SRV_SCHEME}'"
73
71
 
74
72
  # MongoDB URI format specification.
75
73
  #
76
74
  # @since 2.0.0
77
75
  FORMAT = 'mongodb://[username:password@]host1[:port1][,host2[:port2]' +
78
- ',...[,hostN[:portN]]][/[database][?options]]'.freeze
76
+ ',...[,hostN[:portN]]][/[database][?options]]'
79
77
 
80
78
  # MongoDB URI (connection string) documentation url
81
79
  #
82
80
  # @since 2.0.0
83
- HELP = 'https://www.mongodb.com/docs/manual/reference/connection-string/'.freeze
81
+ HELP = 'https://www.mongodb.com/docs/manual/reference/connection-string/'
84
82
 
85
83
  # Unsafe characters that must be urlencoded.
86
84
  #
87
85
  # @since 2.1.0
88
- UNSAFE = /[\:\/\@]/
86
+ UNSAFE = %r{[:/@]}
89
87
 
90
88
  # Percent sign that must be encoded in user creds.
91
89
  #
92
90
  # @since 2.5.1
93
- PERCENT_CHAR = /\%/
91
+ PERCENT_CHAR = /%/
94
92
 
95
93
  # Unix socket suffix.
96
94
  #
@@ -100,110 +98,113 @@ module Mongo
100
98
  # The character delimiting hosts.
101
99
  #
102
100
  # @since 2.1.0
103
- HOST_DELIM = ','.freeze
101
+ HOST_DELIM = ','
104
102
 
105
103
  # The character separating a host and port.
106
104
  #
107
105
  # @since 2.1.0
108
- HOST_PORT_DELIM = ':'.freeze
106
+ HOST_PORT_DELIM = ':'
109
107
 
110
108
  # The character delimiting a database.
111
109
  #
112
110
  # @since 2.1.0
113
- DATABASE_DELIM = '/'.freeze
111
+ DATABASE_DELIM = '/'
114
112
 
115
113
  # The character delimiting options.
116
114
  #
117
115
  # @since 2.1.0
118
- URI_OPTS_DELIM = '?'.freeze
116
+ URI_OPTS_DELIM = '?'
119
117
 
120
118
  # The character delimiting multiple options.
121
119
  #
122
120
  # @since 2.1.0
123
121
  # @deprecated
124
- INDIV_URI_OPTS_DELIM = '&'.freeze
122
+ INDIV_URI_OPTS_DELIM = '&'
125
123
 
126
124
  # The character delimiting an option and its value.
127
125
  #
128
126
  # @since 2.1.0
129
- URI_OPTS_VALUE_DELIM = '='.freeze
127
+ URI_OPTS_VALUE_DELIM = '='
130
128
 
131
129
  # The character separating a username from the password.
132
130
  #
133
131
  # @since 2.1.0
134
- AUTH_USER_PWD_DELIM = ':'.freeze
132
+ AUTH_USER_PWD_DELIM = ':'
135
133
 
136
134
  # The character delimiting auth credentials.
137
135
  #
138
136
  # @since 2.1.0
139
- AUTH_DELIM = '@'.freeze
137
+ AUTH_DELIM = '@'
140
138
 
141
139
  # Scheme delimiter.
142
140
  #
143
141
  # @since 2.5.0
144
- SCHEME_DELIM = '://'.freeze
142
+ SCHEME_DELIM = '://'
145
143
 
146
144
  # Error details for an invalid options format.
147
145
  #
148
146
  # @since 2.1.0
149
- INVALID_OPTS_VALUE_DELIM = "Options and their values must be delimited" +
150
- " by '#{URI_OPTS_VALUE_DELIM}'".freeze
147
+ INVALID_OPTS_VALUE_DELIM = 'Options and their values must be delimited' +
148
+ " by '#{URI_OPTS_VALUE_DELIM}'"
151
149
 
152
150
  # Error details for an non-urlencoded user name or password.
153
151
  #
154
152
  # @since 2.1.0
155
- UNESCAPED_USER_PWD = "User name and password must be urlencoded.".freeze
153
+ UNESCAPED_USER_PWD = 'User name and password must be urlencoded.'
156
154
 
157
155
  # Error details for a non-urlencoded unix socket path.
158
156
  #
159
157
  # @since 2.1.0
160
- UNESCAPED_UNIX_SOCKET = "UNIX domain sockets must be urlencoded.".freeze
158
+ UNESCAPED_UNIX_SOCKET = 'UNIX domain sockets must be urlencoded.'
161
159
 
162
160
  # Error details for a non-urlencoded auth database name.
163
161
  #
164
162
  # @since 2.1.0
165
- UNESCAPED_DATABASE = "Auth database must be urlencoded.".freeze
163
+ UNESCAPED_DATABASE = 'Auth database must be urlencoded.'
166
164
 
167
165
  # Error details for providing options without a database delimiter.
168
166
  #
169
167
  # @since 2.1.0
170
- INVALID_OPTS_DELIM = "Database delimiter '#{DATABASE_DELIM}' must be present if options are specified.".freeze
168
+ INVALID_OPTS_DELIM = "Database delimiter '#{DATABASE_DELIM}' must be present if options are specified."
171
169
 
172
170
  # Error details for a missing host.
173
171
  #
174
172
  # @since 2.1.0
175
- INVALID_HOST = "Missing host; at least one must be provided.".freeze
173
+ INVALID_HOST = 'Missing host; at least one must be provided.'
176
174
 
177
175
  # Error details for an invalid port.
178
176
  #
179
177
  # @since 2.1.0
180
- INVALID_PORT = "Invalid port. Port must be an integer greater than 0 and less than 65536".freeze
178
+ INVALID_PORT = 'Invalid port. Port must be an integer greater than 0 and less than 65536'
181
179
 
182
180
  # Map of URI read preference modes to Ruby driver read preference modes
183
181
  #
184
182
  # @since 2.0.0
185
183
  READ_MODE_MAP = {
186
- 'primary' => :primary,
187
- 'primarypreferred' => :primary_preferred,
188
- 'secondary' => :secondary,
184
+ 'primary' => :primary,
185
+ 'primarypreferred' => :primary_preferred,
186
+ 'secondary' => :secondary,
189
187
  'secondarypreferred' => :secondary_preferred,
190
- 'nearest' => :nearest
188
+ 'nearest' => :nearest
191
189
  }.freeze
192
190
 
193
191
  # Map of URI authentication mechanisms to Ruby driver mechanisms
194
192
  #
195
193
  # @since 2.0.0
196
194
  AUTH_MECH_MAP = {
197
- 'GSSAPI' => :gssapi,
198
- 'MONGODB-AWS' => :aws,
195
+ 'GSSAPI' => :gssapi,
196
+ 'MONGODB-AWS' => :aws,
199
197
  # MONGODB-CR is deprecated and will be removed in driver version 3.0
200
- 'MONGODB-CR' => :mongodb_cr,
198
+ 'MONGODB-CR' => :mongodb_cr,
201
199
  'MONGODB-X509' => :mongodb_x509,
202
- 'PLAIN' => :plain,
203
- 'SCRAM-SHA-1' => :scram,
200
+ 'PLAIN' => :plain,
201
+ 'SCRAM-SHA-1' => :scram,
204
202
  'SCRAM-SHA-256' => :scram256,
205
203
  }.freeze
206
204
 
205
+ # Valid values for the serverMonitoringMode URI option.
206
+ SERVER_MONITORING_MODES = %w[stream poll auto].freeze
207
+
207
208
  # Options that are allowed to appear more than once in the uri.
208
209
  #
209
210
  # In order to follow the URI options spec requirement that all instances
@@ -212,7 +213,7 @@ module Mongo
212
213
  # they will be condensed to a single value immediately after parsing the URI.
213
214
  #
214
215
  # @since 2.1.0
215
- REPEATABLE_OPTIONS = [ :tag_sets, :ssl ]
216
+ REPEATABLE_OPTIONS = %i[tag_sets ssl]
216
217
 
217
218
  # Get either a URI object or a SRVProtocol URI object.
218
219
  #
@@ -228,21 +229,18 @@ module Mongo
228
229
  #
229
230
  # @since 2.5.0
230
231
  def self.get(string, opts = {})
231
- unless string
232
- raise Error::InvalidURI.new(string, 'URI must be a string, not nil.')
233
- end
234
- if string.empty?
235
- raise Error::InvalidURI.new(string, 'Cannot parse an empty URI.')
236
- end
232
+ raise Error::InvalidURI.new(string, 'URI must be a string, not nil.') unless string
233
+ raise Error::InvalidURI.new(string, 'Cannot parse an empty URI.') if string.empty?
237
234
 
238
- scheme, _, _ = string.partition(SCHEME_DELIM)
235
+ scheme, = string.partition(SCHEME_DELIM)
239
236
  case scheme
240
- when MONGODB_SCHEME
241
- URI.new(string, opts)
242
- when MONGODB_SRV_SCHEME
243
- SRVProtocol.new(string, opts)
244
- else
245
- raise Error::InvalidURI.new(string, "Invalid scheme '#{scheme}'. Scheme must be '#{MONGODB_SCHEME}' or '#{MONGODB_SRV_SCHEME}'")
237
+ when MONGODB_SCHEME
238
+ URI.new(string, opts)
239
+ when MONGODB_SRV_SCHEME
240
+ SRVProtocol.new(string, opts)
241
+ else
242
+ raise Error::InvalidURI.new(string,
243
+ "Invalid scheme '#{scheme}'. Scheme must be '#{MONGODB_SCHEME}' or '#{MONGODB_SRV_SCHEME}'")
246
244
  end
247
245
  end
248
246
 
@@ -282,12 +280,8 @@ module Mongo
282
280
  #
283
281
  # @since 2.0.0
284
282
  def initialize(string, options = {})
285
- unless string
286
- raise Error::InvalidURI.new(string, 'URI must be a string, not nil.')
287
- end
288
- if string.empty?
289
- raise Error::InvalidURI.new(string, 'Cannot parse an empty URI.')
290
- end
283
+ raise Error::InvalidURI.new(string, 'URI must be a string, not nil.') unless string
284
+ raise Error::InvalidURI.new(string, 'Cannot parse an empty URI.') if string.empty?
291
285
 
292
286
  @string = string
293
287
  @options = options
@@ -295,9 +289,7 @@ module Mongo
295
289
  unless parsed_scheme == scheme
296
290
  raise_invalid_error!("Invalid scheme '#{parsed_scheme}'. Scheme must be '#{MONGODB_SCHEME}'. Use URI#get to parse SRV URIs.")
297
291
  end
298
- if remaining.empty?
299
- raise_invalid_error!('No hosts in the URI')
300
- end
292
+ raise_invalid_error!('No hosts in the URI') if remaining.empty?
301
293
  parse!(remaining)
302
294
  validate_uri_options!
303
295
  end
@@ -313,7 +305,7 @@ module Mongo
313
305
  #
314
306
  # @since 2.0.0
315
307
  def credentials
316
- { :user => @user, :password => @password }
308
+ { user: @user, password: @password }
317
309
  end
318
310
 
319
311
  # Get the database provided in the URI.
@@ -325,7 +317,7 @@ module Mongo
325
317
  #
326
318
  # @since 2.0.0
327
319
  def database
328
- @database ? @database : Database::ADMIN
320
+ @database || Database::ADMIN
329
321
  end
330
322
 
331
323
  # Get the uri as a string.
@@ -359,9 +351,9 @@ module Mongo
359
351
  uri = "#{scheme}#{SCHEME_DELIM}"
360
352
  uri += @user.to_s if @user
361
353
  uri += "#{AUTH_USER_PWD_DELIM}#{@password}" if @password
362
- uri += "@" if @user || @password
354
+ uri += '@' if @user || @password
363
355
  uri += @query_hostname || servers
364
- uri += "/" if @database || !options.empty?
356
+ uri += '/' if @database || !options.empty?
365
357
  uri += @database.to_s if @database
366
358
  uri += "?#{options}" unless options.empty?
367
359
  uri
@@ -374,32 +366,22 @@ module Mongo
374
366
  def parse!(remaining)
375
367
  hosts_and_db, options = remaining.split('?', 2)
376
368
  if options && options.index('?')
377
- raise_invalid_error!("Options contain an unescaped question mark (?), or the database name contains a question mark and was not escaped")
369
+ raise_invalid_error!('Options contain an unescaped question mark (?), or the database name contains a question mark and was not escaped')
378
370
  end
379
371
 
380
372
  hosts, db = hosts_and_db.split('/', 2)
381
- if db && db.index('/')
382
- raise_invalid_error!("Database name contains an unescaped slash (/): #{db}")
383
- end
373
+ raise_invalid_error!("Database name contains an unescaped slash (/): #{db}") if db && db.index('/')
384
374
 
385
375
  if hosts.index('@')
386
376
  creds, hosts = hosts.split('@', 2)
387
- if hosts.empty?
388
- raise_invalid_error!("Empty hosts list")
389
- end
390
- if hosts.index('@')
391
- raise_invalid_error!("Unescaped @ in auth info")
392
- end
377
+ raise_invalid_error!('Empty hosts list') if hosts.empty?
378
+ raise_invalid_error!('Unescaped @ in auth info') if hosts.index('@')
393
379
  end
394
380
 
395
- unless hosts.length > 0
396
- raise_invalid_error!("Missing host; at least one must be provided")
397
- end
381
+ raise_invalid_error!('Missing host; at least one must be provided') unless hosts.length > 0
398
382
 
399
383
  @servers = hosts.split(',').map do |host|
400
- if host.empty?
401
- raise_invalid_error!('Empty host given in the host list')
402
- end
384
+ raise_invalid_error!('Empty host given in the host list') if host.empty?
403
385
  decode(host).tap do |host|
404
386
  validate_address_str!(host)
405
387
  end
@@ -408,32 +390,26 @@ module Mongo
408
390
  @user = parse_user!(creds)
409
391
  @password = parse_password!(creds)
410
392
  @uri_options = Options::Redacted.new(parse_uri_options!(options))
411
- if db
412
- @database = parse_database!(db)
413
- end
393
+ @database = parse_database!(db) if db
414
394
  rescue Error::InvalidAddress => e
415
395
  raise_invalid_error!(e.message)
416
396
  end
417
397
 
418
398
  def options_mapper
419
399
  @options_mapper ||= OptionsMapper.new(
420
- logger: @options[:logger],
400
+ logger: @options[:logger]
421
401
  )
422
402
  end
423
403
 
424
404
  def parse_uri_options!(string)
425
405
  uri_options = {}
426
- unless string
427
- return uri_options
428
- end
406
+ return uri_options unless string
407
+
429
408
  string.split('&').each do |option_str|
430
- if option_str.empty?
431
- next
432
- end
409
+ next if option_str.empty?
410
+
433
411
  key, value = option_str.split('=', 2)
434
- if value.nil?
435
- raise_invalid_error!("Option #{key} has no value")
436
- end
412
+ raise_invalid_error!("Option #{key} has no value") if value.nil?
437
413
  key = decode(key)
438
414
  value = decode(value)
439
415
  options_mapper.add_uri_option(key, value, uri_options)
@@ -442,31 +418,25 @@ module Mongo
442
418
  end
443
419
 
444
420
  def parse_user!(string)
445
- if (string && user = string.partition(AUTH_USER_PWD_DELIM)[0])
446
- raise_invalid_error!(UNESCAPED_USER_PWD) if user =~ UNSAFE
421
+ if string && user = string.partition(AUTH_USER_PWD_DELIM)[0]
422
+ raise_invalid_error!(UNESCAPED_USER_PWD) if UNSAFE.match?(user)
447
423
  user_decoded = decode(user)
448
- if user_decoded =~ PERCENT_CHAR && encode(user_decoded) != user
449
- raise_invalid_error!(UNESCAPED_USER_PWD)
450
- end
424
+ raise_invalid_error!(UNESCAPED_USER_PWD) if user_decoded =~ PERCENT_CHAR && encode(user_decoded) != user
451
425
  user_decoded
452
426
  end
453
427
  end
454
428
 
455
429
  def parse_password!(string)
456
- if (string && pwd = string.partition(AUTH_USER_PWD_DELIM)[2])
457
- if pwd.length > 0
458
- raise_invalid_error!(UNESCAPED_USER_PWD) if pwd =~ UNSAFE
459
- pwd_decoded = decode(pwd)
460
- if pwd_decoded =~ PERCENT_CHAR && encode(pwd_decoded) != pwd
461
- raise_invalid_error!(UNESCAPED_USER_PWD)
462
- end
463
- pwd_decoded
464
- end
430
+ if string && (pwd = string.partition(AUTH_USER_PWD_DELIM)[2]) && (pwd.length > 0)
431
+ raise_invalid_error!(UNESCAPED_USER_PWD) if UNSAFE.match?(pwd)
432
+ pwd_decoded = decode(pwd)
433
+ raise_invalid_error!(UNESCAPED_USER_PWD) if pwd_decoded =~ PERCENT_CHAR && encode(pwd_decoded) != pwd
434
+ pwd_decoded
465
435
  end
466
436
  end
467
437
 
468
438
  def parse_database!(string)
469
- raise_invalid_error!(UNESCAPED_DATABASE) if string =~ UNSAFE
439
+ raise_invalid_error!(UNESCAPED_DATABASE) if UNSAFE.match?(string)
470
440
  decode(string) if string.length > 0
471
441
  end
472
442
 
@@ -513,18 +483,14 @@ module Mongo
513
483
  end
514
484
  end
515
485
 
516
- unless uri_options[:ssl_verify_certificate].nil?
517
- unless uri_options[:ssl_verify_ocsp_endpoint].nil?
518
- raise_invalid_error_no_fmt!("tlsAllowInvalidCertificates' and 'tlsDisableOCSPEndpointCheck' cannot both be specified")
519
- end
486
+ if !uri_options[:ssl_verify_certificate].nil? && !uri_options[:ssl_verify_ocsp_endpoint].nil?
487
+ raise_invalid_error_no_fmt!("tlsAllowInvalidCertificates' and 'tlsDisableOCSPEndpointCheck' cannot both be specified")
520
488
  end
521
489
 
522
490
  # Since we know that the only URI option that sets :ssl_cert is
523
491
  # "tlsCertificateKeyFile", any value set for :ssl_cert must also be set
524
492
  # for :ssl_key.
525
- if uri_options[:ssl_cert]
526
- uri_options[:ssl_key] = uri_options[:ssl_cert]
527
- end
493
+ uri_options[:ssl_key] = uri_options[:ssl_cert] if uri_options[:ssl_cert]
528
494
 
529
495
  if uri_options[:write_concern] && !uri_options[:write_concern].empty?
530
496
  begin
@@ -538,50 +504,40 @@ module Mongo
538
504
  if uri_options[:connect] && uri_options[:connect].to_s != 'direct'
539
505
  raise_invalid_error_no_fmt!("directConnection=true cannot be used with connect=#{uri_options[:connect]}")
540
506
  end
541
- if servers.length > 1
542
- raise_invalid_error_no_fmt!("directConnection=true cannot be used with multiple seeds")
543
- end
507
+ raise_invalid_error_no_fmt!('directConnection=true cannot be used with multiple seeds') if servers.length > 1
544
508
  elsif uri_options[:direct_connection] == false && uri_options[:connect].to_s == 'direct'
545
- raise_invalid_error_no_fmt!("directConnection=false cannot be used with connect=direct")
509
+ raise_invalid_error_no_fmt!('directConnection=false cannot be used with connect=direct')
546
510
  end
547
511
 
548
512
  if uri_options[:load_balanced]
549
- if servers.length > 1
550
- raise_invalid_error_no_fmt!("loadBalanced=true cannot be used with multiple seeds")
551
- end
513
+ raise_invalid_error_no_fmt!('loadBalanced=true cannot be used with multiple seeds') if servers.length > 1
552
514
 
553
515
  if uri_options[:direct_connection]
554
- raise_invalid_error_no_fmt!("directConnection=true cannot be used with loadBalanced=true")
516
+ raise_invalid_error_no_fmt!('directConnection=true cannot be used with loadBalanced=true')
555
517
  end
556
518
 
557
519
  if uri_options[:connect] && uri_options[:connect].to_sym == :direct
558
- raise_invalid_error_no_fmt!("connect=direct cannot be used with loadBalanced=true")
520
+ raise_invalid_error_no_fmt!('connect=direct cannot be used with loadBalanced=true')
559
521
  end
560
522
 
561
523
  if uri_options[:replica_set]
562
- raise_invalid_error_no_fmt!("loadBalanced=true cannot be used with replicaSet option")
524
+ raise_invalid_error_no_fmt!('loadBalanced=true cannot be used with replicaSet option')
563
525
  end
564
526
  end
565
527
 
566
- unless self.is_a?(URI::SRVProtocol)
567
- if uri_options[:srv_max_hosts]
568
- raise_invalid_error_no_fmt!("srvMaxHosts cannot be used on non-SRV URI")
569
- end
528
+ unless is_a?(URI::SRVProtocol)
529
+ raise_invalid_error_no_fmt!('srvMaxHosts cannot be used on non-SRV URI') if uri_options[:srv_max_hosts]
570
530
 
571
- if uri_options[:srv_service_name]
572
- raise_invalid_error_no_fmt!("srvServiceName cannot be used on non-SRV URI")
573
- end
531
+ raise_invalid_error_no_fmt!('srvServiceName cannot be used on non-SRV URI') if uri_options[:srv_service_name]
574
532
  end
575
533
 
576
- if uri_options[:srv_max_hosts] && uri_options[:srv_max_hosts] > 0
577
- if uri_options[:replica_set]
578
- raise_invalid_error_no_fmt!("srvMaxHosts > 0 cannot be used with replicaSet option")
579
- end
534
+ return unless uri_options[:srv_max_hosts] && uri_options[:srv_max_hosts] > 0
580
535
 
581
- if options[:load_balanced]
582
- raise_invalid_error_no_fmt!("srvMaxHosts > 0 cannot be used with loadBalanced=true")
583
- end
584
- end
536
+ raise_invalid_error_no_fmt!('srvMaxHosts > 0 cannot be used with replicaSet option') if uri_options[:replica_set]
537
+
538
+ return unless options[:load_balanced]
539
+
540
+ raise_invalid_error_no_fmt!('srvMaxHosts > 0 cannot be used with loadBalanced=true')
585
541
  end
586
542
  end
587
543
  end
data/lib/mongo/utils.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
  #
@@ -16,10 +15,8 @@
16
15
  # limitations under the License.
17
16
 
18
17
  module Mongo
19
-
20
18
  # @api private
21
19
  module Utils
22
-
23
20
  class LocalLogger
24
21
  include Loggable
25
22
 
@@ -60,17 +57,17 @@ module Mongo
60
57
 
61
58
  # Symbolizes the keys in the provided hash.
62
59
  module_function def shallow_symbolize_keys(hash)
63
- Hash[hash.map { |k, v| [k.to_sym, v] }]
60
+ Hash[hash.map { |k, v| [ k.to_sym, v ] }]
64
61
  end
65
62
 
66
63
  # Stringifies the keys in the provided hash and converts underscore
67
64
  # style keys to camel case style keys.
68
65
  module_function def shallow_camelize_keys(hash)
69
- Hash[hash.map { |k, v| [camelize(k), v] }]
66
+ Hash[hash.map { |k, v| [ camelize(k), v ] }]
70
67
  end
71
68
 
72
69
  module_function def camelize(sym)
73
- sym.to_s.gsub(/_(\w)/) { $1.upcase }
70
+ sym.to_s.gsub(/_(\w)/) { ::Regexp.last_match(1).upcase }
74
71
  end
75
72
 
76
73
  # @note server_api must have symbol keys or be a BSON::Document.
@@ -79,12 +76,8 @@ module Mongo
79
76
  if version = server_api[:version]
80
77
  doc['apiVersion'] = version
81
78
  end
82
- unless server_api[:strict].nil?
83
- doc['apiStrict'] = server_api[:strict]
84
- end
85
- unless server_api[:deprecation_errors].nil?
86
- doc['apiDeprecationErrors'] = server_api[:deprecation_errors]
87
- end
79
+ doc['apiStrict'] = server_api[:strict] unless server_api[:strict].nil?
80
+ doc['apiDeprecationErrors'] = server_api[:deprecation_errors] unless server_api[:deprecation_errors].nil?
88
81
  end
89
82
  end
90
83
 
data/lib/mongo/version.rb CHANGED
@@ -5,5 +5,5 @@ module Mongo
5
5
  #
6
6
  # Note that this file is automatically updated via `rake candidate:create`.
7
7
  # Manual changes to this file will be overwritten by that rake task.
8
- VERSION = '2.22.0'
8
+ VERSION = '2.24.0'
9
9
  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
  #
@@ -17,7 +16,6 @@
17
16
 
18
17
  module Mongo
19
18
  module WriteConcern
20
-
21
19
  # An acknowledged write concern provides a get last error command with the
22
20
  # appropriate options on each write operation.
23
21
  #
@@ -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,12 +16,10 @@
17
16
 
18
17
  module Mongo
19
18
  module WriteConcern
20
-
21
19
  # Defines common behavior for write concerns.
22
20
  #
23
21
  # @since 2.7.0
24
22
  class Base
25
-
26
23
  # @return [ Hash ] The write concern options.
27
24
  attr_reader :options
28
25
 
@@ -51,11 +48,14 @@ module Mongo
51
48
 
52
49
  if options[:w]
53
50
  if options[:w] == 0 && options[:j]
54
- raise Error::InvalidWriteConcern, "Invalid write concern options: :j cannot be true when :w is 0: #{options.inspect}"
51
+ raise Error::InvalidWriteConcern,
52
+ "Invalid write concern options: :j cannot be true when :w is 0: #{options.inspect}"
55
53
  elsif options[:w] == 0 && options[:fsync]
56
- raise Error::InvalidWriteConcern, "Invalid write concern options: :fsync cannot be true when :w is 0: #{options.inspect}"
54
+ raise Error::InvalidWriteConcern,
55
+ "Invalid write concern options: :fsync cannot be true when :w is 0: #{options.inspect}"
57
56
  elsif options[:w].is_a?(Integer) && options[:w] < 0
58
- raise Error::InvalidWriteConcern, "Invalid write concern options: :w cannot be negative (#{options[:w]}): #{options.inspect}"
57
+ raise Error::InvalidWriteConcern,
58
+ "Invalid write concern options: :w cannot be negative (#{options[:w]}): #{options.inspect}"
59
59
  end
60
60
  end
61
61
 
@@ -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 WriteConcern
20
-
21
19
  # An unacknowledged write concern will provide no error on write outside of
22
20
  # network and connection exceptions.
23
21
  #