@@ -430,17 +430,19 @@ def self.uri_option(uri_key, name, extra = {})
430
430
uri_option 'sockettimeoutms' , :socket_timeout , :type => :ms_convert
431
431
uri_option 'serverselectiontimeoutms' , :server_selection_timeout , :type => :ms_convert
432
432
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
433
435
434
436
# Write Options
435
437
uri_option 'w' , :w , :group => :write
436
- uri_option 'journal' , :j , :group => :write
438
+ uri_option 'journal' , :j , :group => :write , :type => :bool
437
439
uri_option 'fsync' , :fsync , :group => :write
438
- uri_option 'wtimeoutms' , :timeout , :group => :write
440
+ uri_option 'wtimeoutms' , :timeout , :group => :write , :type => :unsigned_int
439
441
440
442
# Read Options
441
443
uri_option 'readpreference' , :mode , :group => :read , :type => :read_mode
442
444
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
444
446
445
447
# Pool options
446
448
uri_option 'minpoolsize' , :min_pool_size
@@ -449,6 +451,13 @@ def self.uri_option(uri_key, name, extra = {})
449
451
450
452
# Security Options
451
453
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
+
452
461
453
462
# Topology options
454
463
uri_option 'connect' , :connect
@@ -461,7 +470,9 @@ def self.uri_option(uri_key, name, extra = {})
461
470
# Client Options
462
471
uri_option 'appname' , :app_name
463
472
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
465
476
466
477
# Casts option values that do not have a specifically provided
467
478
# transformation to the appropriate type.
@@ -571,7 +582,7 @@ def auth_source(value)
571
582
#
572
583
# @return [Symbol] The transformed authentication mechanism.
573
584
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" )
575
586
end
576
587
577
588
# Read preference mode transformation.
@@ -615,6 +626,92 @@ def auth_mech_props(value)
615
626
properties
616
627
end
617
628
629
+ # Parses the zlib compression level.
630
+ #
631
+ # @param value [ String ] The zlib compression level string.
632
+ #
633
+ # @return [ Integer | nil ] The compression level value if it is between -1 and 9 (inclusive),
634
+ # otherwise nil (and a warning will be raised).
635
+ def zlib_compression_level ( value )
636
+ if /^-?\d +$/ =~ value
637
+ i = value . to_i
638
+
639
+ if i >= -1 && i <= 9
640
+ return i
641
+ end
642
+ end
643
+
644
+ log_warn ( "#{ value } is not a valid zlibCompressionLevel" )
645
+ nil
646
+ end
647
+
648
+
649
+ # Parses a boolean value.
650
+ #
651
+ # @param value [ String ] The URI option value.
652
+ #
653
+ # @return [ true | false | nil ] The boolean value parsed out, otherwise nil (and a warning
654
+ # will be raised).
655
+ def bool ( value )
656
+ case value
657
+ when "true"
658
+ true
659
+ when "false"
660
+ false
661
+ else
662
+ log_warn ( "invalid boolean: #{ value } " )
663
+ nil
664
+ end
665
+ end
666
+
667
+ # Parses a boolean value and returns its inverse. This is used for options where the spec
668
+ # defines the boolean value semantics of enabling/disabling something in the reverse way that
669
+ # the driver does. For instance, the client option `ssl_verify` will disable certificate
670
+ # checking when the value is false, but the spec defines the option
671
+ # `tlsAllowInvalidCertificates`, which disables certificate checking when the value is true.
672
+ #
673
+ # @param value [ String ] The URI option.
674
+ #
675
+ # @return [ true | false | nil ] The inverse of boolean value parsed out, otherwise nil (and a
676
+ # warning will be raised).
677
+ def inverse_bool ( value )
678
+ !bool ( value )
679
+ end
680
+
681
+ # Parses the max staleness value, which must be either "0" or an integer greater or equal to 90.
682
+ #
683
+ # @param value [ String ] The max staleness string.
684
+ #
685
+ # @return [ Integer | nil ] The max staleness integer parsed out if it is valid, otherwise nil
686
+ # (and a warning will be raised).
687
+ def max_staleness ( value )
688
+ if /^\d +$/ =~ value
689
+ int = value . to_i
690
+
691
+ if int == 0 || int >= 90
692
+ return int
693
+ end
694
+ end
695
+
696
+ log_warn ( "Invalid max staleness value: #{ value } " )
697
+ nil
698
+ end
699
+
700
+ # Parses an unsigned integer value.
701
+ #
702
+ # @param value [ String ] The URI option value.
703
+ #
704
+ # @return [ Integer | nil ] The integer parsed out, otherwise nil (and a warning will be
705
+ # raised).
706
+ def unsigned_int ( value )
707
+ unless /^-?\d +$/ =~ value
708
+ log_warn ( "Invalid unsigned integer value: #{ value } " )
709
+ return nil
710
+ end
711
+
712
+ value . to_i
713
+ end
714
+
618
715
# Ruby's convention is to provide timeouts in seconds, not milliseconds and
619
716
# to use fractions where more precision is necessary. The connection string
620
717
# options are always in MS so we provide an easy conversion type.
@@ -625,6 +722,11 @@ def auth_mech_props(value)
625
722
#
626
723
# @since 2.0.0
627
724
def ms_convert ( value )
725
+ unless /^-?\d +(\. \d +)?$/ =~ value
726
+ log_warn ( "Invalid ms value: #{ value } " )
727
+ return nil
728
+ end
729
+
628
730
value . to_f / 1000
629
731
end
630
732
@@ -636,6 +738,11 @@ def ms_convert(value)
636
738
def hash_extractor ( value )
637
739
value . split ( ',' ) . reduce ( { } ) do |set , tag |
638
740
k , v = tag . split ( ':' )
741
+ if v . nil?
742
+ log_warn ( "#{ value } is not a valid URI hash" )
743
+ return nil
744
+ end
745
+
639
746
set . merge ( decode ( k ) . downcase . to_sym => decode ( v ) )
640
747
end
641
748
end
0 commit comments