File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Schemas for direct user mTLS routes"""
2
+
3
+ from pydantic import Field , BaseModel , ConfigDict
4
+
5
+
6
+ class UserCredentials (BaseModel ):
7
+ """Request to add product interoperability."""
8
+
9
+ username : str = Field (description = "MediaMTX username" )
10
+ password : str = Field (description = "MediaMTX password" )
11
+
12
+ model_config = ConfigDict (
13
+ extra = "forbid" ,
14
+ json_schema_extra = {
15
+ "examples" : [
16
+ {
17
+ "username" : "KOIRA11a" ,
18
+ "password" : "SomethingRandom" , # pragma: allowlist secret
19
+ },
20
+ ],
21
+ },
22
+ )
Original file line number Diff line number Diff line change 17
17
from .instructions import router as irouter
18
18
from .interop import interoprouter
19
19
from .health import hrouter
20
+ from .userdirect import userrouter
20
21
21
22
LOGGER = logging .getLogger (__name__ )
22
23
@@ -46,6 +47,7 @@ def get_app_no_init() -> FastAPI:
46
47
app .include_router (interoprouter , prefix = "/api/v1/interop" , tags = ["interop" ])
47
48
app .include_router (crudrouter , prefix = "/api/v1/users" , tags = ["users" ])
48
49
app .include_router (mtxrouter , prefix = "/api/v1/mediamtx" , tags = ["mediamtx" ])
50
+ app .include_router (userrouter , prefix = "/api/v1/direct" , tags = ["directuser" ])
49
51
app .include_router (irouter , prefix = "/api/v1" , tags = ["instructions" ])
50
52
app .include_router (hrouter , prefix = "/api/v1" , tags = ["health" ])
51
53
return app
Original file line number Diff line number Diff line change
1
+ """APIs usable directly by the user with mTLS"""
2
+
3
+ import logging
4
+
5
+ from fastapi import APIRouter , Depends , Request
6
+ from libpvarki .middleware import MTLSHeader
7
+
8
+ from ..db .user import User
9
+ from ..schema .userdirect import UserCredentials
10
+
11
+ LOGGER = logging .getLogger (__name__ )
12
+
13
+ userrouter = APIRouter (dependencies = [Depends (MTLSHeader (auto_error = True ))])
14
+
15
+
16
+ def get_callsign (request : Request ) -> str :
17
+ """extract callsign from metadata"""
18
+ payload = request .state .mtlsdn
19
+ return str (payload .get ("CN" ))
20
+
21
+
22
+ @userrouter .get ("/credentials" , response_model = UserCredentials )
23
+ async def get_credentials (request : Request ) -> UserCredentials :
24
+ """Get my MediaMTX credentials"""
25
+ user = await User .by_username (get_callsign (request ))
26
+ return UserCredentials (username = user .username , password = user .mtxpassword )
You can’t perform that action at this time.
0 commit comments