File size: 1,827 Bytes
1fe7075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Prevision renderer authentication and internal allowance service configuration."""

from config.loader import config_value

AUTH_ENFORCEMENT = str(config_value("AUTH_ENFORCEMENT", "auth", "enforcement", "off")).strip().lower()
if AUTH_ENFORCEMENT not in {"off", "on"}:
    raise RuntimeError("AUTH_ENFORCEMENT must be 'off' or 'on'")
AUTH_ENFORCED = AUTH_ENFORCEMENT == "on"

PROCESSING_TOKEN_SECRET = str(config_value("PROCESSING_TOKEN_SECRET", "auth", "processing_token_secret", ""))
PROCESSING_TOKEN_AUDIENCE = str(config_value(
    "PROCESSING_TOKEN_AUDIENCE", "auth", "processing_token_audience", "prevision-processing",
))
TOKEN_ISSUER = str(config_value("TOKEN_ISSUER", "auth", "token_issuer", "prevision-api"))
# The Prevision API (apps/prevision-api) issues processing tokens. Its users have free
# tries: each accepted job is charged to that API, and refunded if it fails.
PREVISION_TOKEN_ISSUER = "prevision-api"
TOKEN_ISSUERS = (TOKEN_ISSUER,)
PREVISION_API_INTERNAL_URL = str(config_value(
    "PREVISION_API_INTERNAL_URL", "auth", "prevision_api_internal_url", "http://127.0.0.1:8001",
)).rstrip("/")
PREVISION_INTERNAL_AUDIENCE = "prevision-internal"
# Allowed clock drift between the account API and this service.
TOKEN_LEEWAY_SECONDS = int(config_value("TOKEN_LEEWAY_SECONDS", "auth", "token_leeway_seconds", "30"))

if AUTH_ENFORCED and len(PROCESSING_TOKEN_SECRET) < 32:
    raise RuntimeError("AUTH_ENFORCEMENT=on requires PROCESSING_TOKEN_SECRET (32+ characters)")

# Comma-separated browser origins. Tokens travel in the Authorization header,
# never in cookies, so a wildcard does not expose ambient credentials.
CORS_ALLOWED_ORIGINS = [
    origin.strip().rstrip("/")
    for origin in str(config_value("CORS_ALLOWED_ORIGINS", "auth", "cors_allowed_origins", "*")).split(",")
    if origin.strip()
]