From d7fce217ec5debacad4751aa0c053e756322d7bc Mon Sep 17 00:00:00 2001 From: Lyanis Souidi Date: Mon, 3 Jun 2024 16:38:39 +0200 Subject: [PATCH] Fix bug export db --- app/scodoc/sco_dump_db.py | 7 ++++--- tools/anonymize_db.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/scodoc/sco_dump_db.py b/app/scodoc/sco_dump_db.py index 21abe5e33..875807fc4 100644 --- a/app/scodoc/sco_dump_db.py +++ b/app/scodoc/sco_dump_db.py @@ -129,7 +129,7 @@ def _duplicate_db(db_uri: str, db_name: str, ano_db_uri: str, ano_db_name: str): f"erreur lors de la creation de la base {ano_db_name}" ) from e - cmd = ["pg_dump", db_uri, "|", "psql", ano_db_uri] + cmd = f"pg_dump {db_uri} | psql {ano_db_uri}" log("sco_dump_and_send_db/_duplicate_db: {}".format(cmd)) try: _ = subprocess.check_output(cmd, shell=1) @@ -173,8 +173,9 @@ def _send_db( """Dump this (anonymized) database and send it to tech support""" log(f"dumping anonymized database {ano_db_name}") try: - cmd = ["pg_dump", "--format=custom", ano_db_uri] - dump = subprocess.check_output(cmd, shell=1) + dump = subprocess.check_output( + f"pg_dump --format=custom {ano_db_name}", shell=1 + ) except subprocess.CalledProcessError as e: log(f"sco_dump_and_send_db: exception in anonymisation: {e}") raise ScoValueError( diff --git a/tools/anonymize_db.py b/tools/anonymize_db.py index cdcfc47e1..d98afdea4 100755 --- a/tools/anonymize_db.py +++ b/tools/anonymize_db.py @@ -205,6 +205,8 @@ def anonymize_users(cursor): }, ) +def uri_rm_passwd(uri): + return re.compile(r'(postgres://[^:]+:)([^@]+)(@)').sub(r'\1*****\3', uri) def anonymize_db(cursor): """Traite, une à une, les colonnes indiquées dans ANONYMIZED_FIELDS""" @@ -230,7 +232,7 @@ if __name__ == "__main__": cnx = psycopg2.connect(dburi) except Exception as e: log(f"\n*** Error: can't connect to database {dbname} ***\n") - log(f"""connexion uri was "{re.compile(r'(postgres://[^:]+:)([^@]+)(@)').sub(r'\1*****\3', uri)}" """) + log(f"""connexion uri was "{uri_rm_passwd(dburi)}" """) traceback.print_exc() cnx.set_session(autocommit=False) @@ -242,4 +244,4 @@ if __name__ == "__main__": anonymize_users(cursor) cnx.commit() - cnx.close() + cnx.close() \ No newline at end of file