974e782057
- Add dict[str, Any] / list[Any] type params throughout (fingerprint, models, schemas, scanner, status_checker) - Add return type annotations to all route functions (nodes, edges, canvas, scan, auth, status, main) - Fix no-any-return in security.py: cast pwd/jwt results to bool/str explicitly - Fix canvas.py: use model_validate() for NodeResponse/EdgeResponse, rename db_node/db_edge upsert vars - Fix scheduler.py: rename 'result' → 'check_result' to avoid type collision - Fix get_db() return type: AsyncGenerator[AsyncSession, None] - Add types-PyYAML for yaml import stubs - Fix scanner.py: remove unnecessary type: ignore comment (nmap has stubs) - Fix scan.py: wrap scalars().all() with list() for Sequence→list compatibility
32 lines
959 B
Python
32 lines
959 B
Python
from datetime import UTC, datetime, timedelta
|
|
|
|
from jose import JWTError, jwt
|
|
from passlib.context import CryptContext
|
|
|
|
from app.core.config import settings
|
|
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
|
|
|
|
def verify_password(plain: str, hashed: str) -> bool:
|
|
return bool(pwd_context.verify(plain, hashed))
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
return str(pwd_context.hash(password))
|
|
|
|
|
|
def create_access_token(subject: str) -> str:
|
|
expire = datetime.now(UTC) + timedelta(minutes=settings.access_token_expire_minutes)
|
|
payload = {"sub": subject, "exp": expire}
|
|
return str(jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm))
|
|
|
|
|
|
def decode_token(token: str) -> str | None:
|
|
try:
|
|
payload = jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
|
|
sub = payload.get("sub")
|
|
return str(sub) if sub is not None else None
|
|
except JWTError:
|
|
return None
|