Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mongodb_credentials_prompt():
logging.info('Configuring SEML. Warning: Password will be stored in plain text.')
host = get_nonempty_input("MongoDB host")
port = input('Port (default: 27017):')
port = "27017" if port == "" else port
database = get_nonempty_input("database name")
username = get_nonempty_input("user name")
password = get_nonempty_input("password")
file_path = SETTINGS.DATABASE.MONGODB_CONFIG_PATH
config_string = (f'username: {username}\n'
f'password: {password}\n'
f'port: {port}\n'
f'database: {database}\n'
f'host: {host}')
logging.info(f"Saving the following configuration to {file_path}:\n"
f"{config_string.replace(f'password: {password}', 'password: ********')}"
)
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, 'w') as f:
f.write(config_string)
def get_mongodb_config(path=SETTINGS.DATABASE.MONGODB_CONFIG_PATH):
"""Read the MongoDB connection configuration.
Reads the file at the provided path or otherwise {SETTINGS.DATABASE.MONGODB_CONFIG_PATH} to get
- database host
- database port
- database name
- username
- password
Default path is $HOME/.config/seml/mongodb.config.
Config file should be in the format:
username:
password:
port:
database:
def get_mongodb_config(path=SETTINGS.DATABASE.MONGODB_CONFIG_PATH):
"""Read the MongoDB connection configuration.
Reads the file at the provided path or otherwise {SETTINGS.DATABASE.MONGODB_CONFIG_PATH} to get
- database host
- database port
- database name
- username
- password
Default path is $HOME/.config/seml/mongodb.config.
Config file should be in the format:
username:
password:
port:
database: