Skip to content

tdfs4ds.serve.sessions

tdfs4ds.serve.sessions

Time-boxed Connect-page sessions for the admin app (0.3.7.10).

The app has no login: it uses one database identity. When that identity is typed on the Connect page, two optional limits (minutes, read at each use) bound how long it lives:

  • TDFS4DS_SERVE_SESSION_TTL: inactivity. A user request restarts the clock; the status poll, static files, /health and the documentation do not.
  • TDFS4DS_SERVE_SESSION_MAX: absolute lifetime since the Connect, activity or not.

On expiry the TDFS4DS_TD_* values the form set are forgotten (the values that were in the environment before the form are put back), teradataml's context is closed, the app is marked disconnected with the reason, and the health monitor stops probing. Connect again to continue. Neither variable set = nothing here does anything. An app started with operator credentials and never connected through the form is not expired: use a JWT token there.

TDFS4DS_SERVE_CONNECT_PAGE=off refuses the Connect page and POST /ui/connect. Nothing in this module returns or logs a credential value.

logger module-attribute

logger = logging.getLogger('tdfs4ds.serve')

WARN_BEFORE_S module-attribute

WARN_BEFORE_S = 120

_LOCK module-attribute

_LOCK = threading.RLock()

_LOCAL module-attribute

_LOCAL = threading.local()

_SAVED module-attribute

_SAVED: dict = {}

_STATE module-attribute

_STATE: dict = {}

CONNECT_PAGE_OFF_MESSAGE module-attribute

CONNECT_PAGE_OFF_MESSAGE = 'The Connect page is switched off on this server (TDFS4DS_SERVE_CONNECT_PAGE=off): the connection is set by the operator and cannot be changed from the app.'

IGNORED module-attribute

IGNORED = ('/ui/status', '/health', '/ui/static', '/static', '/documentation', '/docs', '/openapi.json', '/favicon.ico')

SessionClock

Started-at / last-activity bookkeeping for ONE session, with an inactivity limit and an absolute limit (seconds, None = no limit). Pure: the clock is time.monotonic.

The Connect-page session below is one instance; a login gate can keep one per cookie session and reuse touch / remaining / due unchanged.

started instance-attribute

started = time.monotonic() if now is None else now

last_activity instance-attribute

last_activity = time.monotonic() if now is None else now

__init__

__init__(ttl_s=None, max_s=None, now=None)

touch

touch(now=None)

remaining

remaining(now=None)

due

due(now=None)

None while valid, else 'max' or 'idle' (the limit that ran out).

_reset

_reset() -> None

_minutes

_minutes(name: str) -> Optional[float]

ttl_minutes

ttl_minutes() -> Optional[float]

max_minutes

max_minutes() -> Optional[float]

limits_configured

limits_configured() -> bool

connect_page_enabled

connect_page_enabled() -> bool

connect_refusal

connect_refusal() -> str

recording

recording()

Within this block, env changes made through :func:set_env / :func:pop_env are remembered so that expiry can undo them. Used by the Connect page only.

_note

_note(var: str) -> None

set_env

set_env(var: str, value) -> None

pop_env

pop_env(var: str) -> None

start

start() -> None

A Connect-page logon succeeded: open the session (when limits are set).

expired

expired() -> bool

is_activity_path

is_activity_path(path: str) -> bool

A request that shows someone is using the app. The status poll, static files, /health and the documentation do not (they would keep a forgotten tab alive).

touch

touch(path: str = '/ui/x') -> None

_jobs_running

_jobs_running() -> bool

remaining

remaining() -> Optional[dict]

Seconds left on each limit, or None when no session is under limits.

_fmt

_fmt(minutes) -> str

check

check() -> bool

Expire the session if a limit has run out. True when it expired now.

A background job (an index build, a rebuild) counts as activity for the inactivity limit, not for the maximum.

expire

expire(reason: str, close: bool = True) -> None

Forget the form's credentials, disconnect, record the reason.

snapshot

snapshot() -> dict

For the status bar. No credential, no host name.