File tree Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Original file line number Diff line number Diff line change 5
5
from .clientinfo import router as clientinfo_router
6
6
from .admininfo import router as admininfo_router
7
7
from .healthcheck import router as healthcheck_router
8
+ from .description import router as description_router
9
+
8
10
9
11
all_routers = APIRouter ()
10
12
all_routers .include_router (usercrud_router , prefix = "/users" , tags = ["users" ])
11
13
all_routers .include_router (clientinfo_router , prefix = "/clients" , tags = ["clients" ])
12
14
all_routers .include_router (admininfo_router , prefix = "/admins" , tags = ["admins" ])
13
15
all_routers .include_router (healthcheck_router , prefix = "/healthcheck" , tags = ["healthcheck" ])
16
+ all_routers .include_router (description_router , prefix = "/description" , tags = ["description" ])
Original file line number Diff line number Diff line change 13
13
router = APIRouter (dependencies = [Depends (MTLSHeader (auto_error = True ))])
14
14
15
15
16
- @router .get ("/fragment" )
16
+ @router .get ("/fragment" , deprecated = True )
17
17
async def admin_instruction_fragment () -> UserInstructionFragment :
18
18
"""Return user instructions, we use POST because the integration layer might not keep
19
19
track of callsigns and certs by UUID and will probably need both for the instructions"""
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ def zip_pem(pem: str, filename: str) -> bytes:
22
22
return zip_buffer .getvalue ()
23
23
24
24
25
- @router .post ("/fragment" )
25
+ @router .post ("/fragment" , deprecated = True )
26
26
async def client_instruction_fragment (user : UserCRUDRequest ) -> List [Dict [str , str ]]:
27
27
"""Return user instructions, we use POST because the integration layer might not keep
28
28
track of callsigns and certs by UUID and will probably need both for the instructions"""
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change
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"
You can’t perform that action at this time.
0 commit comments