Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use override values even if already set #683

Open
wants to merge 4 commits into
base: shawaj/hostname
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions hw_diag/utilities/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 4 additions & 6 deletions hw_diag/utilities/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading