From b7423c488e9df2174cbbbbaebdf5a9c6f319b9c6 Mon Sep 17 00:00:00 2001 From: Divyansh Singh Date: Thu, 15 Jun 2023 22:54:06 +0530 Subject: [PATCH] refactor password assignment logic --- borgmatic/actions/restore.py | 2 +- borgmatic/hooks/postgresql.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/borgmatic/actions/restore.py b/borgmatic/actions/restore.py index 6d8eb4e..532c587 100644 --- a/borgmatic/actions/restore.py +++ b/borgmatic/actions/restore.py @@ -72,7 +72,7 @@ def restore_single_database( ): # pragma: no cover ''' Given (among other things) an archive name, a database hook name, the hostname, - port, username and password as connection params, and a configured database + port, username and password as connection params, and a configured database configuration dict, restore that database from the archive. ''' logger.info( diff --git a/borgmatic/hooks/postgresql.py b/borgmatic/hooks/postgresql.py index c90ae63..8672028 100644 --- a/borgmatic/hooks/postgresql.py +++ b/borgmatic/hooks/postgresql.py @@ -30,7 +30,10 @@ def make_extra_environment(database, restore_connection_params=None): extra = dict() try: - extra['PGPASSWORD'] = restore_connection_params.get('password') or database['restore_password'] or database['password'] + if restore_connection_params: + extra['PGPASSWORD'] = restore_connection_params.get('password') or database.get('restore_password', database['password']) + else: + extra['PGPASSWORD'] = database['password'] except (AttributeError, KeyError): pass