Skip to content

Commit

Permalink
Make echo endpoint return JSON object
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
shenanigansd authored Mar 7, 2024
1 parent 9c1bbcd commit bd1b035
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/reporter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import sentry_sdk

from reporter.constants import GIT_SHA, Sentry
from reporter.http_client import HTTPClientDependency
from reporter.models import Observation, ServerMetadata
from reporter.observations import send_observation
from reporter.pypi_client import PyPIClientDependency
from reporter.models import Observation, ServerMetadata, EchoResponse

from reporter.dependencies import build_graph_client
from reporter.mailer import build_report_email_content, send_mail
Expand All @@ -33,6 +32,13 @@ async def metadata() -> ServerMetadata:
)


@app.get("/echo", summary="Echo the username of the PyPI User")
async def echo(pypi_client: PyPIClientDependency) -> EchoResponse:
"""Return the username of the PyPI User."""
username = await pypi_client.echo()
return EchoResponse(username=username)


@app.post("/report/{project_name}")
async def report_endpoint(project_name: str, observation: Observation, http_client: HTTPClientDependency):
await send_observation(project_name=project_name, observation=observation, http_client=http_client)
Expand Down
6 changes: 6 additions & 0 deletions src/reporter/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class ServerMetadata(BaseModel):
commit: str


class EchoResponse(BaseModel):
"""Reponse from PyPI's echo endpoint."""

username: str


# Taken from
# https://github.com/pypi/warehouse/blob/4d2628560e6e764dc80a026fa080e9cf70446c81/warehouse/observations/models.py#L109-L122
class ObservationKind(Enum):
Expand Down

0 comments on commit bd1b035

Please sign in to comment.