Commit 3b3dea8 1 parent 7657214 commit 3b3dea8 Copy full SHA for 3b3dea8
File tree 2 files changed +18
-19
lines changed
2 files changed +18
-19
lines changed Original file line number Diff line number Diff line change 1
- from typing import Annotated
2
-
3
- from fastapi import APIRouter , Path
1
+ from fastapi import APIRouter
4
2
from redis import Redis
5
3
6
4
from src .api .dependencies import SettingsDep
7
- from src .common import PasswordStorage
5
+ from src .common import Password , PasswordStorage , Prefix
8
6
9
7
v1_router = APIRouter (
10
8
prefix = "/api/v1" ,
11
9
)
12
10
13
- PREFIX_REGEX_PATTERN = "^[0-9a-fA-F]{5}$"
14
- APIPrefix = Annotated [
15
- str ,
16
- Path (
17
- description = "5 first chars of a password hash" ,
18
- example = "123AB" ,
19
- pattern = PREFIX_REGEX_PATTERN ,
20
- ),
21
- ]
22
-
23
11
24
- @v1_router .get ("/haveibeenrocked/{prefix}" ) # TODO add response schema to openAPI
25
- def check_password_leak (prefix : APIPrefix , settings : SettingsDep ):
12
+ @v1_router .get ("/haveibeenrocked/{prefix}" )
13
+ def check_password_leak (prefix : Prefix , settings : SettingsDep ) -> dict [ Prefix , set [ Password ]] :
26
14
redis_client = Redis .from_url (str (settings .kvrocks_url ))
27
15
password_storage = PasswordStorage (client = redis_client )
28
16
Original file line number Diff line number Diff line change 1
- # type alias for clarity
2
- Prefix = str # first 5 chars of password's hash
3
- Password = str
1
+ from typing import Annotated
2
+
3
+ from fastapi import Path
4
+
5
+ PREFIX_REGEX_PATTERN = "^[0-9a-fA-F]{5}$" # first 5 chars of password's hash
6
+ Prefix = Annotated [
7
+ str ,
8
+ Path ( # /!\ only enforced on FastApi side
9
+ description = "5 first chars of a password hash" ,
10
+ example = "5c283" ,
11
+ pattern = PREFIX_REGEX_PATTERN ,
12
+ ),
13
+ ]
14
+ Password = str # type alias for clarity
You can’t perform that action at this time.
0 commit comments