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()

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.

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.