58 lines
2.7 KiB
Python
58 lines
2.7 KiB
Python
"""Runtime configuration read from environment variables.
|
|
|
|
AppFactory injects variables/secrets as environment variables (see AGENTS.md).
|
|
This module holds only NON-secret infrastructure configuration. Per-request
|
|
credentials are never stored here - they arrive in X- headers (see
|
|
``app.credentials``).
|
|
"""
|
|
import os
|
|
|
|
# Public app metadata
|
|
APP_NAME = os.getenv("APP_NAME", "Meta services")
|
|
APP_VERSION = os.getenv("APP_VERSION", "1.0.0")
|
|
|
|
# Reverse-proxy prefix injected by AppFactory (e.g. "/apps/meta").
|
|
# Empty when running locally at the domain root.
|
|
ROOT_PATH = os.getenv("ROOT_PATH", "")
|
|
|
|
# --- Meta Graph / Marketing API ----------------------------------------------
|
|
# Base URL is configurable so we can point at a staging/mock endpoint, but
|
|
# defaults to the production Graph endpoint.
|
|
META_GRAPH_BASE_URL = os.getenv("META_GRAPH_BASE_URL", "https://graph.facebook.com")
|
|
|
|
# Default Graph API version. Meta ships a new version every few months and
|
|
# deprecates old ones after ~2 years, so the version lives in an env var (same
|
|
# reasoning as GOOGLE_ADS_API_VERSION in the sibling `analytics` service).
|
|
# Callers may additionally override it per request via X-Meta-Api-Version.
|
|
META_API_VERSION = os.getenv("META_API_VERSION", "v25.0")
|
|
|
|
# Optional comma-separated allowlist of versions accepted in X-Meta-Api-Version.
|
|
# Empty (default) = accept any well-formed "vNN.N" value, so upgrading the Graph
|
|
# version never needs a deploy on our side. Set it to lock the service down to
|
|
# versions that have actually been tested.
|
|
META_ALLOWED_API_VERSIONS = tuple(
|
|
v.strip()
|
|
for v in os.getenv("META_ALLOWED_API_VERSIONS", "").split(",")
|
|
if v.strip()
|
|
)
|
|
|
|
# Safety cap for cursor-paged reads. Auto-paging is the default (all_pages), so
|
|
# this is the backstop that keeps a runaway edge from looping forever. Mirrors
|
|
# the Sklik report page cap in `analytics`: a truncated result says so
|
|
# explicitly instead of silently looking complete.
|
|
# Graph's own page size defaults to 25, so 100 pages ~ 2500 rows; pass a larger
|
|
# `limit` to cover more rows in fewer round trips.
|
|
META_MAX_PAGES = int(os.getenv("META_MAX_PAGES", "100"))
|
|
|
|
# --- Async insights jobs ------------------------------------------------------
|
|
# Large insights reports are run as async jobs on Meta's side (start job ->
|
|
# poll -> read results). These bound the convenience "run and wait" endpoint.
|
|
META_ASYNC_POLL_INTERVAL_SECONDS = float(
|
|
os.getenv("META_ASYNC_POLL_INTERVAL_SECONDS", "2")
|
|
)
|
|
META_ASYNC_MAX_WAIT_SECONDS = float(os.getenv("META_ASYNC_MAX_WAIT_SECONDS", "120"))
|
|
|
|
# --- HTTP ---------------------------------------------------------------------
|
|
# Upstream request timeout in seconds.
|
|
HTTP_TIMEOUT_SECONDS = float(os.getenv("HTTP_TIMEOUT_SECONDS", "60"))
|