From 4faf8d1934bfb0837802859fa27590be1d7d356c Mon Sep 17 00:00:00 2001 From: jayme-github Date: Sun, 7 Jul 2013 17:27:41 +0200 Subject: [PATCH] Allow to set password in configuration --- bakthat/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bakthat/__init__.py b/bakthat/__init__.py index bdf44da..e76ea07 100755 --- a/bakthat/__init__.py +++ b/bakthat/__init__.py @@ -286,7 +286,18 @@ def backup(filename=os.getcwd(), destination=None, profile="default", config=CON # Useful only when using bakmanager.io hook backup_key = key - password = kwargs.get("password", os.environ.get("BAKTHAT_PASSWORD")) + # Check if a password is set in the configuration. + if conf: + password = conf.get("password", None) + else: + password = config.get(profile).get("password", None) + + # Password may still be overridden by environment variable BAKTHAT_PASSWORD + # or when given as argument + if kwargs.get("password", os.environ.get("BAKTHAT_PASSWORD")): + password = kwargs.get("password", os.environ.get("BAKTHAT_PASSWORD")) + + # If we still have no password and prompt is not disabled, prompt for it if password is None and prompt.lower() != "no": password = getpass("Password (blank to disable encryption): ") if password: