Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Allow mongodb ssl connections by adding missing parameters for cert, … #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/mosql/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand Down