Skip to content

Commit 240c28a

Browse files
author
maxim-lixakov
committed
[DOP-21268] - add SessionSettings
1 parent e1efdaa commit 240c28a

File tree

12 files changed

+93
-13
lines changed

12 files changed

+93
-13
lines changed

.env.docker

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ SYNCMASTER__LOGGING__SETUP=True
99
SYNCMASTER__LOGGING__PRESET=colored
1010
SYNCMASTER__LOG_URL_TEMPLATE=https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}
1111

12+
# Session
13+
SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key
14+
1215
# Encrypt / Decrypt credentials data
1316
SYNCMASTER__CRYPTO_KEY=UBgPTioFrtH2unlC4XFDiGf5sYfzbdSf_VgiUSaQc94=
1417

.env.local

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export SYNCMASTER__LOGGING__SETUP=True
99
export SYNCMASTER__LOGGING__PRESET=colored
1010
export SYNCMASTER__LOG_URL_TEMPLATE="https://grafana.example.com?correlation_id={{ correlation_id }}&run_id={{ run.id }}"
1111

12+
# Session
13+
export SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key
14+
1215
# Encrypt / Decrypt credentials data
1316
export SYNCMASTER__CRYPTO_KEY=UBgPTioFrtH2unlC4XFDiGf5sYfzbdSf_VgiUSaQc94=
1417

docs/backend/configuration/cors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ CORS settings
55

66
These settings used to control `CORS <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS>`_ options.
77

8-
.. autopydantic_model:: syncmaster.settings.server.cors.CORSSettings
8+
.. autopydantic_model:: syncmaster.backend.settings.server.cors.CORSSettings

docs/backend/configuration/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Configuration
1111
database
1212
broker
1313
logging
14+
session
1415
cors
1516
debug
1617
monitoring

docs/backend/configuration/monitoring.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ REST API server provides the following endpoints with Prometheus compatible metr
1313

1414
These endpoints are enabled and configured using settings below:
1515

16-
.. autopydantic_model:: syncmaster.settings.server.monitoring.MonitoringSettings
16+
.. autopydantic_model:: syncmaster.backend.settings.server.monitoring.MonitoringSettings

docs/backend/configuration/openapi.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ OpenAPI settings
55

66
These settings used to control exposing OpenAPI.json and SwaggerUI/ReDoc endpoints.
77

8-
.. autopydantic_model:: syncmaster.settings.server.openapi.OpenAPISettings
9-
.. autopydantic_model:: syncmaster.settings.server.openapi.SwaggerSettings
10-
.. autopydantic_model:: syncmaster.settings.server.openapi.RedocSettings
11-
.. autopydantic_model:: syncmaster.settings.server.openapi.LogoSettings
12-
.. autopydantic_model:: syncmaster.settings.server.openapi.FaviconSettings
8+
.. autopydantic_model:: syncmaster.backend.settings.server.openapi.OpenAPISettings
9+
.. autopydantic_model:: syncmaster.backend.settings.server.openapi.SwaggerSettings
10+
.. autopydantic_model:: syncmaster.backend.settings.server.openapi.RedocSettings
11+
.. autopydantic_model:: syncmaster.backend.settings.server.openapi.LogoSettings
12+
.. autopydantic_model:: syncmaster.backend.settings.server.openapi.FaviconSettings
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _backend-configuration-server-session:
2+
3+
Session settings
4+
================
5+
6+
These settings used to control `Session <https://developer.mozilla.org/en-US/docs/Web/HTTP/Session>`_ options.
7+
8+
.. autopydantic_model:: syncmaster.backend.settings.server.session.SessionSettings

docs/backend/configuration/static_files.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Serving static files
55

66
These settings used to control serving static files by a server.
77

8-
.. autopydantic_model:: syncmaster.settings.server.static_files.StaticFilesSettings
8+
.. autopydantic_model:: syncmaster.backend.settings.server.static_files.StaticFilesSettings

syncmaster/backend/middlewares/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ def apply_middlewares(
2929
apply_request_id_middleware(application, settings.server.request_id)
3030
apply_openapi_middleware(application, settings.server.openapi)
3131
apply_static_files(application, settings.server.static_files)
32-
apply_session_middleware(application)
32+
apply_session_middleware(application, settings.server.session)
3333

3434
return application
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# SPDX-FileCopyrightText: 2023-2024 MTS PJSC
22
# SPDX-License-Identifier: Apache-2.0
3-
import secrets
43

54
from fastapi import FastAPI
65
from starlette.middleware.sessions import SessionMiddleware
76

7+
from syncmaster.backend.settings.server.session import SessionSettings
88

9-
def apply_session_middleware(app: FastAPI) -> FastAPI:
9+
10+
def apply_session_middleware(app: FastAPI, settings: SessionSettings) -> FastAPI:
1011
"""Add SessionMiddleware middleware to the application."""
11-
secret_key = secrets.token_urlsafe(32)
12-
app.add_middleware(SessionMiddleware, secret_key=secret_key)
12+
13+
app.add_middleware(
14+
SessionMiddleware,
15+
**settings.dict(),
16+
)
1317
return app

0 commit comments

Comments
 (0)