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