tdfs4ds.utils.session_token¶
tdfs4ds.utils.session_token
¶
Renew a session token from the platform, where the platform provides one.
On Teradata AI Studio, %gen_token calls the platform module
oauth_token_helper (/opt/oauth_token_helper.py), which asks the
JupyterHub hub for the user's current token; the hub renews it every 20
minutes. Any process of the user's server can call it, so a process that runs
longer than a token (the app) can renew its own instead of failing two hours
after it started.
Inert everywhere else, by construction:
- no
oauth_token_helpermodule -> :func:platform_tokenreturnsNoneand nothing changes; - only a connection that already logs on with a token
(
TDFS4DS_TD_LOGDATA='token=...') is renewed; a password logon is never touched, and the Vector Store / MCP settings are renewed only when they already carry a token.
tdfs4ds reads no unprefixed variable here: the platform's module does, the
same way %gen_token does.
HUB_REFUSED_HINT
module-attribute
¶
HUB_REFUSED_HINT = 'The JupyterHub hub gave no token (%gen_token fails the same way): it answered with a login page instead. Get a token by signing in directly: open_session() does it by itself in a notebook, or run %gen_token_using_device_flow and pass open_session(token=user_token). Logging out of JupyterHub and back in may also help.'
platform_token
¶
A current token from the platform's oauth_token_helper, or None.
None when the module does not exist (any environment but AI Studio) or the platform could not answer. Never raises.
device_flow_token
¶
A token from the platform's device-flow login (%gen_token_using_device_flow), or None.
Shows a link in the notebook, waits for the user to sign in (up to the code's
lifetime, about five minutes) and returns the token. It does not go through the
hub, so it works when :func:platform_token fails. None when the platform
module (td_ai_utils) is absent or the sign-in did not complete. Never raises.
current_logon_token
¶
The token of a token logon (TDFS4DS_TD_LOGDATA='token=...'), else None.
uses_token_logon
¶
True when the database logon in environ (default os.environ) is a token.
apply_token
¶
Put token everywhere this session already uses a token. Returns what changed.
TDFS4DS_TD_LOGDATA(the logon an automatic reconnect uses);- the Vector Store token, then
set_auth_tokenagain, when one is set; - the MCP
Authorization: Bearerheader, when one is set.
refresh_now
¶
Renew once. True when a new token was applied; False when nothing to do.
start_refresher
¶
Renew the token in the background every interval seconds. True when running.
Started only when the logon is a token and the platform provides one; a second call does nothing.