Skip to content

Commit

Permalink
fix deeplink (#628)
Browse files Browse the repository at this point in the history
* fix deeplink

* Update backup_restore.py

* Update auth.py

* Update backup_restore.py

* Update myst.py

* Update ttn.py

* Update thingsix.py
  • Loading branch information
shawaj authored Jun 27, 2023
1 parent 226ff25 commit a1ce39d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
8 changes: 7 additions & 1 deletion hw_diag/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ def get_login_form():
@authenticate
def get_password_change_form():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
now = datetime.datetime.utcnow()
template_filename = 'password_change_form.html'

return render_template(
template_filename,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
display_lte=False,
now=now
)
Expand All @@ -80,12 +82,14 @@ def handle_password_change():
msg = result.get('msg')
color = result.get('color')
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
now = datetime.datetime.utcnow()
template_filename = 'password_change_form.html'

return render_template(
template_filename,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
display_lte=False,
now=now,
msg=msg,
Expand Down Expand Up @@ -218,7 +222,9 @@ def display_upgrade_page():
@authenticate
def display_openfleet_page():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
return render_template(
'openfleet.html',
diagnostics=diagnostics
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)
8 changes: 7 additions & 1 deletion hw_diag/views/backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from hw_diag.utilities.backup import update_backup_checkpoint
from hw_diag.utilities.balena_supervisor import BalenaSupervisor
from hw_diag.utilities.diagnostics import read_diagnostics_file
from hw_diag.utilities.dashboard_registration import claim_miner_deeplink


logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))
Expand All @@ -25,8 +26,13 @@
@authenticate
def get_backup_page():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()

return render_template('backup_restore.html', diagnostics=diagnostics)
return render_template(
'backup_restore.html',
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)


@BACKUP_RESTORE.route('/backup')
Expand Down
4 changes: 4 additions & 0 deletions hw_diag/views/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def get_diagnostics():
@authenticate
def get_helium_info():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
now = datetime.utcnow()
template_filename = 'helium_info.html'
response = render_template(
template_filename,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
now=now
)
return response
Expand Down Expand Up @@ -300,6 +302,7 @@ def add_security_headers(response):
@authenticate
def get_device_config_page():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
display_lte = should_display_lte(diagnostics)
now = datetime.utcnow()
hostname = get_device_hostname()
Expand All @@ -312,6 +315,7 @@ def get_device_config_page():
now=now,
hostname=hostname,
has_external_antenna_support=has_external_antenna_support(),
claim_deeplink=claim_deeplink
)

return response
Expand Down
3 changes: 3 additions & 0 deletions hw_diag/views/myst.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from hw_diag.utilities.auth import authenticate
from hw_diag.utilities.auth import commercial_fleet_only
from hw_diag.utilities.diagnostics import read_diagnostics_file
from hw_diag.utilities.dashboard_registration import claim_miner_deeplink


logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))
Expand All @@ -22,10 +23,12 @@
@commercial_fleet_only
def get_myst_dashboard():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
now = round(time.time())

return render_template(
'myst.html',
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
now=now
)
40 changes: 34 additions & 6 deletions hw_diag/views/thingsix.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from hw_diag.utilities.thix import is_region_set
from hw_diag.utilities.thix import write_region_file
from hw_diag.utilities.diagnostics import read_diagnostics_file
from hw_diag.utilities.dashboard_registration import claim_miner_deeplink


logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))
Expand Down Expand Up @@ -51,32 +52,53 @@
def get_thix_dashboard():
# If THIX isn't enabled render the setup page.
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()

try:
if get_value('thix_enabled') != 'true':
raise Exception("ThingsIX not enabled yet.")
except Exception:
# Check if region is set, if not set then send user to the set region page...
if not is_region_set():
return render_template(THINGSIX_SET_REGION_TEMPLATE, diagnostics=diagnostics)
return render_template(THINGSIX_SETUP_TEMPLATE, diagnostics=diagnostics)
return render_template(
THINGSIX_SET_REGION_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)
return render_template(
THINGSIX_SETUP_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)

try:
if get_value('thix_onboarded') == 'true':
# Here we must undo the previous testnet stuff...
remove_testnet()
set_value('thix_enabled', 'false')
set_value('thix_onboarded', 'false')
return render_template(THINGSIX_SETUP_TEMPLATE, diagnostics=diagnostics)
return render_template(
THINGSIX_SETUP_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)
except Exception: # nosec
pass

# If THIX is enabled but isn't onboarded render the onboard page.
try:
if get_value('thix_onboarded') != 'mainnet':
render_template(THINGSIX_ONBOARD_TEMPLATE, diagnostics=diagnostics)
render_template(
THINGSIX_ONBOARD_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)
except Exception:
return render_template(THINGSIX_ONBOARD_TEMPLATE, diagnostics=diagnostics)
return render_template(
THINGSIX_ONBOARD_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)

try:
gateways = get_gateways()
Expand All @@ -86,13 +108,15 @@ def get_thix_dashboard():
return render_template(
'thix_dashboard.html',
gateway=gateway,
claim_deeplink=claim_deeplink,
diagnostics=diagnostics
)

except Exception: # nosec
return render_template(
'thix_error.html',
diagnostics=diagnostics
diagnostics=diagnostics,
claim_deeplink=claim_deeplink
)


Expand Down Expand Up @@ -133,12 +157,14 @@ def set_region():
@commercial_fleet_only
def process_onboard(): # noqa:C901
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
# Only allow this if it's currently enabled and not onboarded...
try:
if get_value('thix_enabled') != 'true':
return render_template(
THINGSIX_ONBOARD_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
msg='ThingsIX gateway needs to be enabled before onboarding!'
)
except Exception: # nosec
Expand All @@ -149,6 +175,7 @@ def process_onboard(): # noqa:C901
return render_template(
THINGSIX_ONBOARD_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
msg='ThingsIX gateway already onboarded!'
)
except Exception: # nosec
Expand Down Expand Up @@ -176,6 +203,7 @@ def process_onboard(): # noqa:C901
return render_template(
THINGSIX_ONBOARD_TEMPLATE,
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
msg=('Error occured during onboard. '
'Please check wallet id and try again - %s'
% str(err))
Expand Down
3 changes: 3 additions & 0 deletions hw_diag/views/ttn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from hw_diag.utilities.ttn import write_ttn_config
from hw_diag.utilities.ttn import read_ttn_config
from hw_diag.utilities.diagnostics import read_diagnostics_file
from hw_diag.utilities.dashboard_registration import claim_miner_deeplink


logging.basicConfig(level=os.environ.get("LOGLEVEL", "DEBUG"))
Expand All @@ -25,11 +26,13 @@
@commercial_fleet_only
def get_ttn_dashboard():
diagnostics = read_diagnostics_file()
claim_deeplink = claim_miner_deeplink()
gateway_eui = '0000%s' % generate_default_password().upper()
ttn_config = read_ttn_config()
return render_template(
'ttn_config.html',
diagnostics=diagnostics,
claim_deeplink=claim_deeplink,
gateway_eui=gateway_eui,
ttn_config=ttn_config
)
Expand Down

0 comments on commit a1ce39d

Please sign in to comment.