Method: Puppet::Provider::Mongodb.mongosh_cmd

Defined in:
lib/puppet/provider/mongodb.rb

.mongosh_cmd(db, host, cmd) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/puppet/provider/mongodb.rb', line 62

def self.mongosh_cmd(db, host, cmd)
  config = mongo_conf

  host = conn_string if host.nil? || host.split(':')[0] == Facter.value(:fqdn) || host == '127.0.0.1'

  args = [db, '--quiet', '--host', host]
  args.push('--ipv6') if ipv6_is_enabled(config)

  if tls_is_enabled(config)
    args.push('--tls')
    args += ['--tlsCertificateKeyFile', config['tlscert']]

    tls_ca = config['tlsca']
    args += ['--tlsCAFile', tls_ca] unless tls_ca.nil?

    args.push('--tlsAllowInvalidHostnames') if tls_invalid_hostnames(config)
    args.push('--tlsAllowInvalidCertificates') if tls_invalid_certificates(config)
  end

  args += ['--eval', cmd]
  mongosh(args)
end