fix: harden users startup and hashing
This commit is contained in:
@@ -65,6 +65,8 @@ class Settings(BaseSettings):
|
|||||||
CSRF_COOKIE_PATH: str = '/'
|
CSRF_COOKIE_PATH: str = '/'
|
||||||
CSRF_COOKIE_DOMAIN: str | None = None
|
CSRF_COOKIE_DOMAIN: str | None = None
|
||||||
|
|
||||||
|
CORS_ALLOW_ORIGIN_REGEX: str = r'https?://([a-z0-9-]+\.)*elcsa\.ru(:\d+)?$'
|
||||||
|
|
||||||
DOCS_USERNAME: str = 'admin'
|
DOCS_USERNAME: str = 'admin'
|
||||||
DOCS_PASSWORD: str = 'admin'
|
DOCS_PASSWORD: str = 'admin'
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ class HashService(IHashService):
|
|||||||
|
|
||||||
async def hash(self, value: str) -> str:
|
async def hash(self, value: str) -> str:
|
||||||
hashed_value = bcrypt.hashpw(value.encode(), bcrypt.gensalt())
|
hashed_value = bcrypt.hashpw(value.encode(), bcrypt.gensalt())
|
||||||
self._logger.info(f'Hash value {hashed_value.decode()}')
|
|
||||||
return hashed_value.decode()
|
return hashed_value.decode()
|
||||||
|
|
||||||
async def verify(self, hashed_value: str, plain_value: str) -> bool:
|
async def verify(self, hashed_value: str, plain_value: str) -> bool:
|
||||||
self._logger.info(f'Hash value {hashed_value[:10]}')
|
|
||||||
return bcrypt.checkpw(plain_value.encode(), hashed_value.encode())
|
return bcrypt.checkpw(plain_value.encode(), hashed_value.encode())
|
||||||
@@ -66,7 +66,12 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|||||||
|
|
||||||
app.state.jwt_key_store = jwt_store
|
app.state.jwt_key_store = jwt_store
|
||||||
app.state.jwt_keys_scheduler = jwt_scheduler
|
app.state.jwt_keys_scheduler = jwt_scheduler
|
||||||
|
try:
|
||||||
yield
|
yield
|
||||||
|
finally:
|
||||||
|
sched = getattr(app.state,'jwt_keys_scheduler',None)
|
||||||
|
if sched:
|
||||||
|
sched.shutdown(wait=False)
|
||||||
await app.state.redis.aclose()
|
await app.state.redis.aclose()
|
||||||
logger.info(f'Users service instance ended with id {instance_id}')
|
logger.info(f'Users service instance ended with id {instance_id}')
|
||||||
|
|
||||||
@@ -107,7 +112,7 @@ app.add_middleware(
|
|||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=[],
|
allow_origins=[],
|
||||||
allow_origin_regex='.*',
|
allow_origin_regex=settings.CORS_ALLOW_ORIGIN_REGEX,
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=['*'],
|
allow_methods=['*'],
|
||||||
allow_headers=['*'],
|
allow_headers=['*'],
|
||||||
|
|||||||
Reference in New Issue
Block a user