Skip to content

trading_agent.doctor.checks.gateway_token_check

Checks that the gateway's access token is set and long enough.

Typical usage example:

result = GatewayTokenCheck(secrets).run()

GatewayTokenCheck

GatewayTokenCheck(secrets)

Bases: DoctorCheck

Checks TRADING_AGENT_GATEWAY_ACCESS_TOKEN without revealing it.

Creates the check.

Parameters:

Name Type Description Default
secrets Secrets

The secrets read from the environment and .env.

required
Source code in src/trading_agent/doctor/checks/gateway_token_check.py
def __init__(self, secrets: secrets_module.Secrets):
    """Creates the check.

    Args:
        secrets (secrets_module.Secrets): The secrets read from the environment and .env.
    """
    self._secrets = secrets

run

run()

Checks that the token is present and at least 32 characters long.

Returns:

Type Description
CheckResult

OK when it is, failed when it is missing or short.

Source code in src/trading_agent/doctor/checks/gateway_token_check.py
def run(self) -> doctor_check.CheckResult:
    """Checks that the token is present and at least 32 characters long.

    Returns:
        doctor_check.CheckResult: OK when it is, failed when it is missing or short.
    """
    token = self._secrets.gateway_access_token
    if not token:
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.FAILED,
            'TRADING_AGENT_GATEWAY_ACCESS_TOKEN is not set in .env.',
        )
    if len(token) < _MINIMUM_LENGTH:
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.FAILED,
            f'The access token is shorter than {_MINIMUM_LENGTH} characters.',
        )
    return doctor_check.CheckResult(
        doctor_check.CheckStatus.OK,
        f'Set ({len(token)} characters).',
    )