From c75ea649853b3bba25cb4f53a69dc2848166da48 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sat, 25 Feb 2023 20:03:37 +0100 Subject: [PATCH] Make the auth logic more explicit and warnings if necessary --- borgmatic/hooks/ntfy.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/borgmatic/hooks/ntfy.py b/borgmatic/hooks/ntfy.py index fd3b9881b..2d8bb6bd5 100644 --- a/borgmatic/hooks/ntfy.py +++ b/borgmatic/hooks/ntfy.py @@ -59,11 +59,14 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_ username = hook_config.get('username') password = hook_config.get('password') - auth = ( - requests.auth.HTTPBasicAuth(username, password) - if (username and password) is not None - else None - ) + auth = None + if (username and password) is not None: + auth = requests.auth.HTTPBasicAuth(username, password) + logger.info(f'{config_filename}: Using basic auth with user {username} for Ntfy') + elif username is not None: + logger.warn(f'{config_filename}: Password missing for Ntfy authentication, defaulting to no auth') + elif password is not None: + logger.warn(f'{config_filename}: Username missing for Ntfy authentication, defaulting to no auth') if not dry_run: logging.getLogger('urllib3').setLevel(logging.ERROR)