From df081a9c59e04cf33ffbdba388e49b001748b3ad Mon Sep 17 00:00:00 2001 From: Jae Lo Presti Date: Wed, 18 May 2022 21:43:20 +0300 Subject: [PATCH 1/5] hash_password: raise an error if no config file is specified (#11548) --- synapse/_scripts/hash_password.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/_scripts/hash_password.py b/synapse/_scripts/hash_password.py index 3aa29de5bd8a..d5a39bd450d7 100755 --- a/synapse/_scripts/hash_password.py +++ b/synapse/_scripts/hash_password.py @@ -54,6 +54,8 @@ def main() -> None: bcrypt_rounds = config.get("bcrypt_rounds", bcrypt_rounds) password_config = config.get("password_config", None) or {} password_pepper = password_config.get("pepper", password_pepper) + else: + raise Exception("The specified config file could not be found or is missing.") password = args.password if not password: From 59cf3e3dee4024baf2b2325c4dae61530303866b Mon Sep 17 00:00:00 2001 From: Jae Lo Presti Date: Wed, 18 May 2022 22:01:18 +0300 Subject: [PATCH 2/5] hash_password: more explicit error message --- synapse/_scripts/hash_password.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/_scripts/hash_password.py b/synapse/_scripts/hash_password.py index d5a39bd450d7..ca986599809e 100755 --- a/synapse/_scripts/hash_password.py +++ b/synapse/_scripts/hash_password.py @@ -55,7 +55,7 @@ def main() -> None: password_config = config.get("password_config", None) or {} password_pepper = password_config.get("pepper", password_pepper) else: - raise Exception("The specified config file could not be found or is missing.") + raise Exception("Please specify a path to a config file (-c).") password = args.password if not password: From 22aba37d8e6ff1d7781ea482d50654a06c7107eb Mon Sep 17 00:00:00 2001 From: Jae Lo Presti Date: Wed, 18 May 2022 22:04:59 +0300 Subject: [PATCH 3/5] changelod.d: add changelog file --- changelog.d/12789.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12789.misc diff --git a/changelog.d/12789.misc b/changelog.d/12789.misc new file mode 100644 index 000000000000..cd6c7dc015c5 --- /dev/null +++ b/changelog.d/12789.misc @@ -0,0 +1 @@ +The hash_password script now returns an exception when it is called without specifying a config file. From 1c6648e1786740204e2b05201408989fc60da772 Mon Sep 17 00:00:00 2001 From: Jae Lo Presti Date: Thu, 19 May 2022 15:29:57 +0300 Subject: [PATCH 4/5] hash_password: use required=True to have cleaner logic --- synapse/_scripts/hash_password.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/synapse/_scripts/hash_password.py b/synapse/_scripts/hash_password.py index ca986599809e..3bed367be29d 100755 --- a/synapse/_scripts/hash_password.py +++ b/synapse/_scripts/hash_password.py @@ -46,16 +46,14 @@ def main() -> None: "Path to server config file. " "Used to read in bcrypt_rounds and password_pepper." ), + required=True, ) args = parser.parse_args() - if "config" in args and args.config: - config = yaml.safe_load(args.config) - bcrypt_rounds = config.get("bcrypt_rounds", bcrypt_rounds) - password_config = config.get("password_config", None) or {} - password_pepper = password_config.get("pepper", password_pepper) - else: - raise Exception("Please specify a path to a config file (-c).") + config = yaml.safe_load(args.config) + bcrypt_rounds = config.get("bcrypt_rounds", bcrypt_rounds) + password_config = config.get("password_config", None) or {} + password_pepper = password_config.get("pepper", password_pepper) password = args.password if not password: From 0d7b1f8959ff721ca6c0e0077a9c99cac6fc56cd Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 19 May 2022 13:38:30 +0100 Subject: [PATCH 5/5] Tweak the changelog --- changelog.d/12789.misc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/12789.misc b/changelog.d/12789.misc index cd6c7dc015c5..3398d00110c8 100644 --- a/changelog.d/12789.misc +++ b/changelog.d/12789.misc @@ -1 +1 @@ -The hash_password script now returns an exception when it is called without specifying a config file. +The `hash_password` script now fails when it is called without specifying a config file.