diff --git a/drivers/trustpager/__init__.py b/drivers/trustpager/__init__.py index 6041f81..ba1fa38 100644 --- a/drivers/trustpager/__init__.py +++ b/drivers/trustpager/__init__.py @@ -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__). @@ -79,6 +85,7 @@ secret_pattern=TP_SECRET_PATTERN, error_map=TP_ERROR_MAP, approval_url=APPROVAL_URL, + extra_headers=HOME_REGION_HEADERS, ) diff --git a/tests/test_trustpager_driver.py b/tests/test_trustpager_driver.py index e4bf6d7..2b89bfe 100644 --- a/tests/test_trustpager_driver.py +++ b/tests/test_trustpager_driver.py @@ -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()