feat(webpage): add force_start_webpage() to manually override account-match check #268

Merged
holler merged 1 commits from feat/web_upload into main 2026-07-22 10:11:36 +02:00
3 changed files with 40 additions and 2 deletions
@@ -244,6 +244,13 @@ class LamNI(TomoQueueMixin, LamNIAlignmentMixin, LamNIOpticsMixin, LamniGuiTools
"""Set the web password for the current BEC account."""
self._webpage_gen.set_web_password(password)
def force_start_webpage(self) -> None:
"""Manually force-start the webpage uploader with real upload enabled,
bypassing the account-match check. For testing/debugging sessions only
(e.g. verifying uploads from the allowed subnet, or verifying the
remote server blocks uploads from outside it)."""
self._webpage_gen.start(force=True)
def _maybe_reset_params_on_account_change(self) -> None:
"""Offer a tomo-parameter reset when the active account has changed.
@@ -58,6 +58,7 @@ Interactive helpers (optional, in the iPython session):
flomni._webpage_gen.verbosity = 3 # DEBUG: full JSON per cycle
flomni._webpage_gen.stop() # release lock, stop local server
flomni._webpage_gen.start() # restart after stop()
flomni._webpage_gen.start(force=True) # bypass account-match check (testing only)
flomni._webpage_gen.set_web_password("pw") # set web password for current e-account
Session authentication:
@@ -80,6 +81,13 @@ starts a *local-only* status page on a separate port (default 8081, see
mismatch_local_port) for local debugging: no singleton lock (so it can never
block the real session's takeover), no remote upload, no session.htpasswd
changes. Look for "[local-only: account mismatch]" in the startup log / status().
For testing/debugging sessions that intentionally run under a mismatched
account, start(force=True) skips this fallback and always takes the real
path (singleton lock, remote upload, session.htpasswd changes) -- e.g. to
verify uploads work from the allowed subnet, or to verify the remote
server's IP whitelist rejects uploads from outside it. See force_start_webpage()
on the Flomni/LamNI setup classes for the console-facing wrapper.
"""
import datetime
@@ -491,7 +499,7 @@ class WebpageGeneratorBase:
# Public API
# ------------------------------------------------------------------
def start(self) -> None:
def start(self, force: bool = False) -> None:
"""Start the generator.
If this session already holds the thread, does nothing.
@@ -499,8 +507,18 @@ class WebpageGeneratorBase:
is launched that polls every 3 s and takes over as soon as the lock
goes stale — no blocking, no second call to start() needed.
Progress messages during the wait are printed at verbosity >= 2 only.
force=True skips the BEC-account/system-user match check and always
takes the real (non-local-only) path: singleton lock, remote upload,
session.htpasswd changes — as if the account matched. For manual
testing/debugging only (e.g. verifying uploads work from the allowed
subnet, or verifying the remote server rejects uploads from outside
it) when running under a mismatched account. Logged at warning level
since it bypasses a safety check and can affect the shared web page.
"""
if not _check_account_match(self._bec):
account_match = _check_account_match(self._bec)
if not force and not account_match:
if self._thread is not None and self._thread.is_alive():
self._log(VERBOSITY_NORMAL, "WebpageGenerator already running in this session.")
return
@@ -513,6 +531,12 @@ class WebpageGeneratorBase:
self._launch(local_only=True)
return
if force and not account_match:
self._log(VERBOSITY_NORMAL,
"WebpageGenerator: force-starting with real upload despite "
"BEC account / system user mismatch (manual override).",
level="warning")
if self._thread is not None and self._thread.is_alive():
self._log(VERBOSITY_NORMAL, "WebpageGenerator already running in this session.")
return
@@ -1659,6 +1659,13 @@ class Flomni(
"""Set the web password for the current BEC account."""
self._webpage_gen.set_web_password(password)
def force_start_webpage(self) -> None:
"""Manually force-start the webpage uploader with real upload enabled,
bypassing the account-match check. For testing/debugging sessions only
(e.g. verifying uploads from the allowed subnet, or verifying the
remote server blocks uploads from outside it)."""
self._webpage_gen.start(force=True)
def _maybe_reset_params_on_account_change(self) -> None:
"""Offer a tomo-parameter reset when the active account has changed.