htpasswd: raise error on del if user is not exist

This commit is contained in:
Maxim Devaev
2025-02-13 14:20:33 +02:00
parent 30a82efea4
commit dd3f4c16e3
2 changed files with 14 additions and 3 deletions

View File

@@ -136,8 +136,15 @@ def _cmd_set(config: Section, options: argparse.Namespace) -> None:
def _cmd_delete(config: Section, options: argparse.Namespace) -> None:
with _get_htpasswd_for_write(config) as htpasswd:
assert options.user == options.user.strip()
assert options.user
has_user = (options.user in htpasswd.users())
if not has_user:
raise SystemExit(f"The user {options.user!r} is not exist")
htpasswd.delete(options.user)
if has_user and not options.quiet:
_print_invalidate_tip(False)