@@ -430,17 +430,19 @@ def self.uri_option(uri_key, name, extra = {})
430430 uri_option 'sockettimeoutms' , :socket_timeout , :type => :ms_convert
431431 uri_option 'serverselectiontimeoutms' , :server_selection_timeout , :type => :ms_convert
432432 uri_option 'localthresholdms' , :local_threshold , :type => :ms_convert
433+ uri_option 'heartbeatfrequencyms' , :heartbeat_frequency , :type => :ms_convert
434+ uri_option 'maxidletimems' , :max_idle_time , :type => :ms_convert
433435
434436 # Write Options
435437 uri_option 'w' , :w , :group => :write
436- uri_option 'journal' , :j , :group => :write
438+ uri_option 'journal' , :j , :group => :write , :type => :bool
437439 uri_option 'fsync' , :fsync , :group => :write
438- uri_option 'wtimeoutms' , :timeout , :group => :write
440+ uri_option 'wtimeoutms' , :timeout , :group => :write , :type => :unsigned_int
439441
440442 # Read Options
441443 uri_option 'readpreference' , :mode , :group => :read , :type => :read_mode
442444 uri_option 'readpreferencetags' , :tag_sets , :group => :read , :type => :read_tags
443- uri_option 'maxstalenessseconds' , :max_staleness , :group => :read
445+ uri_option 'maxstalenessseconds' , :max_staleness , :group => :read , :type => :max_staleness
444446
445447 # Pool options
446448 uri_option 'minpoolsize' , :min_pool_size
@@ -449,6 +451,13 @@ def self.uri_option(uri_key, name, extra = {})
449451
450452 # Security Options
451453 uri_option 'ssl' , :ssl
454+ uri_option 'tls' , :ssl
455+ uri_option 'tlsallowinvalidcertificates' , :ssl_verify , :type => :inverse_bool
456+ uri_option 'tlscafilepath' , :ssl_ca_cert
457+ uri_option 'tlsclientcertfilepath' , :ssl_cert
458+ uri_option 'tlsclientkeyfilepath' , :ssl_key
459+ uri_option 'tlsclientkeypassword' , :ssl_key_pass_phrase
460+
452461
453462 # Topology options
454463 uri_option 'connect' , :connect
@@ -461,7 +470,9 @@ def self.uri_option(uri_key, name, extra = {})
461470 # Client Options
462471 uri_option 'appname' , :app_name
463472 uri_option 'compressors' , :compressors , :type => :array
464- uri_option 'zlibcompressionlevel' , :zlib_compression_level
473+ uri_option 'readconcernlevel' , :read_concern
474+ uri_option 'retrywrites' , :retry_writes , :type => :bool
475+ uri_option 'zlibcompressionlevel' , :zlib_compression_level , :type => :zlib_compression_level
465476
466477 # Casts option values that do not have a specifically provided
467478 # transformation to the appropriate type.
@@ -571,7 +582,7 @@ def auth_source(value)
571582 #
572583 # @return [Symbol] The transformed authentication mechanism.
573584 def auth_mech ( value )
574- AUTH_MECH_MAP [ value . upcase ]
585+ AUTH_MECH_MAP [ value . upcase ] || log_warn ( " #{ value } is not a valid auth mechanism" )
575586 end
576587
577588 # Read preference mode transformation.
@@ -615,6 +626,60 @@ def auth_mech_props(value)
615626 properties
616627 end
617628
629+ def zlib_compression_level ( value )
630+ if /^-?\d +$/ =~ value
631+ i = value . to_i
632+
633+ if i >= -1 && i <= 9
634+ return i
635+ end
636+ end
637+
638+ log_warn ( "#{ value } is not valid zlibCompressionLevel" )
639+ nil
640+ end
641+
642+ def bool ( value )
643+ case value
644+ when "true"
645+ true
646+ when "false"
647+ false
648+ else
649+ log_warn ( "invalid boolean: #{ value } " )
650+ nil
651+ end
652+ end
653+
654+ def inverse_bool ( value )
655+ !bool ( value )
656+ end
657+
658+ def max_staleness ( value )
659+ if /^\d +$/ =~ value
660+ int = value . to_i
661+
662+ if int >= 0 && int < 90
663+ log_warn ( "max staleness must be either 0 or greater than 90: #{ value } " )
664+ end
665+
666+ return int
667+ end
668+
669+ log_warn ( "Invalid max staleness value: #{ value } " )
670+ nil
671+ end
672+
673+ # Ensures that a connection string value
674+ def unsigned_int ( value )
675+ unless /^\d +$/ =~ value
676+ log_warn ( "Invalid unsigned int value: #{ value } " )
677+ return nil
678+ end
679+
680+ value . to_i
681+ end
682+
618683 # Ruby's convention is to provide timeouts in seconds, not milliseconds and
619684 # to use fractions where more precision is necessary. The connection string
620685 # options are always in MS so we provide an easy conversion type.
@@ -625,6 +690,11 @@ def auth_mech_props(value)
625690 #
626691 # @since 2.0.0
627692 def ms_convert ( value )
693+ unless /^-?\d +(\. \d +)?$/ =~ value
694+ log_warn ( "Invalid ms value: #{ value } " )
695+ return nil
696+ end
697+
628698 value . to_f / 1000
629699 end
630700
@@ -636,6 +706,11 @@ def ms_convert(value)
636706 def hash_extractor ( value )
637707 value . split ( ',' ) . reduce ( { } ) do |set , tag |
638708 k , v = tag . split ( ':' )
709+ if v . nil?
710+ log_warn ( "#{ value } is not a valid URI hash" )
711+ return nil
712+ end
713+
639714 set . merge ( decode ( k ) . downcase . to_sym => decode ( v ) )
640715 end
641716 end
0 commit comments