Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0850b3c

Browse files
authored
feat(mongodb_shell): Add TLS options (ansible-collections#644)
Signed-off-by: Julien Riou <[email protected]>
1 parent f1186ff commit 0850b3c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

plugins/modules/mongodb_shell.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
2525
extends_documentation_fragment:
2626
- community.mongodb.login_options
27+
- community.mongodb.ssl_options
2728
2829
options:
2930
mongo_cmd:
@@ -195,7 +196,7 @@
195196
__metaclass__ = type
196197

197198
from ansible_collections.community.mongodb.plugins.module_utils.mongodb_common import (
198-
mongodb_common_argument_spec
199+
load_mongocnf, mongodb_common_argument_spec
199200
)
200201

201202
from ansible_collections.community.mongodb.plugins.module_utils.mongodb_shell import (
@@ -208,7 +209,7 @@
208209

209210

210211
def main():
211-
argument_spec = mongodb_common_argument_spec(ssl_options=False)
212+
argument_spec = mongodb_common_argument_spec(ssl_options=True)
212213
argument_spec.update(
213214
mongo_cmd=dict(type='str', default="mongosh"),
214215
file=dict(type='str', required=False),
@@ -267,16 +268,34 @@ def main():
267268

268269
omit = module.params['omit']
269270

271+
username = module.params['login_user']
272+
password = module.params['login_password']
273+
274+
credentials = load_mongocnf()
275+
if credentials:
276+
if not username:
277+
username = credentials['user']
278+
if not password:
279+
password = credentials['password']
280+
270281
args = add_arg_to_cmd(args, "--host", module.params['login_host'], omit=omit)
271282
args = add_arg_to_cmd(args, "--port", module.params['login_port'], omit=omit)
272-
args = add_arg_to_cmd(args, "--username", module.params['login_user'], omit=omit)
273-
args = add_arg_to_cmd(args, "--password", module.params['login_password'], omit=omit)
283+
args = add_arg_to_cmd(args, "--username", username, omit=omit)
284+
args = add_arg_to_cmd(args, "--password", password, omit=omit)
274285
args = add_arg_to_cmd(args, "--authenticationDatabase", module.params['login_database'], omit=omit)
286+
args = add_arg_to_cmd(args, "--authenticationMechanism", module.params['auth_mechanism'], omit=omit)
275287
args = add_arg_to_cmd(args, "--eval", module.params['eval'], omit=omit)
276288
args = add_arg_to_cmd(args, "--nodb", None, module.params['nodb'], omit=omit)
277289
args = add_arg_to_cmd(args, "--norc", None, module.params['norc'], omit=omit)
278290
args = add_arg_to_cmd(args, "--quiet", None, module.params['quiet'], omit=omit)
279291

292+
args = add_arg_to_cmd(args, "--tls", None, module.params['ssl'], omit=omit)
293+
args = add_arg_to_cmd(args, "--tlsAllowInvalidCertificates", None, module.params['ssl_cert_reqs'] in ('CERT_NONE', 'CERT_OPTIONAL'), omit=omit)
294+
args = add_arg_to_cmd(args, "--tlsCAFile", module.params['ssl_ca_certs'], omit=omit)
295+
args = add_arg_to_cmd(args, "--tlsCRLFile", module.params['ssl_crlfile'], omit=omit)
296+
args = add_arg_to_cmd(args, "--tlsCertificateKeyFile", module.params['ssl_keyfile'], omit=omit)
297+
args = add_arg_to_cmd(args, "--tlsCertificateKeyFilePassword", module.params['ssl_pem_passphrase'], omit=omit)
298+
280299
additional_args = module.params['additional_args']
281300
if additional_args is not None:
282301
for key, value in additional_args.items():

0 commit comments

Comments
 (0)