Skip to content

Migrate api/link endpoint to FastAPI#13144

Merged
jimchamp merged 1 commit into
internetarchive:masterfrom
Sanket17052006:migrate-api-link
Jul 17, 2026
Merged

Migrate api/link endpoint to FastAPI#13144
jimchamp merged 1 commit into
internetarchive:masterfrom
Sanket17052006:migrate-api-link

Conversation

@Sanket17052006

@Sanket17052006 Sanket17052006 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Closes #

This PR migrates link_ia_ol (/api/link) to FastAPI

Technical

  • Add POST /api/link FastAPI endpoint at openlibrary/fastapi/link.py
  • HMAC verification via HMACToken.verify (unix_time=True) matching legacy behaviour
  • Edition association via accounts.RunAs("ImportBot") + site.save()
  • Legacy link_ia_ol class in openlibrary/plugins/openlibrary/api.py marked @deprecated("migrated to fastapi")

Testing

  • Ran make test-py-uv PYTEST_ARGS="openlibrary/tests/fastapi/test_link.py -v"
  • Add - IA_SYNC_SECRET=${IA_SYNC_SECRET:-} to compose.override.yaml under fast_web.environment:
  • Restart and verify:
    IA_SYNC_SECRET=test-secret docker compose up -d --force-recreate fast_web
python3 << 'PYEOF'
import hmac, hashlib, time
secret = 'test-secret'
msg = f'ocaid-test|OL1M|{int(time.time())+3600}'
d = hmac.new(secret.encode(), msg.encode(), hashlib.sha256).hexdigest()
print(f"curl -X POST http://localhost:18080/api/link -d \"digest={d}&msg={msg}\" -w \"\\nHTTP %{{http_code}}\"")
PYEOF

Verify Scenarios - Valid HM, Bad/forged digest, Expired timestamp and No IA_SYNC_SECRET set

Screenshot

N/A

Stakeholders

@RayBB

@jimchamp
jimchamp merged commit 5dbc391 into internetarchive:master Jul 17, 2026
4 checks passed
@Sanket17052006
Sanket17052006 deleted the migrate-api-link branch July 17, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants