diff --git a/hw_diag/utilities/auth.py b/hw_diag/utilities/auth.py index 327c2968..d794d60a 100644 --- a/hw_diag/utilities/auth.py +++ b/hw_diag/utilities/auth.py @@ -71,19 +71,19 @@ def write_password(password): def read_password(): PASSWORD_OVERRIDE = os.getenv('PASSWORD_OVERRIDE', 'false') - try: - password_row = g.db.query(AuthKeyValue). \ + if PASSWORD_OVERRIDE != "false": # nosec + default_password = PASSWORD_OVERRIDE + password_row = write_password(default_password) + logging.info("Using password from override env var!") + else: + try: + password_row = g.db.query(AuthKeyValue). \ filter(AuthKeyValue.key == 'password_hash'). \ one() - except NoResultFound: - if PASSWORD_OVERRIDE != "false": # nosec - default_password = PASSWORD_OVERRIDE - logging.info("Using password from override env var!") - else: + except NoResultFound: default_password = generate_default_password() + password_row = write_password(default_password) logging.info("No password override. Generating default!") - - password_row = write_password(default_password) return password_row diff --git a/hw_diag/utilities/network.py b/hw_diag/utilities/network.py index fc215b93..2276c5f2 100644 --- a/hw_diag/utilities/network.py +++ b/hw_diag/utilities/network.py @@ -71,19 +71,17 @@ def setup_hostname(): # We don't use boolean here because the field in the DB is a string as we have # some general key value pair table with string values. Sorry bros :-( - if hostname_set_row.value == "false": - logging.info("Hostname not set yet...") + if hostname_set_row.value == "false" or HOSTNAME_OVERRIDE: + logging.info("Hostname not set yet or override enabled...") # Set hostname via Balena supervisor... - default_password = generate_default_password() - hostname_suffix = default_password[6:] - if HOSTNAME_OVERRIDE != "false": hostname = HOSTNAME_OVERRIDE logging.info("Using hostname override from env var!") else: + default_password = generate_default_password() + hostname_suffix = default_password[6:] hostname = "nebra-%s.local" % hostname_suffix logging.info("No hostname override, using default!") - balena_supervisor = BalenaSupervisor.new_from_env() balena_supervisor.set_hostname(hostname) hostname_set_row.value = "true"