Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions drivers/trustpager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
# path. (Removed a duplicate constant here per the Task 3 code-quality finding.)


# Run every call next to TrustPager's database (Sydney). The API otherwise runs
# in the region nearest the caller, and from the Philippines that was Singapore:
# about 3.3 seconds a call against about 1.2 in Sydney, because every database
# read crossed the sea (measured 2026-09-28).
HOME_REGION_HEADERS = {"x-region": "ap-southeast-2"}

# =============================================================================
# The single TrustPager DriverConfig. Constructing it registers the tp_ secret
# pattern with the redaction registry (DriverConfig.__post_init__).
Expand All @@ -79,6 +85,7 @@
secret_pattern=TP_SECRET_PATTERN,
error_map=TP_ERROR_MAP,
approval_url=APPROVAL_URL,
extra_headers=HOME_REGION_HEADERS,
)


Expand Down
9 changes: 9 additions & 0 deletions tests/test_trustpager_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,14 @@ def test_bare_prefix_not_redacted(self):
self.assertEqual(redact(text), text)


class TestHomeRegion(unittest.TestCase):
def test_every_call_asks_for_the_database_region(self):
# Without this header the API runs near the caller (Singapore from the
# Philippines) and each call takes about 3 seconds instead of 1.
from drivers.trustpager import TP_CFG

self.assertEqual((TP_CFG.extra_headers or {}).get("x-region"), "ap-southeast-2")


if __name__ == "__main__":
unittest.main()
Loading