swxsoc_reach.net.auth#
UDL authentication helpers.
Resolves the UDL HTTP Basic auth credential used by
swxsoc_reach.net.udl.download_UDL_reach_window() (and the legacy
relative-time wrapper). Two sources are supported, in priority order:
The
BASICAUTHenvironment variable (local-dev fallback / what an operator pre-exports).AWS Secrets Manager via
SECRET_ARN_UDL— the secret’sSecretStringis parsed as JSON and thebasicauthfield is used. This matches the existing scheduled-Lambda pattern.
boto3 is imported lazily inside resolve_udl_auth() so this
module remains importable on environments where boto3 is not
installed (e.g. running the package without the net extra and
relying on a pre-set BASICAUTH).
Functions
|
Resolve the UDL HTTP Basic auth credential. |
- swxsoc_reach.net.auth.resolve_udl_auth(region_name: str | None = None) str[source]#
Resolve the UDL HTTP Basic auth credential.
Resolution order:
If
BASICAUTHis set in the environment, return it directly and do not touch AWS.Else if
SECRET_ARN_UDLis set, fetch the secret from AWS Secrets Manager, parse itsSecretStringas JSON, extract thebasicauthfield, write it back toos.environ['BASICAUTH'](so downstream code that reads the env var continues to work unchanged), and return it.Else raise
RuntimeError.
- Parameters:
region_name (str or None, optional) – Optional AWS region passed to
boto3.session.Session. WhenNone,boto3’s standard region resolution chain is used (AWS_REGION/AWS_DEFAULT_REGION/ config file).- Returns:
str – The UDL HTTP Basic auth credential value.
- Raises:
RuntimeError – If neither
BASICAUTHnorSECRET_ARN_UDLis set, if theboto3package is not installed when Secrets Manager resolution is attempted, or if the secret payload does not contain abasicauthkey.