From b9d523351072b65702e1987274aa0dd2904b4dba Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Thu, 5 Dec 2019 00:38:58 +0100 Subject: [PATCH] Do not expose db passwords when pinging --- restic_compose_backup/commands.py | 6 ++---- restic_compose_backup/containers_db.py | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/restic_compose_backup/commands.py b/restic_compose_backup/commands.py index fad7947..8773b58 100644 --- a/restic_compose_backup/commands.py +++ b/restic_compose_backup/commands.py @@ -9,7 +9,7 @@ def test(): return run_command(['ls', '/volumes']) -def ping_mysql(host, port, username, password) -> int: +def ping_mysql(host, port, username) -> int: """Check if the mysql is up and can be reached""" return run([ 'mysqladmin', @@ -20,11 +20,10 @@ def ping_mysql(host, port, username, password) -> int: port, '--user', username, - f'--password={password}', ]) -def ping_mariadb(host, port, username, password) -> int: +def ping_mariadb(host, port, username): #, password) -> int: """Check if the mariadb is up and can be reached""" return run([ 'mysqladmin', @@ -35,7 +34,6 @@ def ping_mariadb(host, port, username, password) -> int: port, '--user', username, - f'--password={password}', ]) diff --git a/restic_compose_backup/containers_db.py b/restic_compose_backup/containers_db.py index 813f641..5ad3ce0 100644 --- a/restic_compose_backup/containers_db.py +++ b/restic_compose_backup/containers_db.py @@ -22,12 +22,13 @@ class MariadbContainer(Container): def ping(self) -> bool: """Check the availability of the service""" creds = self.get_credentials() - return commands.ping_mysql( - creds['host'], - creds['port'], - creds['username'], - creds['password'], - ) + + with utils.environment('MYSQL_PWD', creds['password']): + return commands.ping_mariadb( + creds['host'], + creds['port'], + creds['username'], + ) def dump_command(self) -> list: """list: create a dump command restic and use to send data through stdin""" @@ -67,12 +68,13 @@ class MysqlContainer(Container): def ping(self) -> bool: """Check the availability of the service""" creds = self.get_credentials() - return commands.ping_mysql( - creds['host'], - creds['port'], - creds['username'], - creds['password'], - ) + + with utils.environment('MYSQL_PWD', creds['password']): + return commands.ping_mysql( + creds['host'], + creds['port'], + creds['username'], + ) def dump_command(self) -> list: """list: create a dump command restic and use to send data through stdin"""