From 636ff234c917c2db60d2fd1e91dd1cd355825640 Mon Sep 17 00:00:00 2001 From: Richard Bateman Date: Thu, 15 Oct 2015 19:20:01 +0000 Subject: [PATCH] Allow mongodb ssl connections by adding missing parameters for cert, key, and ca --- lib/mosql/cli.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/mosql/cli.rb b/lib/mosql/cli.rb index 4f537ec..ee3fa65 100644 --- a/lib/mosql/cli.rb +++ b/lib/mosql/cli.rb @@ -63,6 +63,18 @@ def parse_args @options[:mongo] = uri end + opts.on("--mongo_sslcert [path]", "Path to the SSL public certificate to use w/ mongo connection (enables SSL)") do |uri| + @options[:mongo_sslcert] = uri + end + + opts.on("--mongo_sslkey [path]", "Path to the SSL private key to use w/ mongo connection (enables SSL)") do |uri| + @options[:mongo_sslkey] = uri + end + + opts.on("--mongo_sslca [path]", "Path to the SSL public CA certificate to use w/ mongo connection (enables SSL)") do |uri| + @options[:mongo_ca] = uri + end + opts.on("--schema [schema]", "PostgreSQL 'schema' to namespace tables") do |schema| @options[:schema] = schema end @@ -121,7 +133,16 @@ def parse_args end def connect_mongo - @mongo = Mongo::MongoClient.from_uri(options[:mongo]) + opts = {} + if options.key?(:mongo_sslcert) && options.key?(:mongo_sslkey) + opts[:ssl] = true + opts[:ssl_cert] = options[:mongo_sslcert] + opts[:ssl_key] = options[:mongo_sslkey] + end + if options.key?(:mongo_sslca) + opts[:ssl_ca_cert] = options[:mongo_sslca] + end + @mongo = Mongo::MongoClient.from_uri(options[:mongo], opts) config = @mongo['admin'].command(:ismaster => 1) if !config['setName'] && !options[:skip_tail] log.warn("`#{options[:mongo]}' is not a replset.")