|
| 1 | +"""Maintainer endpoints.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING, Annotated, ClassVar |
| 6 | + |
| 7 | +from litestar import Controller, get |
| 8 | +from litestar.di import Provide |
| 9 | +from litestar.openapi.spec.example import Example |
| 10 | +from litestar.params import Parameter |
| 11 | + |
| 12 | +from hub_api import client # noqa: TC001 |
| 13 | +from hub_api.schemas import api as api_schemas # noqa: TC001 |
| 14 | + |
| 15 | +from .dependencies import get_hub |
| 16 | + |
| 17 | +if TYPE_CHECKING: |
| 18 | + from litestar.types.composite_types import Dependencies |
| 19 | + |
| 20 | + |
| 21 | +class MaintainersController(Controller): |
| 22 | + path = "/meltano/api/v1/maintainers" |
| 23 | + |
| 24 | + dependencies: ClassVar[Dependencies] = { # type: ignore[misc] |
| 25 | + "hub": Provide(get_hub), |
| 26 | + } |
| 27 | + |
| 28 | + @get("/", summary="Get maintainers list") |
| 29 | + async def get_maintainers(self, hub: client.MeltanoHub) -> api_schemas.MaintainersList: # noqa: PLR6301 |
| 30 | + """Retrieve global index of plugins.""" |
| 31 | + return await hub.get_maintainers() |
| 32 | + |
| 33 | + @get("/top", summary="Get top plugin maintainers") |
| 34 | + async def get_top_maintainers( # noqa: PLR6301 |
| 35 | + self, |
| 36 | + hub: client.MeltanoHub, |
| 37 | + count: Annotated[ |
| 38 | + int, |
| 39 | + Parameter( |
| 40 | + ..., |
| 41 | + ge=1, |
| 42 | + lt=50, |
| 43 | + description="The number of maintainers to return", |
| 44 | + ), |
| 45 | + ] = 10, |
| 46 | + ) -> list[api_schemas.MaintainerPluginCount]: |
| 47 | + """Retrieve top maintainers.""" |
| 48 | + return await hub.get_top_maintainers(count) |
| 49 | + |
| 50 | + @get("/{maintainer:str}", summary="Get maintainer details") |
| 51 | + async def get_maintainer( # noqa: PLR6301 |
| 52 | + self, |
| 53 | + hub: client.MeltanoHub, |
| 54 | + maintainer: Annotated[ |
| 55 | + str, |
| 56 | + Parameter( |
| 57 | + ..., |
| 58 | + description="The maintainer identifier", |
| 59 | + pattern=r"^[A-Za-z0-9-_]+$", |
| 60 | + examples=[ |
| 61 | + Example(value="meltanolabs"), |
| 62 | + Example(value="singer-io"), |
| 63 | + ], |
| 64 | + ), |
| 65 | + ], |
| 66 | + ) -> api_schemas.MaintainerDetails: |
| 67 | + """Retrieve maintainer details.""" |
| 68 | + return await hub.get_maintainer(maintainer) |
0 commit comments