From d4c50b5c87fe7e858a04acaf4464e88c90575a7e Mon Sep 17 00:00:00 2001 From: Hamid Zare <12127420+hamidzr@users.noreply.github.com> Date: Thu, 11 Jul 2024 09:17:12 -0500 Subject: [PATCH] chore: set cli pwd warning go to stderr (#9536) --- harness/determined/cli/user.py | 6 +----- harness/determined/common/api/authentication.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/harness/determined/cli/user.py b/harness/determined/cli/user.py index 97753c3e26d..2bb359bed83 100644 --- a/harness/determined/cli/user.py +++ b/harness/determined/cli/user.py @@ -83,11 +83,7 @@ def log_in_user(args: argparse.Namespace) -> None: try: authentication.check_password_complexity(password) except ValueError as e: - print( - "Warning: your password does not appear to satisfy " - + f"recommended complexity requirements:\n{e}\n" - + "Please change your password as soon as possible." - ) + authentication.warn_about_complexity(e) token_store.set_token(sess.username, sess.token) token_store.set_active(sess.username) diff --git a/harness/determined/common/api/authentication.py b/harness/determined/common/api/authentication.py index ef4fcc5daee..7eea446c6b0 100644 --- a/harness/determined/common/api/authentication.py +++ b/harness/determined/common/api/authentication.py @@ -5,6 +5,7 @@ import os import pathlib import re +import sys from typing import Any, Dict, Iterator, List, Optional, Tuple from urllib import parse @@ -23,6 +24,15 @@ def salt_and_hash(password: str) -> str: return password +def warn_about_complexity(e: ValueError) -> None: + print( + "Warning: your password does not appear to satisfy " + + f"recommended complexity requirements:\n{e}\n" + + "Please change your password as soon as possible.", + file=sys.stderr, + ) + + def check_password_complexity(password: Optional[str]) -> None: """Raises a ValueError if the password does not meet complexity requirements. @@ -239,11 +249,7 @@ def login_with_cache( try: check_password_complexity(password) except ValueError as e: - print( - "Warning: your password does not appear to satisfy " - + f"recommended complexity requirements:\n{e}\n" - + "Please change your password as soon as possible." - ) + warn_about_complexity(e) token_store.set_token(user, token)