I have this code, and the point is I want to dynamically change the mongo connecter to change between ssl, not ssl and with and without username in the same connecter function.
if auth_required:
if config.getboolean(component, 'ssl', fallback=False):
client = MongoClient(
'{host}:{port}'.format(host=config[component]['host'], port=config[component]['port']),
ssl=True,
ssl_ca_certs=config.get(component, 'ssl_path'),
serverSelectionTimeoutMS=timeout,
username=username,
password=password,
authSource=auth_source,
authMechanism=auth_mechanism
)
else:
client = MongoClient(
'{host}:{port}'.format(host=config[component]['host'], port=config[component]['port']),
serverSelectionTimeoutMS=timeout,
username=username,
password=password,
authSource=auth_source,
authMechanism=auth_mechanism
)
else:
if config.getboolean(component, 'ssl', fallback=False):
client = MongoClient(
'{host}:{port}'.format(host=config[component]['host'], port=config[component]['port']),
ssl=True,
ssl_ca_certs=config.get(component, 'ssl_path'),
serverSelectionTimeoutMS=timeout
)
else:
client = MongoClient(
'{host}:{port}'.format(host=config[component]['host'], port=config[component]['port']),
serverSelectionTimeoutMS=timeout
)