File tree Expand file tree Collapse file tree 2 files changed +18
-19
lines changed
Expand file tree Collapse file tree 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
42from redis import Redis
53
64from src .api .dependencies import SettingsDep
7- from src .common import PasswordStorage
5+ from src .common import Password , PasswordStorage , Prefix
86
97v1_router = APIRouter (
108 prefix = "/api/v1" ,
119)
1210
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-
2311
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 ]] :
2614 redis_client = Redis .from_url (str (settings .kvrocks_url ))
2715 password_storage = PasswordStorage (client = redis_client )
2816
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