Skip to content

Commit 675788b

Browse files
committed
Add product description endpoint
1 parent cb965e5 commit 675788b

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

src/rmfpapi/api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
from .clientinfo import router as clientinfo_router
66
from .admininfo import router as admininfo_router
77
from .healthcheck import router as healthcheck_router
8+
from .description import router as description_router
9+
810

911
all_routers = APIRouter()
1012
all_routers.include_router(usercrud_router, prefix="/users", tags=["users"])
1113
all_routers.include_router(clientinfo_router, prefix="/clients", tags=["clients"])
1214
all_routers.include_router(admininfo_router, prefix="/admins", tags=["admins"])
1315
all_routers.include_router(healthcheck_router, prefix="/healthcheck", tags=["healthcheck"])
16+
all_routers.include_router(description_router, prefix="/description", tags=["description"])

src/rmfpapi/api/admininfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
router = APIRouter(dependencies=[Depends(MTLSHeader(auto_error=True))])
1414

1515

16-
@router.get("/fragment")
16+
@router.get("/fragment", deprecated=True)
1717
async def admin_instruction_fragment() -> UserInstructionFragment:
1818
"""Return user instructions, we use POST because the integration layer might not keep
1919
track of callsigns and certs by UUID and will probably need both for the instructions"""

src/rmfpapi/api/clientinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def zip_pem(pem: str, filename: str) -> bytes:
2222
return zip_buffer.getvalue()
2323

2424

25-
@router.post("/fragment")
25+
@router.post("/fragment", deprecated=True)
2626
async def client_instruction_fragment(user: UserCRUDRequest) -> List[Dict[str, str]]:
2727
"""Return user instructions, we use POST because the integration layer might not keep
2828
track of callsigns and certs by UUID and will probably need both for the instructions"""

src/rmfpapi/api/description.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Descriptions API"""
2+
from typing import Optional
3+
import logging
4+
5+
from fastapi import APIRouter
6+
from pydantic import BaseModel, Extra, Field # pylint: disable=(no-name-in-module # false-positive
7+
8+
LOGGER = logging.getLogger(__name__)
9+
10+
router = APIRouter() # These endpoints are public
11+
12+
13+
# FIXME: Move to libpvarki
14+
class ProductDescription(BaseModel): # pylint: disable=too-few-public-methods
15+
"""Description of a product"""
16+
17+
shortname: str = Field(description="Short name for the product, used as slug/key in dicts and urls")
18+
title: str = Field(description="Fancy name for the product")
19+
icon: Optional[str] = Field(description="URL for icon")
20+
description: str = Field(description="Short-ish description of the product")
21+
language: str = Field(description="Language of this response")
22+
23+
class Config: # pylint: disable=too-few-public-methods
24+
"""Pydantic configs"""
25+
26+
extra = Extra.forbid
27+
28+
29+
@router.get(
30+
"/{language}",
31+
response_model=ProductDescription,
32+
deprecated=True,
33+
)
34+
async def return_product_description(language: str) -> ProductDescription:
35+
"""Fetch description from each product in manifest"""
36+
_ = language
37+
return ProductDescription(
38+
shortname="fake",
39+
title="Fake Product",
40+
icon=None,
41+
description="Fake product for integrations testing and examples",
42+
language="en",
43+
)

tests/test_description.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Test description endpoint"""
2+
import logging
3+
4+
import pytest
5+
from fastapi.testclient import TestClient
6+
7+
LOGGER = logging.getLogger(__name__)
8+
9+
10+
@pytest.mark.parametrize("lang", ["en", "fi"])
11+
def test_get_description(mtlsclient: TestClient, lang: str) -> None:
12+
"""Check getting the description"""
13+
resp = mtlsclient.get(f"api/v1/description/{lang}")
14+
assert resp.status_code == 200
15+
payload = resp.json()
16+
assert payload["shortname"] == "fake"
17+
assert payload["language"] == "en"

0 commit comments

Comments
 (0)