44from fastapi_sqlalchemy import DBSessionMiddleware
55from starlette .middleware .cors import CORSMiddleware
66
7+ from sqladmin import Admin
8+ from sqlalchemy import create_engine
9+ from auth_backend .admin .admin import ScopeAdmin , GroupAdmin , UserAdmin
10+
711from auth_backend import __version__
812from auth_backend .auth_method import AuthPluginMeta
913from auth_backend .kafka .kafka import get_kafka_producer
@@ -23,6 +27,9 @@ async def lifespan(app: FastAPI):
2327
2428
2529settings = get_settings ()
30+
31+ engine = create_engine (str (settings .DB_DSN ))
32+
2633app = FastAPI (
2734 title = 'Сервис аутентификации и авторизации' ,
2835 description = (
@@ -37,6 +44,8 @@ async def lifespan(app: FastAPI):
3744 lifespan = lifespan ,
3845)
3946
47+ admin = Admin (app , engine = engine , title = 'Admin panel' )
48+
4049app .add_middleware (
4150 DBSessionMiddleware ,
4251 db_url = str (settings .DB_DSN ),
@@ -51,6 +60,10 @@ async def lifespan(app: FastAPI):
5160 allow_headers = settings .CORS_ALLOW_HEADERS ,
5261)
5362
63+ admin .add_view (GroupAdmin )
64+ admin .add_view (ScopeAdmin )
65+ admin .add_view (UserAdmin )
66+
5467app .include_router (groups_router )
5568app .include_router (scopes_router )
5669app .include_router (user_router )
0 commit comments