Skip to content

Commit fd7b51d

Browse files
šŸ“ Add docstrings to codex/refactor-_process-to-use-own-sqlalchemy-session (#154)
Docstrings generation was requested by @shayancoin. * #90 (comment) The following files were modified: * `backend/api/routes_sync.py` * `backend/api/security.py` * `backend/tests/test_sync_routes_metrics.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Shayan <shayan@coin.link>
1 parent bf54ca7 commit fd7b51d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

ā€Žbackend/api/routes_sync.pyā€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ async def hygraph_webhook(
129129
raise HTTPException(status_code=400, detail=_error_envelope("BAD_REQUEST", "Invalid JSON payload"))
130130

131131
async def _process(event_id_local: Optional[str], body_sha_local: str) -> None:
132+
"""
133+
Perform the background Hygraph sync: pull all content, update Prometheus metrics, and log success or failure.
134+
135+
Parameters:
136+
event_id_local (Optional[str]): Optional sync event identifier used for logging and correlation.
137+
body_sha_local (str): SHA-256 of the webhook body used for correlation in logs and metrics.
138+
"""
132139
t0 = time.perf_counter()
133140
with _tracer.start_as_current_span("hygraph.pull_all") as pull_span:
134141
pull_span.set_attribute("retry.count", 0)

ā€Žbackend/api/security.pyā€Ž

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515

1616

1717
def _load_expected_write_token(settings: Settings) -> str:
18-
"""Resolve the configured API write token from settings or environment."""
18+
"""
19+
Resolve the API write token from the provided settings or the API_WRITE_TOKEN environment variable.
20+
21+
Parameters:
22+
settings (Settings): Configuration object that may contain an `api_write_token` attribute.
23+
24+
Returns:
25+
str: The resolved token with surrounding whitespace removed; an empty string if no token is configured.
26+
"""
1927

2028
token = getattr(settings, "api_write_token", None)
2129
if isinstance(token, str) and token.strip():
@@ -137,4 +145,4 @@ async def validate_hygraph_request(
137145
raise HTTPException(status_code=HTTP_401_UNAUTHORIZED, detail="Invalid signature")
138146
request.state.raw_body = body
139147
request.state.body_sha256 = hashlib.sha256(body).hexdigest()
140-
return True
148+
return True

ā€Žbackend/tests/test_sync_routes_metrics.pyā€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
def _sig(secret: str, body: bytes) -> str:
1919
# x-hygraph-signature uses sha256=<hex>
20+
"""
21+
Compute an HMAC-SHA256 signature for a request body using the given secret.
22+
23+
Returns:
24+
A string in the form "sha256=<hex digest>" containing the lowercase hexadecimal HMAC-SHA256 of the body (the secret is encoded as UTF-8).
25+
"""
2026
return "sha256=" + hmac.new(secret.encode("utf-8"), body, hashlib.sha256).hexdigest()
2127

2228

@@ -95,4 +101,4 @@ async def fake_pull_modules(db, page_size=None):
95101
)
96102
assert r.status_code == 200
97103
assert r.json()["ok"] is True
98-
assert r.json()["data"]["processed"] == 5
104+
assert r.json()["data"]["processed"] == 5

0 commit comments

Comments
Ā (0)