@@ -41,6 +41,9 @@ def self.get_mongo_conf
4141 config_hash [ 'bindip' ] = config [ 'net.bindIp' ]
4242 config_hash [ 'port' ] = config [ 'net.port' ]
4343 config_hash [ 'ipv6' ] = config [ 'net.ipv6' ]
44+ config_hash [ 'ssl' ] = config [ 'net.ssl.mode' ]
45+ config_hash [ 'sslcert' ] = config [ 'net.ssl.PEMKeyFile' ]
46+ config_hash [ 'sslca' ] = config [ 'net.ssl.CAFile' ]
4447 config_hash [ 'auth' ] = config [ 'security.authorization' ]
4548 config_hash [ 'shardsvr' ] = config [ 'sharding.clusterRole' ]
4649 config_hash [ 'confsvr' ] = config [ 'sharding.clusterRole' ]
@@ -53,6 +56,9 @@ def self.get_mongo_conf
5356 config_hash [ 'bindip' ] = config [ 'bind_ip' ]
5457 config_hash [ 'port' ] = config [ 'port' ]
5558 config_hash [ 'ipv6' ] = config [ 'ipv6' ]
59+ config_hash [ 'ssl' ] = config [ 'sslMode' ]
60+ config_hash [ 'sslcert' ] = config [ 'sslPEMKeyFile' ]
61+ config_hash [ 'sslca' ] = config [ 'sslCAFile' ]
5662 config_hash [ 'auth' ] = config [ 'auth' ]
5763 config_hash [ 'shardsvr' ] = config [ 'shardsvr' ]
5864 config_hash [ 'confsvr' ] = config [ 'confsvr' ]
@@ -66,9 +72,28 @@ def self.ipv6_is_enabled(config=nil)
6672 config [ 'ipv6' ]
6773 end
6874
75+ def self . ssl_is_enabled ( config = nil )
76+ config ||= get_mongo_conf
77+ ssl_mode = config . fetch ( 'ssl' )
78+ ssl_mode . nil? ? false : ssl_mode != 'disabled'
79+ end
80+
6981 def self . mongo_cmd ( db , host , cmd )
82+ config = get_mongo_conf
83+
7084 args = [ db , '--quiet' , '--host' , host ]
71- args . push ( '--ipv6' ) if ipv6_is_enabled
85+ args . push ( '--ipv6' ) if ipv6_is_enabled ( config )
86+
87+ if ssl_is_enabled ( config )
88+ args . push ( '--ssl' )
89+ args += [ '--sslPEMKeyFile' , config [ 'sslcert' ] ]
90+
91+ ssl_ca = config [ 'sslca' ]
92+ unless ssl_ca . nil?
93+ args += [ '--sslCAFile' , ssl_ca ]
94+ end
95+ end
96+
7297 args += [ '--eval' , cmd ]
7398 mongo ( args )
7499 end
0 commit comments