feat(proxy): route outbound requests through single authenticated http_proxy#12724
Conversation
There was a problem hiding this comment.
Pull request overview
Adds per-service HTTP proxy configuration to support authenticated squid ACLs (fixing #12715) while keeping existing global http_proxy behavior as the default fallback.
Changes:
- Introduces
get_proxy_params(service_tag)to build arequests-compatibleproxiesdict fromhttp_proxies.<service>config. - Routes reCAPTCHA verification through the per-service proxy configuration when present.
- Updates the affiliate server to prefer
http_proxies.amazonwhile retaining backward compatibility with legacy proxy config keys.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/affiliate_server.py | Prefer http_proxies.amazon for Amazon proxy settings, with fallback to legacy flat keys. |
| openlibrary/plugins/upstream/utils.py | Add get_proxy_params() helper for service-specific proxy (including auth). |
| openlibrary/plugins/recaptcha/recaptcha.py | Pass proxies=get_proxy_params("recaptcha") to the verification request. |
| conf/openlibrary.yml | Document the new http_proxies config shape (commented examples). |
bfc7d8c to
940f8f8
Compare
93e1643 to
7822fec
Compare
Investigation: Amazon 403 on worker restartRoot cause identified. The The flow:
Why it worked initially: The token was valid in-process during the session. The failure only surfaces when the token expires (~1hr) or, more visibly, on every worker restart (cold cache → immediate refresh attempt). Our PR does not fix this. Our change is backward-compatible in production (falls back to Fix options (not in this PR — needs a follow-up):
Recommended: Option 1 (add to |
jimchamp
left a comment
There was a problem hiding this comment.
I'm not certain that the is_lwa method exists on OAuth2Config objects. Other than that, this looks okay to me.
Configuring the recaptcha URL has caused a merge conflict on this branch.
9939df3 to
ed7d782
Compare
70282ac to
6943d7d
Compare
|
Hi — I'm Pierre, an AI-assisted PR health agent running on behalf of @mekarpeles. Folded 1 bot commit: The The single unresolved Copilot thread ( Note: This PR still has a merge conflict (CONFLICTING). The conflict is in semantic code (not mechanical), so it's been left for @mekarpeles to resolve manually. Safeguards: Confirmed all non-bot commits authored by @mekarpeles. Used To reverse: |
|
Pushed an update (f0a2aff) that simplifies the proxy implementation significantly. Root cause that was fixed upstream
What changed in this commit
Tested on End-to-end test via |
c92958b to
19a390a
Compare
537729c to
fdf21f1
Compare
…p_proxy Replaces the per-service http_proxies config (with separate url/user/password per service) with a single http_proxy URL containing embedded credentials (e.g. http://user:pass@proxy.example.com:3128). - vendors.py: AmazonCreatorsAPI passes proxy URL directly to the fork's python-amazon-paapi proxy= kwarg; removes credential-building logic - affiliate_server.py: load_config() reads http_proxy directly - utils.py: removes get_proxy_params() — proxy now handled via env vars set by setup_requests(), which requests picks up automatically - recaptcha.py: removes explicit proxies= kwarg; relies on setup_requests() - test_utils.py: removes TestGetProxyParams tests - conf/openlibrary.yml: documents the new single-URL proxy config format - requirements.txt: pins python-amazon-paapi to mekarpeles/proxy-support fork
fdf21f1 to
b148937
Compare
for more information, see https://pre-commit.ci
…egression fix(proxy): restore 5 items dropped by bad rebase in #12724
…12724 The rebase on internetarchive#12724 (single http_proxy consolidation) incorrectly dropped changes from master that the proxy refactor had no relation to: - conf/openlibrary.yml: restore otp_seed dev seed (needed by OTP auth) - conf/openlibrary.yml: restore sentry.frontend DSN block (Sentry JS) - conf/openlibrary.yml: restore profiles_sample_rate: 0.05 (was 0.001) - conf/openlibrary.yml: restore author_exclusions: [] (404 exclusions) - requirements.txt: restore cryptography==44.0.2 (Fernet cookie encrypt) The cryptography omission is the most critical: accounts/model.py imports Fernet at runtime for S3 key cookie encryption, so its absence causes ModuleNotFoundError on any code path touching S3 auth cookies. Verified: docker compose run --rm home python -m pytest \ openlibrary/tests/core/test_processors.py -x -v # 9 passed docker compose run --rm home python -c \ "from cryptography.fernet import Fernet; print('OK')" # cryptography OK Closes internetarchive#12724 regression
Summary
Routes all outbound service calls (Amazon Creators API, reCAPTCHA) through a single
http_proxyURL with embedded credentials — the model ops now supports.Before: per-service
http_proxies.{amazon,recaptcha}entries with separateurl,user,passwordkeys and manual URL construction inget_proxy_params().After: flat
http_proxy: http://user:pass@proxy:8080in config, consumed bysetup_requests()(setsHTTP_PROXY/HTTPS_PROXYenv vars) and passed directly to the Amazon API client.Changes
openlibrary/core/vendors.py—AmazonCreatorsAPItakesproxy_url: str = ""and passes it to the mekarpeles/python-amazon-paapi@proxy-support fork'sproxy=kwarg (covers both urllib3 REST leg and OAuth2 token refresh via requests)scripts/affiliate_server.py—load_config()reads flatconfig.get("http_proxy")instead of per-servicehttp_proxies.amazonblockopenlibrary/plugins/recaptcha/recaptcha.py— drops explicitproxies=get_proxy_params("recaptcha"); relies on env vars set bysetup_requests()which requests honours automaticallyopenlibrary/plugins/upstream/utils.py— removesget_proxy_params()entirelyconf/openlibrary.yml— documents single-URL proxy formatrequirements.txt— pins tomekarpeles/python-amazon-paapi@proxy-supportforkTesting
Pre-commit clean (mypy/generate-pot skip locally as expected).
Related
Closes #12715
See also: sergioteula/python-amazon-paapi#150