Skip to content

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_helper module -> :func:platform_token returns None and 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.

logger module-attribute

logger = getLogger('tdfs4ds')

REFRESH_SECONDS module-attribute

REFRESH_SECONDS = 900

_THREAD module-attribute

_THREAD = None

_LOCK module-attribute

_LOCK = Lock()

LAST_FAILURE module-attribute

LAST_FAILURE = None

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.'

_failure_text

_failure_text(exc)

platform_token

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

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

current_logon_token(environ=None)

The token of a token logon (TDFS4DS_TD_LOGDATA='token=...'), else None.

uses_token_logon

uses_token_logon(environ=None)

True when the database logon in environ (default os.environ) is a token.

apply_token

apply_token(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_token again, when one is set;
  • the MCP Authorization: Bearer header, when one is set.

refresh_now

refresh_now()

Renew once. True when a new token was applied; False when nothing to do.

start_refresher

start_refresher(interval=None)

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.