Compare commits
51 Commits
VORKOUT-9
...
VORKOUT-6-
Author | SHA1 | Date | |
---|---|---|---|
15bc323ee4 | |||
958f00069f | |||
d7a5109d8e | |||
8122f1878a | |||
9d2aef5671 | |||
34be97996e | |||
e0dca78ef3 | |||
0bba6e7f54 | |||
21216a6ad5 | |||
2bf0f20e73 | |||
abd87b46b3 | |||
787dc0e8f8 | |||
2e4e9d1113 | |||
c1d315d6e9 | |||
|
a31758192d | ||
8965365afc | |||
|
c68286f7cc | ||
|
58cc23f79b | ||
|
48d52bf903 | ||
|
66c60cfc59 | ||
|
c60d19262e | ||
|
31236d558f | ||
|
5094b84675 | ||
7e1fe6f5c4 | |||
|
320c13183f | ||
|
98a4692247 | ||
8613cbdaac | |||
5f981e8ce1 | |||
98e425862c | |||
|
96dbc744d7 | ||
|
e47e449a36 | ||
86d48d0d1c | |||
|
c3c421f66f | ||
fe91bb7103 | |||
f97d419467 | |||
131102beba | |||
881a72a66c | |||
de06890f6a | |||
8191ee3a48 | |||
|
eb63ebb10f | ||
|
3554d43d15 | ||
|
19f8236b47 | ||
f1214e7b5a | |||
dbe3e3ab86 | |||
|
b90b70568c | ||
|
23329e7d36 | ||
|
22e2bca83c | ||
|
f67ef7f96f | ||
|
8271737ce2 | ||
|
29027bf9f8 | ||
|
1333992dc5 |
12
Makefile
12
Makefile
@@ -39,12 +39,22 @@ revision:
|
|||||||
|
|
||||||
venv-api:
|
venv-api:
|
||||||
cd api && \
|
cd api && \
|
||||||
|
poetry env activate \
|
||||||
poetry install
|
poetry install
|
||||||
|
|
||||||
install:
|
install:
|
||||||
make migrate head && \
|
make migrate head && \
|
||||||
cd api && \
|
cd api && \
|
||||||
poetry run python3 api/utils/init.py
|
poetry run python3 -m api.utils.init
|
||||||
|
|
||||||
%::
|
%::
|
||||||
echo $(MESSAGE)
|
echo $(MESSAGE)
|
||||||
|
|
||||||
|
format-api:
|
||||||
|
cd api && \
|
||||||
|
poetry run ruff format .
|
||||||
|
|
||||||
|
|
||||||
|
check-api:
|
||||||
|
cd api && \
|
||||||
|
poetry run ruff format . --check
|
||||||
|
@@ -9,9 +9,10 @@ from uvicorn import run
|
|||||||
from api.config import get_settings, DefaultSettings
|
from api.config import get_settings, DefaultSettings
|
||||||
from api.endpoints import list_of_routes
|
from api.endpoints import list_of_routes
|
||||||
from api.utils.common import get_hostname
|
from api.utils.common import get_hostname
|
||||||
|
from api.services.middleware import MiddlewareAccessTokenValidadtion
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def bind_routes(application: FastAPI, setting: DefaultSettings) -> None:
|
def bind_routes(application: FastAPI, setting: DefaultSettings) -> None:
|
||||||
@@ -32,7 +33,7 @@ def get_app() -> FastAPI:
|
|||||||
description=description,
|
description=description,
|
||||||
docs_url="/swagger",
|
docs_url="/swagger",
|
||||||
openapi_url="/openapi",
|
openapi_url="/openapi",
|
||||||
version="0.1.0",
|
version="0.0.2",
|
||||||
)
|
)
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
bind_routes(application, settings)
|
bind_routes(application, settings)
|
||||||
@@ -44,6 +45,7 @@ app = get_app()
|
|||||||
|
|
||||||
dev_origins = [
|
dev_origins = [
|
||||||
"http://localhost:3000",
|
"http://localhost:3000",
|
||||||
|
"http://127.0.0.1:64775",
|
||||||
]
|
]
|
||||||
|
|
||||||
prod_origins = [""]
|
prod_origins = [""]
|
||||||
@@ -71,6 +73,7 @@ if __name__ == "__main__":
|
|||||||
log_level="info",
|
log_level="info",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
app.add_middleware(MiddlewareAccessTokenValidadtion)
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=origins,
|
allow_origins=origins,
|
||||||
|
@@ -18,7 +18,8 @@ class DbCredentialsSchema(BaseModel):
|
|||||||
class DefaultSettings(BaseSettings):
|
class DefaultSettings(BaseSettings):
|
||||||
ENV: str = environ.get("ENV", "local")
|
ENV: str = environ.get("ENV", "local")
|
||||||
PATH_PREFIX: str = environ.get("PATH_PREFIX", "/api/v1")
|
PATH_PREFIX: str = environ.get("PATH_PREFIX", "/api/v1")
|
||||||
APP_HOST: str = environ.get("APP_HOST", "http://127.0.0.1")
|
# APP_HOST: str = environ.get("APP_HOST", "http://127.0.0.1")
|
||||||
|
APP_HOST: str = environ.get("APP_HOST", "http://localhost")
|
||||||
APP_PORT: int = int(environ.get("APP_PORT", 8000))
|
APP_PORT: int = int(environ.get("APP_PORT", 8000))
|
||||||
APP_ID: uuid.UUID = environ.get("APP_ID", uuid.uuid4())
|
APP_ID: uuid.UUID = environ.get("APP_ID", uuid.uuid4())
|
||||||
LOGS_STORAGE_PATH: str = environ.get("LOGS_STORAGE_PATH", "storage/logs")
|
LOGS_STORAGE_PATH: str = environ.get("LOGS_STORAGE_PATH", "storage/logs")
|
||||||
@@ -44,6 +45,12 @@ class DefaultSettings(BaseSettings):
|
|||||||
REDIS_DB: int = int(environ.get("REDIS_DB", "0"))
|
REDIS_DB: int = int(environ.get("REDIS_DB", "0"))
|
||||||
REDIS_PASSWORD: str = environ.get("REDIS_PASSWORD", "hackme")
|
REDIS_PASSWORD: str = environ.get("REDIS_PASSWORD", "hackme")
|
||||||
|
|
||||||
|
SECRET_KEY: str = environ.get("SECRET_KEY", "secret")
|
||||||
|
ALGORITHM: str = environ.get("ALGORITHM", "HS256")
|
||||||
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = int(environ.get("ACCESS_TOKEN_EXPIRE_MINUTES", 600))
|
||||||
|
|
||||||
|
REFRESH_TOKEN_EXPIRE_DAYS: int = int(environ.get("REFRESH_TOKEN_EXPIRE_DAYS_LONG", 365))
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def database_settings(self) -> dict:
|
def database_settings(self) -> dict:
|
||||||
"""Get all settings for connection with database."""
|
"""Get all settings for connection with database."""
|
||||||
|
138
api/api/db/alembic/versions/f1b06efacec0_.py
Normal file
138
api/api/db/alembic/versions/f1b06efacec0_.py
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: f1b06efacec0
|
||||||
|
Revises:
|
||||||
|
Create Date: 2025-04-23 15:09:14.833213
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'f1b06efacec0'
|
||||||
|
down_revision: Union[str, None] = None
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
"""Upgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.create_table('account',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=100), nullable=False),
|
||||||
|
sa.Column('login', sa.String(length=100), nullable=False),
|
||||||
|
sa.Column('email', sa.String(length=100), nullable=True),
|
||||||
|
sa.Column('bind_tenant_id', sa.String(length=40), nullable=True),
|
||||||
|
sa.Column('role', sa.Enum('OWNER', 'ADMIN', 'EDITOR', 'VIEWER', name='accountrole'), nullable=False),
|
||||||
|
sa.Column('meta', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('creator_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=True),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'DISABLED', 'BLOCKED', 'DELETED', name='accountstatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['account.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index('idx_login', 'account', ['login'], unique=False)
|
||||||
|
op.create_index('idx_name', 'account', ['name'], unique=False)
|
||||||
|
op.create_table('account_keyring',
|
||||||
|
sa.Column('owner_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('key_type', sa.Enum('PASSWORD', 'ACCESS_TOKEN', 'REFRESH_TOKEN', 'API_KEY', name='keytype'), nullable=False),
|
||||||
|
sa.Column('key_id', sa.String(length=40), nullable=False),
|
||||||
|
sa.Column('key_value', sa.String(length=255), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('expiry', sa.DateTime(timezone=True), nullable=True),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'EXPIRED', 'DELETED', name='keystatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['owner_id'], ['account.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('owner_id', 'key_type', 'key_id')
|
||||||
|
)
|
||||||
|
op.create_table('list_events',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=40, collation='latin1_bin'), nullable=False),
|
||||||
|
sa.Column('title', sa.String(length=64), nullable=False),
|
||||||
|
sa.Column('creator_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('schema', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('state', sa.Enum('AUTO', 'DESCRIPTED', name='eventstate'), nullable=False),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'DISABLED', 'DELETED', name='eventstatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['account.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
sa.UniqueConstraint('name')
|
||||||
|
)
|
||||||
|
op.create_table('process_schema',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('title', sa.String(length=100), nullable=False),
|
||||||
|
sa.Column('description', sa.Text(), nullable=False),
|
||||||
|
sa.Column('owner_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('creator_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('settings', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'STOPPING', 'STOPPED', 'DELETED', name='processstatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['account.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['owner_id'], ['account.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index('idx_owner_id', 'process_schema', ['owner_id'], unique=False)
|
||||||
|
op.create_table('process_version_archive',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('ps_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('version', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('snapshot', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('owner_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('is_last', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=True),
|
||||||
|
sa.ForeignKeyConstraint(['owner_id'], ['account.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['ps_id'], ['process_schema.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id', 'version')
|
||||||
|
)
|
||||||
|
op.create_table('ps_node',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('ps_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('node_type', sa.Enum('TYPE1', 'TYPE2', 'TYPE3', name='nodetype'), nullable=False),
|
||||||
|
sa.Column('settings', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('creator_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'DISABLED', 'DELETED', name='nodestatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['account.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['ps_id'], ['process_schema.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index('idx_ps_id', 'ps_node', ['ps_id'], unique=False)
|
||||||
|
op.create_table('node_link',
|
||||||
|
sa.Column('id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('link_name', sa.String(length=20), nullable=False),
|
||||||
|
sa.Column('node_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('next_node_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('settings', sa.JSON(), nullable=True),
|
||||||
|
sa.Column('creator_id', sa.Integer().with_variant(mysql.INTEGER(unsigned=True), 'mysql'), nullable=False),
|
||||||
|
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
|
||||||
|
sa.Column('status', sa.Enum('ACTIVE', 'STOPPING', 'STOPPED', 'DELETED', name='nodelinkstatus'), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['account.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['next_node_id'], ['ps_node.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['node_id'], ['ps_node.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_index('idx_next_node_id', 'node_link', ['next_node_id'], unique=False)
|
||||||
|
op.create_index('idx_node_id', 'node_link', ['node_id'], unique=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
"""Downgrade schema."""
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_index('idx_node_id', table_name='node_link')
|
||||||
|
op.drop_index('idx_next_node_id', table_name='node_link')
|
||||||
|
op.drop_table('node_link')
|
||||||
|
op.drop_index('idx_ps_id', table_name='ps_node')
|
||||||
|
op.drop_table('ps_node')
|
||||||
|
op.drop_table('process_version_archive')
|
||||||
|
op.drop_index('idx_owner_id', table_name='process_schema')
|
||||||
|
op.drop_table('process_schema')
|
||||||
|
op.drop_table('list_events')
|
||||||
|
op.drop_table('account_keyring')
|
||||||
|
op.drop_index('idx_name', table_name='account')
|
||||||
|
op.drop_index('idx_login', table_name='account')
|
||||||
|
op.drop_table('account')
|
||||||
|
# ### end Alembic commands ###
|
@@ -8,18 +8,16 @@ import asyncio
|
|||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine
|
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine, create_async_engine
|
||||||
from sqlalchemy import URL,create_engine, text
|
from sqlalchemy import URL, create_engine, text
|
||||||
|
|
||||||
|
|
||||||
from api.config import get_settings
|
from api.config import get_settings
|
||||||
from api.config.default import DbCredentialsSchema
|
from api.config.default import DbCredentialsSchema
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SessionManager:
|
class SessionManager:
|
||||||
engines: Any
|
engines: Any
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, database_uri=get_settings().database_uri) -> None:
|
def __init__(self, database_uri=get_settings().database_uri) -> None:
|
||||||
self.database_uri = database_uri
|
self.database_uri = database_uri
|
||||||
self.refresh(database_uri)
|
self.refresh(database_uri)
|
||||||
@@ -44,9 +42,11 @@ class SessionManager:
|
|||||||
pool_size=get_settings().CONNECTION_POOL_SIZE,
|
pool_size=get_settings().CONNECTION_POOL_SIZE,
|
||||||
max_overflow=get_settings().CONNECTION_OVERFLOW,
|
max_overflow=get_settings().CONNECTION_OVERFLOW,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_engine_by_db_uri(self, database_uri) -> AsyncEngine:
|
def get_engine_by_db_uri(self, database_uri) -> AsyncEngine:
|
||||||
return self.engines[database_uri]
|
return self.engines[database_uri]
|
||||||
|
|
||||||
|
|
||||||
@contextlib.asynccontextmanager
|
@contextlib.asynccontextmanager
|
||||||
async def get_connection(
|
async def get_connection(
|
||||||
database_uri=None,
|
database_uri=None,
|
||||||
@@ -58,6 +58,7 @@ async def get_connection(
|
|||||||
async with engine.connect() as conn:
|
async with engine.connect() as conn:
|
||||||
yield conn
|
yield conn
|
||||||
|
|
||||||
|
|
||||||
async def get_connection_dep() -> AsyncConnection:
|
async def get_connection_dep() -> AsyncConnection:
|
||||||
async with get_connection() as conn:
|
async with get_connection() as conn:
|
||||||
yield conn
|
yield conn
|
||||||
|
130
api/api/db/logic/account.py
Normal file
130
api/api/db/logic/account.py
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
from typing import Optional
|
||||||
|
import math
|
||||||
|
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
from sqlalchemy import insert, select, func
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.db.tables.account import account_table
|
||||||
|
|
||||||
|
from api.schemas.account.account import User
|
||||||
|
from api.schemas.endpoints.account import AllUserResponse, all_user_adapter
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_accaunt_page(connection: AsyncConnection, page, limit) -> Optional[User]:
|
||||||
|
"""
|
||||||
|
Получает список ползовелей заданных значениями page, limit.
|
||||||
|
"""
|
||||||
|
|
||||||
|
first_user = page * limit - (limit)
|
||||||
|
|
||||||
|
query = (
|
||||||
|
select(
|
||||||
|
account_table.c.id,
|
||||||
|
account_table.c.name,
|
||||||
|
account_table.c.login,
|
||||||
|
account_table.c.email,
|
||||||
|
account_table.c.bind_tenant_id,
|
||||||
|
account_table.c.role,
|
||||||
|
account_table.c.created_at,
|
||||||
|
account_table.c.status,
|
||||||
|
)
|
||||||
|
.order_by(account_table.c.id)
|
||||||
|
.offset(first_user)
|
||||||
|
.limit(limit)
|
||||||
|
)
|
||||||
|
|
||||||
|
count_query = select(func.count()).select_from(account_table)
|
||||||
|
|
||||||
|
result = await connection.execute(query)
|
||||||
|
count_result = await connection.execute(count_query)
|
||||||
|
|
||||||
|
users_data = result.mappings().all()
|
||||||
|
total_count = count_result.scalar()
|
||||||
|
total_pages = math.ceil(total_count / limit)
|
||||||
|
|
||||||
|
validated_users = all_user_adapter.validate_python(users_data)
|
||||||
|
|
||||||
|
return AllUserResponse(users=validated_users, amount_count=total_count, amount_pages=total_pages)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_by_id(connection: AsyncConnection, id: int) -> Optional[User]:
|
||||||
|
"""
|
||||||
|
Получает юзера по id.
|
||||||
|
"""
|
||||||
|
query = select(account_table).where(account_table.c.id == id)
|
||||||
|
|
||||||
|
user_db_cursor = await connection.execute(query)
|
||||||
|
user_db = user_db_cursor.one_or_none()
|
||||||
|
|
||||||
|
if not user_db:
|
||||||
|
return None
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
column.name: (
|
||||||
|
getattr(user_db, column.name).name
|
||||||
|
if isinstance(getattr(user_db, column.name), Enum)
|
||||||
|
else getattr(user_db, column.name)
|
||||||
|
)
|
||||||
|
for column in account_table.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
return User.model_validate(user_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user_by_login(connection: AsyncConnection, login: str) -> Optional[User]:
|
||||||
|
"""
|
||||||
|
Получает юзера по login.
|
||||||
|
"""
|
||||||
|
query = select(account_table).where(account_table.c.login == login)
|
||||||
|
|
||||||
|
user_db_cursor = await connection.execute(query)
|
||||||
|
user_db = user_db_cursor.one_or_none()
|
||||||
|
|
||||||
|
if not user_db:
|
||||||
|
return None
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
column.name: (
|
||||||
|
getattr(user_db, column.name).name
|
||||||
|
if isinstance(getattr(user_db, column.name), Enum)
|
||||||
|
else getattr(user_db, column.name)
|
||||||
|
)
|
||||||
|
for column in account_table.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
return User.model_validate(user_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_user_by_id(connection: AsyncConnection, update_values, user) -> Optional[User]:
|
||||||
|
"""
|
||||||
|
Вносит изменеия в нужное поле таблицы account_table.
|
||||||
|
"""
|
||||||
|
await connection.execute(account_table.update().where(account_table.c.id == user.id).values(**update_values))
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
async def create_user(connection: AsyncConnection, user: User, creator_id: int) -> Optional[User]:
|
||||||
|
"""
|
||||||
|
Создает нове поле в таблице account_table.
|
||||||
|
"""
|
||||||
|
query = insert(account_table).values(
|
||||||
|
name=user.name,
|
||||||
|
login=user.login,
|
||||||
|
email=user.email,
|
||||||
|
bind_tenant_id=user.bind_tenant_id,
|
||||||
|
role=user.role.value,
|
||||||
|
meta=user.meta,
|
||||||
|
creator_id=creator_id,
|
||||||
|
created_at=datetime.now(timezone.utc),
|
||||||
|
status=user.status.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.execute(query)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return user
|
86
api/api/db/logic/auth.py
Normal file
86
api/api/db/logic/auth.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from sqlalchemy import select, update
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.db.tables.account import account_table, account_keyring_table, KeyType, KeyStatus
|
||||||
|
|
||||||
|
from api.schemas.account.account import User
|
||||||
|
from api.schemas.account.account_keyring import AccountKeyring
|
||||||
|
|
||||||
|
from api.utils.key_id_gen import KeyIdGenerator
|
||||||
|
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
|
async def get_user(connection: AsyncConnection, login: str) -> Optional[User]:
|
||||||
|
query = (
|
||||||
|
select(account_table, account_keyring_table)
|
||||||
|
.join(account_keyring_table, account_table.c.id == account_keyring_table.c.owner_id)
|
||||||
|
.where(account_table.c.login == login, account_keyring_table.c.key_type == KeyType.PASSWORD)
|
||||||
|
)
|
||||||
|
|
||||||
|
user_db_cursor = await connection.execute(query)
|
||||||
|
user_db = user_db_cursor.one_or_none()
|
||||||
|
|
||||||
|
if not user_db:
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
column.name: (
|
||||||
|
getattr(user_db, column.name).name
|
||||||
|
if isinstance(getattr(user_db, column.name), Enum)
|
||||||
|
else getattr(user_db, column.name)
|
||||||
|
)
|
||||||
|
for column in account_table.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
password_data = {
|
||||||
|
column.name: (
|
||||||
|
getattr(user_db, column.name).name
|
||||||
|
if isinstance(getattr(user_db, column.name), Enum)
|
||||||
|
else getattr(user_db, column.name)
|
||||||
|
)
|
||||||
|
for column in account_keyring_table.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
user = User.model_validate(user_data)
|
||||||
|
password = AccountKeyring.model_validate(password_data)
|
||||||
|
return user, password
|
||||||
|
|
||||||
|
|
||||||
|
async def upgrade_old_refresh_token(connection: AsyncConnection, refresh_token) -> Optional[User]:
|
||||||
|
new_status = KeyStatus.EXPIRED
|
||||||
|
|
||||||
|
update_query = (
|
||||||
|
update(account_keyring_table)
|
||||||
|
.where(
|
||||||
|
account_keyring_table.c.status == KeyStatus.ACTIVE,
|
||||||
|
account_keyring_table.c.key_type == KeyType.REFRESH_TOKEN,
|
||||||
|
account_keyring_table.c.key_value == refresh_token,
|
||||||
|
)
|
||||||
|
.values(status=new_status)
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.execute(update_query)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
async def add_new_refresh_token(
|
||||||
|
connection: AsyncConnection, new_refresh_token, new_refresh_token_expires_time, user
|
||||||
|
) -> Optional[User]:
|
||||||
|
new_refresh_token = account_keyring_table.insert().values(
|
||||||
|
owner_id=user.id,
|
||||||
|
key_type=KeyType.REFRESH_TOKEN,
|
||||||
|
key_id=KeyIdGenerator(),
|
||||||
|
key_value=new_refresh_token,
|
||||||
|
created_at=datetime.now(timezone.utc),
|
||||||
|
expiry=new_refresh_token_expires_time,
|
||||||
|
status=KeyStatus.ACTIVE,
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.execute(new_refresh_token)
|
||||||
|
|
||||||
|
await connection.commit()
|
69
api/api/db/logic/keyring.py
Normal file
69
api/api/db/logic/keyring.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
from typing import Optional
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
from sqlalchemy import insert, select
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.tables.account import account_keyring_table
|
||||||
|
|
||||||
|
from api.schemas.account.account_keyring import AccountKeyring
|
||||||
|
|
||||||
|
|
||||||
|
async def get_key_by_id(connection: AsyncConnection, key_id: str) -> Optional[AccountKeyring]:
|
||||||
|
"""
|
||||||
|
Получает key по key_id.
|
||||||
|
"""
|
||||||
|
query = select(account_keyring_table).where(account_keyring_table.c.key_id == key_id)
|
||||||
|
|
||||||
|
user_db_cursor = await connection.execute(query)
|
||||||
|
user_db = user_db_cursor.one_or_none()
|
||||||
|
|
||||||
|
if not user_db:
|
||||||
|
return None
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
column.name: (
|
||||||
|
getattr(user_db, column.name).name
|
||||||
|
if isinstance(getattr(user_db, column.name), Enum)
|
||||||
|
else getattr(user_db, column.name)
|
||||||
|
)
|
||||||
|
for column in account_keyring_table.columns
|
||||||
|
}
|
||||||
|
|
||||||
|
return AccountKeyring.model_validate(user_data)
|
||||||
|
|
||||||
|
|
||||||
|
async def update_key_by_id(connection: AsyncConnection, update_values, key) -> Optional[AccountKeyring]:
|
||||||
|
"""
|
||||||
|
Вносит изменеия в нужное поле таблицы account_keyring_table.
|
||||||
|
"""
|
||||||
|
await connection.execute(
|
||||||
|
account_keyring_table.update().where(account_keyring_table.c.key_id == key.key_id).values(**update_values)
|
||||||
|
)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
async def create_key(connection: AsyncConnection, key: AccountKeyring, key_id: int) -> Optional[AccountKeyring]:
|
||||||
|
"""
|
||||||
|
Создает нове поле в таблице account_keyring_table).
|
||||||
|
"""
|
||||||
|
query = insert(account_keyring_table).values(
|
||||||
|
owner_id=key.owner_id,
|
||||||
|
key_type=key.key_type.value,
|
||||||
|
key_id=key_id,
|
||||||
|
key_value=key.key_value,
|
||||||
|
created_at=datetime.now(timezone.utc),
|
||||||
|
expiry=key.expiry,
|
||||||
|
status=key.status.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
key.created_at = datetime.now(timezone.utc)
|
||||||
|
key.key_id = key_id
|
||||||
|
|
||||||
|
await connection.execute(query)
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return key
|
@@ -1 +1 @@
|
|||||||
from . import account,events,process
|
from . import account, events, process
|
||||||
|
@@ -1,73 +1,67 @@
|
|||||||
from sqlalchemy import Table, Column, Integer, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
import enum
|
||||||
|
|
||||||
|
from sqlalchemy import Table, Column, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from enum import Enum
|
||||||
|
|
||||||
from enum import Enum, auto
|
|
||||||
|
|
||||||
from api.db.sql_types import UnsignedInt
|
from api.db.sql_types import UnsignedInt
|
||||||
|
|
||||||
from api.db import metadata
|
from api.db import metadata
|
||||||
|
|
||||||
|
|
||||||
class AccountRole(str,Enum):
|
class AccountRole(enum.StrEnum):
|
||||||
OWNER = auto()
|
OWNER = "OWNER"
|
||||||
ADMIN = auto()
|
ADMIN = "ADMIN"
|
||||||
EDITOR = auto()
|
EDITOR = "EDITOR"
|
||||||
VIEWER = auto()
|
VIEWER = "VIEWER"
|
||||||
|
|
||||||
class AccountStatus(str,Enum):
|
|
||||||
ACTIVE = auto()
|
|
||||||
DISABLED = auto()
|
|
||||||
BLOCKED = auto()
|
|
||||||
DELETED = auto()
|
|
||||||
|
|
||||||
|
class AccountStatus(enum.StrEnum):
|
||||||
|
ACTIVE = "ACTIVE"
|
||||||
|
DISABLED = "DISABLED"
|
||||||
|
BLOCKED = "BLOCKED"
|
||||||
|
DELETED = "DELETED"
|
||||||
|
|
||||||
|
|
||||||
account_table = Table(
|
account_table = Table(
|
||||||
'account', metadata,
|
"account",
|
||||||
Column('id', UnsignedInt, primary_key=True, autoincrement=True),
|
metadata,
|
||||||
Column('name', String(100), nullable=False),
|
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||||
Column('login', String(100), nullable=False),
|
Column("name", String(100), nullable=False),
|
||||||
Column('email', String(100), nullable=True),
|
Column("login", String(100), nullable=False),
|
||||||
Column('bind_tenant_id', String(40), nullable=True),
|
Column("email", String(100), nullable=True),
|
||||||
Column('role', SQLAEnum(AccountRole), nullable=False),
|
Column("bind_tenant_id", String(40), nullable=True),
|
||||||
Column('meta', JSON, default={}),
|
Column("role", SQLAEnum(AccountRole), nullable=False),
|
||||||
Column('creator_id', UnsignedInt, ForeignKey('account.id'), nullable=True),
|
Column("meta", JSON, default={}),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=True),
|
||||||
Column('status', SQLAEnum(AccountStatus), nullable=False),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
|
Column("status", SQLAEnum(AccountStatus), nullable=False),
|
||||||
Index('idx_login', 'login'),
|
Index("idx_login", "login"),
|
||||||
Index('idx_name', 'name'),
|
Index("idx_name", "name"),
|
||||||
)
|
)
|
||||||
|
|
||||||
class KeyType(str,Enum):
|
|
||||||
PASSWORD = auto()
|
|
||||||
ACCESS_TOKEN = auto()
|
|
||||||
REFRESH_TOKEN = auto()
|
|
||||||
API_KEY = auto()
|
|
||||||
|
|
||||||
class KeyStatus(str,Enum):
|
class KeyType(enum.StrEnum):
|
||||||
ACTIVE = auto()
|
PASSWORD = "PASSWORD"
|
||||||
EXPIRED = auto()
|
ACCESS_TOKEN = "ACCESS_TOKEN"
|
||||||
DELETED = auto()
|
REFRESH_TOKEN = "REFRESH_TOKEN"
|
||||||
|
API_KEY = "API_KEY"
|
||||||
|
|
||||||
|
|
||||||
|
class KeyStatus(enum.StrEnum):
|
||||||
|
ACTIVE = "ACTIVE"
|
||||||
|
EXPIRED = "EXPIRED"
|
||||||
|
DELETED = "DELETED"
|
||||||
|
|
||||||
|
|
||||||
account_keyring_table = Table(
|
account_keyring_table = Table(
|
||||||
'account_keyring', metadata,
|
"account_keyring",
|
||||||
Column('owner_id', UnsignedInt, ForeignKey('account.id'), primary_key=True, nullable=False),
|
metadata,
|
||||||
Column('key_type', SQLAEnum(KeyType), primary_key=True, nullable=False),
|
Column("owner_id", UnsignedInt, ForeignKey("account.id"), primary_key=True, nullable=False),
|
||||||
Column('key_id', String(40), default=None),
|
Column("key_type", SQLAEnum(KeyType), primary_key=True, nullable=False),
|
||||||
Column('key_value', String(64), nullable=False),
|
Column("key_id", String(40), primary_key=True, default=None),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("key_value", String(255), nullable=False),
|
||||||
Column('expiry', DateTime(timezone=True), nullable=True),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
Column('status', SQLAEnum(KeyStatus), nullable=False), )
|
Column("expiry", DateTime(timezone=True), nullable=True),
|
||||||
|
Column("status", SQLAEnum(KeyStatus), nullable=False),
|
||||||
|
)
|
||||||
def set_expiry_for_key_type(key_type: KeyType) -> datetime:
|
|
||||||
match key_type:
|
|
||||||
case KeyType.ACCESS_TOKEN:
|
|
||||||
return datetime.now() + timedelta(hours=1) # 1 hour
|
|
||||||
case KeyType.REFRESH_TOKEN:
|
|
||||||
return datetime.now() + timedelta(days=365) # 1 year
|
|
||||||
case KeyType.API_KEY:
|
|
||||||
return datetime.max # max datetime
|
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import enum
|
||||||
|
|
||||||
from sqlalchemy import Table, Column, Integer, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
from sqlalchemy import Table, Column, Integer, String, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
@@ -6,24 +8,27 @@ from api.db.sql_types import UnsignedInt
|
|||||||
|
|
||||||
from api.db import metadata
|
from api.db import metadata
|
||||||
|
|
||||||
class EventState(str, Enum):
|
|
||||||
AUTO = auto()
|
|
||||||
DESCRIPTED = auto()
|
|
||||||
|
|
||||||
class EventStatus(str, Enum):
|
class EventState(enum.StrEnum):
|
||||||
ACTIVE = auto()
|
AUTO = "AUTO"
|
||||||
DISABLED = auto()
|
DESCRIPTED = "DESCRIPTED"
|
||||||
DELETED = auto()
|
|
||||||
|
|
||||||
|
class EventStatus(enum.StrEnum):
|
||||||
|
ACTIVE = "ACTIVE"
|
||||||
|
DISABLED = "DISABLED"
|
||||||
|
DELETED = "DELETED"
|
||||||
|
|
||||||
|
|
||||||
list_events_table = Table(
|
list_events_table = Table(
|
||||||
'list_events', metadata,
|
"list_events",
|
||||||
Column('id', UnsignedInt, primary_key=True, autoincrement=True),
|
metadata,
|
||||||
Column('name', String(40, collation='latin1_bin'), nullable=False,unique=True),
|
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||||
Column('title', String(64), nullable=False),
|
Column("name", String(40, collation="latin1_bin"), nullable=False, unique=True),
|
||||||
Column('creator_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
Column("title", String(64), nullable=False),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
Column('schema', JSON, default={}),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
Column('state', SQLAEnum(EventState), nullable=False),
|
Column("schema", JSON, default={}),
|
||||||
Column('status', SQLAEnum(EventStatus), nullable=False),
|
Column("state", SQLAEnum(EventState), nullable=False),
|
||||||
|
Column("status", SQLAEnum(EventStatus), nullable=False),
|
||||||
)
|
)
|
||||||
|
@@ -1,4 +1,18 @@
|
|||||||
from sqlalchemy import Table, Column, Integer, String, Text, Enum as SQLAEnum, JSON, ForeignKey, DateTime, Index, PrimaryKeyConstraint
|
import enum
|
||||||
|
|
||||||
|
from sqlalchemy import (
|
||||||
|
Table,
|
||||||
|
Column,
|
||||||
|
Integer,
|
||||||
|
String,
|
||||||
|
Text,
|
||||||
|
Enum as SQLAEnum,
|
||||||
|
JSON,
|
||||||
|
ForeignKey,
|
||||||
|
DateTime,
|
||||||
|
Index,
|
||||||
|
PrimaryKeyConstraint,
|
||||||
|
)
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
|
|
||||||
@@ -7,78 +21,88 @@ from api.db.sql_types import UnsignedInt
|
|||||||
from api.db import metadata
|
from api.db import metadata
|
||||||
|
|
||||||
|
|
||||||
# Определение перечислений для статуса процесса
|
class ProcessStatus(enum.StrEnum):
|
||||||
class ProcessStatus(str, Enum):
|
ACTIVE = "ACTIVE"
|
||||||
ACTIVE = auto()
|
STOPPING = "STOPPING"
|
||||||
STOPPING = auto()
|
STOPPED = "STOPPED"
|
||||||
STOPPED = auto()
|
DELETED = "DELETED"
|
||||||
DELETED = auto()
|
|
||||||
|
|
||||||
# Определение таблицы process_schema
|
|
||||||
process_schema_table = Table(
|
process_schema_table = Table(
|
||||||
'process_schema', metadata,
|
"process_schema",
|
||||||
Column('id', UnsignedInt, primary_key=True, autoincrement=True),
|
metadata,
|
||||||
Column('title', String(100), nullable=False),
|
Column("id", UnsignedInt, primary_key=True, autoincrement=True),
|
||||||
Column('description', Text, nullable=False),
|
Column("title", String(100), nullable=False),
|
||||||
Column('owner_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
Column("description", Text, nullable=False),
|
||||||
Column('creator_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
Column('settings', JSON, default={}),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
Column('status', SQLAEnum(ProcessStatus), nullable=False),
|
Column("settings", JSON, default={}),
|
||||||
|
Column("status", SQLAEnum(ProcessStatus), nullable=False),
|
||||||
Index('idx_owner_id', 'owner_id',)
|
Index(
|
||||||
|
"idx_owner_id",
|
||||||
|
"owner_id",
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
process_version_archive_table = Table(
|
process_version_archive_table = Table(
|
||||||
'process_version_archive', metadata,
|
"process_version_archive",
|
||||||
Column('id', UnsignedInt, autoincrement=True, nullable=False),
|
metadata,
|
||||||
Column('ps_id', UnsignedInt, ForeignKey('process_schema.id'), nullable=False),
|
Column("id", UnsignedInt, autoincrement=True, nullable=False),
|
||||||
Column('version', UnsignedInt, default=1, nullable=False),
|
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
|
||||||
Column('snapshot', JSON, default={}),
|
Column("version", UnsignedInt, default=1, nullable=False),
|
||||||
Column('owner_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
Column("snapshot", JSON, default={}),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("owner_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
Column('is_last', UnsignedInt, default=0),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
PrimaryKeyConstraint('id', 'version') )
|
Column("is_last", UnsignedInt, default=0),
|
||||||
|
PrimaryKeyConstraint("id", "version"),
|
||||||
class NodeStatus(str, Enum):
|
|
||||||
ACTIVE = auto()
|
|
||||||
DISABLED = auto()
|
|
||||||
DELETED = auto()
|
|
||||||
|
|
||||||
class NodeType(Enum):
|
|
||||||
TYPE1 = 'Type1'
|
|
||||||
TYPE2 = 'Type2'
|
|
||||||
TYPE3 = 'Type3'
|
|
||||||
|
|
||||||
ps_node_table = Table(
|
|
||||||
'ps_node', metadata,
|
|
||||||
Column('id', UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
|
||||||
Column('ps_id', UnsignedInt, ForeignKey('process_schema.id'), nullable=False),
|
|
||||||
Column('node_type', SQLAEnum(NodeType), nullable=False),
|
|
||||||
Column('settings', JSON, default={}),
|
|
||||||
Column('creator_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
|
||||||
Column('status', SQLAEnum(NodeStatus), nullable=False),
|
|
||||||
|
|
||||||
Index('idx_ps_id', 'ps_id')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class NodeLinkStatus(str, Enum):
|
|
||||||
ACTIVE = auto()
|
class NodeStatus(enum.StrEnum):
|
||||||
STOPPING = auto()
|
ACTIVE = "ACTIVE"
|
||||||
STOPPED = auto()
|
DISABLED = "DISABLED"
|
||||||
DELETED = auto()
|
DELETED = "DELETED"
|
||||||
|
|
||||||
|
|
||||||
|
class NodeType(Enum):
|
||||||
|
TYPE1 = "Type1"
|
||||||
|
TYPE2 = "Type2"
|
||||||
|
TYPE3 = "Type3"
|
||||||
|
|
||||||
|
|
||||||
|
ps_node_table = Table(
|
||||||
|
"ps_node",
|
||||||
|
metadata,
|
||||||
|
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
||||||
|
Column("ps_id", UnsignedInt, ForeignKey("process_schema.id"), nullable=False),
|
||||||
|
Column("node_type", SQLAEnum(NodeType), nullable=False),
|
||||||
|
Column("settings", JSON, default={}),
|
||||||
|
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
|
Column("status", SQLAEnum(NodeStatus), nullable=False),
|
||||||
|
Index("idx_ps_id", "ps_id"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NodeLinkStatus(enum.StrEnum):
|
||||||
|
ACTIVE = "ACTIVE"
|
||||||
|
STOPPING = "STOPPING"
|
||||||
|
STOPPED = "STOPPED"
|
||||||
|
DELETED = "DELETED"
|
||||||
|
|
||||||
|
|
||||||
node_link_table = Table(
|
node_link_table = Table(
|
||||||
'node_link', metadata,
|
"node_link",
|
||||||
Column('id', UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
metadata,
|
||||||
Column('link_name', String(20), nullable=False),
|
Column("id", UnsignedInt, autoincrement=True, primary_key=True, nullable=False),
|
||||||
Column('node_id', UnsignedInt, ForeignKey('ps_node.id'), nullable=False),
|
Column("link_name", String(20), nullable=False),
|
||||||
Column('next_node_id', UnsignedInt, ForeignKey('ps_node.id'), nullable=False),
|
Column("node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
|
||||||
Column('settings', JSON, default={}),
|
Column("next_node_id", UnsignedInt, ForeignKey("ps_node.id"), nullable=False),
|
||||||
Column('creator_id', UnsignedInt, ForeignKey('account.id'), nullable=False),
|
Column("settings", JSON, default={}),
|
||||||
Column('created_at', DateTime(timezone=True), server_default=func.now()),
|
Column("creator_id", UnsignedInt, ForeignKey("account.id"), nullable=False),
|
||||||
Column('status', SQLAEnum(NodeLinkStatus),nullable=False),
|
Column("created_at", DateTime(timezone=True), server_default=func.now()),
|
||||||
|
Column("status", SQLAEnum(NodeLinkStatus), nullable=False),
|
||||||
Index('idx_node_id', 'node_id'),
|
Index("idx_node_id", "node_id"),
|
||||||
Index('idx_next_node_id', 'next_node_id'))
|
Index("idx_next_node_id", "next_node_id"),
|
||||||
|
)
|
||||||
|
@@ -1,4 +1,9 @@
|
|||||||
list_of_routes = []
|
from api.endpoints.auth import api_router as auth_router
|
||||||
|
from api.endpoints.profile import api_router as profile_router
|
||||||
|
from api.endpoints.account import api_router as account_router
|
||||||
|
from api.endpoints.keyring import api_router as keyring_router
|
||||||
|
|
||||||
|
list_of_routes = [auth_router, profile_router, account_router, keyring_router]
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"list_of_routes",
|
"list_of_routes",
|
||||||
|
135
api/api/endpoints/account.py
Normal file
135
api/api/endpoints/account.py
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
from fastapi import (
|
||||||
|
APIRouter,
|
||||||
|
Depends,
|
||||||
|
HTTPException,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
|
||||||
|
from api.db.logic.account import (
|
||||||
|
get_user_by_id,
|
||||||
|
update_user_by_id,
|
||||||
|
create_user,
|
||||||
|
get_user_by_login,
|
||||||
|
get_user_accaunt_page,
|
||||||
|
)
|
||||||
|
|
||||||
|
from api.schemas.account.account import User
|
||||||
|
from api.db.tables.account import AccountStatus
|
||||||
|
from api.schemas.base import bearer_schema
|
||||||
|
from api.schemas.endpoints.account import UserUpdate, AllUserResponse
|
||||||
|
from api.services.auth import get_current_user
|
||||||
|
|
||||||
|
from api.services.user_role_validation import db_user_role_validation
|
||||||
|
from api.services.update_data_validation import update_user_data_changes
|
||||||
|
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/account",
|
||||||
|
tags=["User accountModel"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=AllUserResponse)
|
||||||
|
async def get_all_account(
|
||||||
|
page: int = 1,
|
||||||
|
limit: int = 10,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
user_list = await get_user_accaunt_page(connection, page, limit)
|
||||||
|
|
||||||
|
if user_list is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Accounts not found")
|
||||||
|
|
||||||
|
return user_list
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def get_account(
|
||||||
|
user_id: int, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def create_account(
|
||||||
|
user: UserUpdate, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
user_validation = await get_user_by_login(connection, user.login)
|
||||||
|
|
||||||
|
if user_validation is None:
|
||||||
|
await create_user(connection, user, authorize_user.id)
|
||||||
|
user_new = await get_user_by_login(connection, user.login)
|
||||||
|
return user_new
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST, detail="An account with this information already exists."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.put("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def update_account(
|
||||||
|
user_id: int,
|
||||||
|
user_update: UserUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
|
update_values = update_user_data_changes(user_update, user)
|
||||||
|
|
||||||
|
if update_values is None:
|
||||||
|
return user
|
||||||
|
|
||||||
|
user_update_data = User.model_validate({**user.model_dump(), **update_values})
|
||||||
|
|
||||||
|
await update_user_by_id(connection, update_values, user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.delete("/{user_id}", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def delete_account(
|
||||||
|
user_id: int, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
|
user_update = UserUpdate(status=AccountStatus.DELETED.value)
|
||||||
|
|
||||||
|
update_values = update_user_data_changes(user_update, user)
|
||||||
|
|
||||||
|
if update_values is None:
|
||||||
|
return user
|
||||||
|
|
||||||
|
await update_user_by_id(connection, update_values, user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user_id)
|
||||||
|
|
||||||
|
return user
|
117
api/api/endpoints/auth.py
Normal file
117
api/api/endpoints/auth.py
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
|
import jwt
|
||||||
|
from fastapi import (
|
||||||
|
APIRouter,
|
||||||
|
Depends,
|
||||||
|
HTTPException,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
from loguru import logger
|
||||||
|
from fastapi_jwt_auth import AuthJWT
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.config import get_settings
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
from api.services.auth import authenticate_user
|
||||||
|
|
||||||
|
from api.db.logic.auth import add_new_refresh_token, upgrade_old_refresh_token
|
||||||
|
|
||||||
|
from api.schemas.endpoints.auth import Auth, Access
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/auth",
|
||||||
|
tags=["User auth"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_login_from_jwt(token: str):
|
||||||
|
payload = jwt.decode(
|
||||||
|
token,
|
||||||
|
get_settings().SECRET_KEY,
|
||||||
|
algorithms=[get_settings().ALGORITHM],
|
||||||
|
)
|
||||||
|
return payload.get("sub")
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(BaseModel):
|
||||||
|
authjwt_secret_key: str = get_settings().SECRET_KEY
|
||||||
|
# Configure application to store and get JWT from cookies
|
||||||
|
authjwt_token_location: set = {"headers", "cookies"}
|
||||||
|
authjwt_cookie_domain: str = get_settings().DOMAIN
|
||||||
|
authjwt_refresh_cookie_name: str = "refresh_token_cookie"
|
||||||
|
|
||||||
|
# Only allow JWT cookies to be sent over https
|
||||||
|
authjwt_cookie_secure: bool = get_settings().ENV == "prod"
|
||||||
|
# Enable csrf double submit protection. default is True
|
||||||
|
authjwt_cookie_csrf_protect: bool = False
|
||||||
|
authjwt_cookie_samesite: str = "lax"
|
||||||
|
|
||||||
|
|
||||||
|
@AuthJWT.load_config
|
||||||
|
def get_config():
|
||||||
|
return Settings()
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("", response_model=Access)
|
||||||
|
async def login_for_access_token(
|
||||||
|
user: Auth,
|
||||||
|
response: Response,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
Authorize: AuthJWT = Depends(),
|
||||||
|
):
|
||||||
|
"""Авторизирует, выставляет токены в куки."""
|
||||||
|
|
||||||
|
user = await authenticate_user(connection, user.login, user.password)
|
||||||
|
|
||||||
|
# print("login_for_access_token", user)
|
||||||
|
|
||||||
|
if not user:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="Incorrect username or password",
|
||||||
|
# headers={"WWW-Authenticate": "Bearer"},
|
||||||
|
)
|
||||||
|
|
||||||
|
# access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||||
|
access_token_expires = timedelta(seconds=5)
|
||||||
|
|
||||||
|
refresh_token_expires = timedelta(days=get_settings().REFRESH_TOKEN_EXPIRE_DAYS)
|
||||||
|
|
||||||
|
logger.debug(f"refresh_token_expires {refresh_token_expires}")
|
||||||
|
|
||||||
|
access_token = Authorize.create_access_token(subject=user.login, expires_time=access_token_expires)
|
||||||
|
refresh_token = Authorize.create_refresh_token(subject=user.login, expires_time=refresh_token_expires)
|
||||||
|
|
||||||
|
refresh_token_expires_time = datetime.now(timezone.utc) + refresh_token_expires
|
||||||
|
|
||||||
|
await add_new_refresh_token(connection, refresh_token, refresh_token_expires_time, user)
|
||||||
|
|
||||||
|
Authorize.set_refresh_cookies(refresh_token)
|
||||||
|
|
||||||
|
return Access(access_token=access_token)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("/refresh", response_model=Access)
|
||||||
|
async def refresh(
|
||||||
|
request: Request,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
Authorize: AuthJWT = Depends(),
|
||||||
|
):
|
||||||
|
refresh_token = request.cookies.get("refresh_token_cookie")
|
||||||
|
|
||||||
|
if not refresh_token:
|
||||||
|
raise HTTPException(status_code=401, detail="Refresh token is missing")
|
||||||
|
Authorize.jwt_refresh_token_required(refresh_token)
|
||||||
|
current_user = Authorize.get_jwt_subject()
|
||||||
|
# try:
|
||||||
|
# access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||||
|
access_token_expires = timedelta(seconds=5)
|
||||||
|
new_access_token = Authorize.create_access_token(subject=current_user, expires_time=access_token_expires)
|
||||||
|
|
||||||
|
return Access(access_token=new_access_token)
|
128
api/api/endpoints/keyring.py
Normal file
128
api/api/endpoints/keyring.py
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
from fastapi import (
|
||||||
|
APIRouter,
|
||||||
|
Body,
|
||||||
|
Depends,
|
||||||
|
Form,
|
||||||
|
HTTPException,
|
||||||
|
Response,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
|
||||||
|
from api.db.logic.keyring import get_key_by_id, create_key, update_key_by_id
|
||||||
|
|
||||||
|
|
||||||
|
from api.db.tables.account import KeyStatus
|
||||||
|
from api.schemas.base import bearer_schema
|
||||||
|
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
|
||||||
|
|
||||||
|
from api.schemas.account.account_keyring import AccountKeyring
|
||||||
|
from api.services.auth import get_current_user
|
||||||
|
|
||||||
|
from api.services.user_role_validation import db_user_role_validation
|
||||||
|
from api.services.update_data_validation import update_key_data_changes
|
||||||
|
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/keyring",
|
||||||
|
tags=["User KeyringModel"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||||
|
async def get_keyring(
|
||||||
|
key_id: str, connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
|
if keyring is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Key not found")
|
||||||
|
|
||||||
|
return keyring
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.post("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||||
|
async def create_keyring(
|
||||||
|
user_id: int,
|
||||||
|
key_id: str,
|
||||||
|
key: AccountKeyringUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
|
if keyring is None:
|
||||||
|
keyring_new = await create_key(
|
||||||
|
connection,
|
||||||
|
key,
|
||||||
|
key_id,
|
||||||
|
)
|
||||||
|
return keyring_new
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_400_BAD_REQUEST, detail="An keyring with this information already exists."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.put("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||||
|
async def update_keyring(
|
||||||
|
user_id: int,
|
||||||
|
key_id: str,
|
||||||
|
keyring_update: AccountKeyringUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
if keyring is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found")
|
||||||
|
|
||||||
|
update_values = update_key_data_changes(keyring_update, keyring)
|
||||||
|
|
||||||
|
if update_values is None:
|
||||||
|
return keyring
|
||||||
|
|
||||||
|
keyring_update_data = AccountKeyring.model_validate({**keyring.model_dump(), **update_values})
|
||||||
|
|
||||||
|
await update_key_by_id(connection, update_values, keyring)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
|
return keyring
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.delete("/{user_id}/{key_id}", dependencies=[Depends(bearer_schema)], response_model=AccountKeyring)
|
||||||
|
async def delete_keyring(
|
||||||
|
user_id: int,
|
||||||
|
key_id: str,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
authorize_user = await db_user_role_validation(connection, current_user)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
if keyring is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="keyring not found")
|
||||||
|
|
||||||
|
keyring_update = AccountKeyringUpdate(status=KeyStatus.DELETED.value)
|
||||||
|
|
||||||
|
update_values = update_key_data_changes(keyring_update, keyring)
|
||||||
|
|
||||||
|
if update_values is None:
|
||||||
|
return keyring
|
||||||
|
|
||||||
|
await update_key_by_id(connection, update_values, keyring)
|
||||||
|
|
||||||
|
keyring = await get_key_by_id(connection, key_id)
|
||||||
|
|
||||||
|
return keyring
|
65
api/api/endpoints/profile.py
Normal file
65
api/api/endpoints/profile.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
from fastapi import (
|
||||||
|
APIRouter,
|
||||||
|
Body,
|
||||||
|
Depends,
|
||||||
|
Form,
|
||||||
|
HTTPException,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
|
||||||
|
from api.db.connection.session import get_connection_dep
|
||||||
|
from api.db.logic.account import get_user_by_id, update_user_by_id, get_user_by_login
|
||||||
|
from api.schemas.base import bearer_schema
|
||||||
|
from api.services.auth import get_current_user
|
||||||
|
from api.services.update_data_validation import update_user_data_changes
|
||||||
|
|
||||||
|
from api.schemas.endpoints.account import UserUpdate
|
||||||
|
from api.schemas.account.account import User
|
||||||
|
|
||||||
|
|
||||||
|
api_router = APIRouter(
|
||||||
|
prefix="/profile",
|
||||||
|
tags=["User accountModel"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.get("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def get_profile(
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep), current_user=Depends(get_current_user)
|
||||||
|
):
|
||||||
|
user = await get_user_by_login(connection, current_user)
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
@api_router.put("", dependencies=[Depends(bearer_schema)], response_model=User)
|
||||||
|
async def update_profile(
|
||||||
|
user_updata: UserUpdate,
|
||||||
|
connection: AsyncConnection = Depends(get_connection_dep),
|
||||||
|
current_user=Depends(get_current_user),
|
||||||
|
):
|
||||||
|
user = await get_user_by_login(connection, current_user)
|
||||||
|
if user is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Account not found")
|
||||||
|
|
||||||
|
if user_updata.role == None and user_updata.login == None:
|
||||||
|
update_values = update_user_data_changes(user_updata, user)
|
||||||
|
|
||||||
|
if update_values is None:
|
||||||
|
return user
|
||||||
|
|
||||||
|
await update_user_by_id(connection, update_values, user)
|
||||||
|
|
||||||
|
user = await get_user_by_id(connection, user.id)
|
||||||
|
|
||||||
|
return user
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Bad body")
|
@@ -1,30 +1,20 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from enum import Enum
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import EmailStr, Field
|
||||||
|
from api.db.tables.account import AccountRole, AccountStatus
|
||||||
|
|
||||||
from pydantic import BaseModel, EmailStr, Field
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class Role(Enum):
|
class User(Base):
|
||||||
OWNER = "Owner"
|
id: Optional[int] = None
|
||||||
ADMIN = "Admin"
|
|
||||||
EDITOR = "Editor"
|
|
||||||
VIEWER = "Viewer"
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
DISABLED = "Disabled"
|
|
||||||
BLOCKED = "Blocked"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
class User(BaseModel):
|
|
||||||
id: int
|
|
||||||
name: str = Field(..., max_length=100)
|
name: str = Field(..., max_length=100)
|
||||||
login: str = Field(..., max_length=100)
|
login: str = Field(..., max_length=100)
|
||||||
email: EmailStr = Field(..., max_length=100)
|
email: Optional[EmailStr] = Field(None, max_length=100) # Электронная почта (может быть None)
|
||||||
bind_tenant_id: str = Field(..., max_length=40)
|
bind_tenant_id: Optional[str] = Field(None, max_length=40)
|
||||||
role: Role
|
role: AccountRole
|
||||||
meta: dict
|
meta: dict
|
||||||
creator_id: int
|
creator_id: Optional[int] = None
|
||||||
is_active: bool
|
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
status: Status
|
status: AccountStatus
|
||||||
|
@@ -1,27 +1,17 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
from typing import Optional
|
||||||
from enum import Enum
|
from pydantic import Field
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from api.db.tables.account import KeyType, KeyStatus
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class Type(Enum):
|
class AccountKeyring(Base):
|
||||||
PASSWORD = "password"
|
|
||||||
ACCESS_TOKEN = "access_token"
|
|
||||||
REFRESH_TOKEN = "refresh_token"
|
|
||||||
API_KEY = "api_key"
|
|
||||||
|
|
||||||
class Status(Enum):
|
|
||||||
ACTIVE = "Active"
|
|
||||||
EXPIRED = "Expired"
|
|
||||||
DELETED = "Deleted"
|
|
||||||
|
|
||||||
class AccountKeyring(BaseModel):
|
|
||||||
owner_id: int
|
owner_id: int
|
||||||
key_type: Type
|
key_type: KeyType
|
||||||
key_id: str = Field(..., max_length=40)
|
key_id: Optional[str] = Field(None, max_length=40)
|
||||||
key_value: str = Field(..., max_length=64)
|
key_value: str = Field(..., max_length=255)
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
expiry: datetime
|
expiry: Optional[datetime] = None
|
||||||
status: Status
|
status: KeyStatus
|
||||||
|
14
api/api/schemas/base.py
Normal file
14
api/api/schemas/base.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
from fastapi.security import HTTPBearer
|
||||||
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
from pydantic.alias_generators import to_camel
|
||||||
|
|
||||||
|
|
||||||
|
bearer_schema = HTTPBearer() # схема для авторизации в swagger
|
||||||
|
|
||||||
|
|
||||||
|
class Base(BaseModel):
|
||||||
|
model_config = ConfigDict(
|
||||||
|
from_attributes=True,
|
||||||
|
alias_generator=to_camel,
|
||||||
|
populate_by_name=True,
|
||||||
|
)
|
0
api/api/schemas/endpoints/__init__.py
Normal file
0
api/api/schemas/endpoints/__init__.py
Normal file
40
api/api/schemas/endpoints/account.py
Normal file
40
api/api/schemas/endpoints/account.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
from typing import Optional, List
|
||||||
|
from datetime import datetime
|
||||||
|
from pydantic import EmailStr, Field, TypeAdapter
|
||||||
|
|
||||||
|
from api.db.tables.account import AccountRole, AccountStatus
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class UserUpdate(Base):
|
||||||
|
id: Optional[int] = None
|
||||||
|
name: Optional[str] = Field(None, max_length=100)
|
||||||
|
login: Optional[str] = Field(None, max_length=100)
|
||||||
|
email: Optional[EmailStr] = None
|
||||||
|
bind_tenant_id: Optional[str] = Field(None, max_length=40)
|
||||||
|
role: Optional[AccountRole] = None
|
||||||
|
meta: Optional[dict] = None
|
||||||
|
creator_id: Optional[int] = None
|
||||||
|
created_at: Optional[datetime] = None
|
||||||
|
status: Optional[AccountStatus] = None
|
||||||
|
|
||||||
|
|
||||||
|
class AllUser(Base):
|
||||||
|
id: int
|
||||||
|
name: str
|
||||||
|
login: str
|
||||||
|
email: Optional[EmailStr] = None
|
||||||
|
bind_tenant_id: Optional[str] = None
|
||||||
|
role: AccountRole
|
||||||
|
created_at: datetime
|
||||||
|
status: AccountStatus
|
||||||
|
|
||||||
|
|
||||||
|
class AllUserResponse(Base):
|
||||||
|
users: List[AllUser]
|
||||||
|
amount_count: int
|
||||||
|
amount_pages: int
|
||||||
|
|
||||||
|
|
||||||
|
all_user_adapter = TypeAdapter(List[AllUser])
|
17
api/api/schemas/endpoints/account_keyring.py
Normal file
17
api/api/schemas/endpoints/account_keyring.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import datetime
|
||||||
|
from typing import Optional
|
||||||
|
from pydantic import Field
|
||||||
|
from datetime import datetime
|
||||||
|
from api.db.tables.account import KeyType, KeyStatus
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AccountKeyringUpdate(Base):
|
||||||
|
owner_id: Optional[int] = None
|
||||||
|
key_type: Optional[KeyType] = None
|
||||||
|
key_id: Optional[str] = Field(None, max_length=40)
|
||||||
|
key_value: Optional[str] = Field(None, max_length=255)
|
||||||
|
created_at: Optional[datetime] = None
|
||||||
|
expiry: Optional[datetime] = None
|
||||||
|
status: Optional[KeyStatus] = None
|
16
api/api/schemas/endpoints/auth.py
Normal file
16
api/api/schemas/endpoints/auth.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
# Таблица для получения информации из запроса
|
||||||
|
|
||||||
|
|
||||||
|
class Auth(Base):
|
||||||
|
login: str
|
||||||
|
password: str
|
||||||
|
|
||||||
|
|
||||||
|
class Refresh(Base):
|
||||||
|
refresh_token: str
|
||||||
|
|
||||||
|
|
||||||
|
class Access(Base):
|
||||||
|
access_token: str
|
@@ -1,8 +1,10 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
AUTO = "Auto"
|
AUTO = "Auto"
|
||||||
@@ -14,7 +16,8 @@ class Status(Enum):
|
|||||||
DISABLED = "Disabled"
|
DISABLED = "Disabled"
|
||||||
DELETED = "Deleted"
|
DELETED = "Deleted"
|
||||||
|
|
||||||
class ListEvent(BaseModel):
|
|
||||||
|
class ListEvent(Base):
|
||||||
id: int
|
id: int
|
||||||
name: str = Field(..., max_length=40)
|
name: str = Field(..., max_length=40)
|
||||||
title: str = Field(..., max_length=64)
|
title: str = Field(..., max_length=64)
|
||||||
|
@@ -1,15 +1,19 @@
|
|||||||
from pydantic import BaseModel, Field, conint
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
ACTIVE = "Active"
|
ACTIVE = "Active"
|
||||||
STOPPING = "Stopping"
|
STOPPING = "Stopping"
|
||||||
STOPPED = "Stopped"
|
STOPPED = "Stopped"
|
||||||
DELETED = "Deleted"
|
DELETED = "Deleted"
|
||||||
|
|
||||||
class MyModel(BaseModel):
|
|
||||||
|
class MyModel(Base):
|
||||||
id: int
|
id: int
|
||||||
link_name: str = Field(..., max_length=20)
|
link_name: str = Field(..., max_length=20)
|
||||||
node_id: int
|
node_id: int
|
||||||
|
@@ -1,15 +1,19 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import Field
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
ACTIVE = "Active"
|
ACTIVE = "Active"
|
||||||
STOPPING = "Stopping"
|
STOPPING = "Stopping"
|
||||||
STOPPED = "Stopped"
|
STOPPED = "Stopped"
|
||||||
DELETED = "Deleted"
|
DELETED = "Deleted"
|
||||||
|
|
||||||
class ProcessSchema(BaseModel):
|
|
||||||
|
class ProcessSchema(Base):
|
||||||
id: int
|
id: int
|
||||||
title: str = Field(..., max_length=100)
|
title: str = Field(..., max_length=100)
|
||||||
description: str
|
description: str
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
from pydantic import BaseModel, Field
|
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class ProcessStatusSchema(BaseModel):
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessStatusSchema(Base):
|
||||||
id: int
|
id: int
|
||||||
version: int
|
version: int
|
||||||
snapshot: Dict[str, Any]
|
snapshot: Dict[str, Any]
|
||||||
|
@@ -1,19 +1,21 @@
|
|||||||
from pydantic import BaseModel
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from api.schemas.base import Base
|
||||||
|
|
||||||
|
|
||||||
class NodeType(Enum):
|
class NodeType(Enum):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Status(Enum):
|
class Status(Enum):
|
||||||
ACTIVE = "Active"
|
ACTIVE = "Active"
|
||||||
DISABLED = "Disabled"
|
DISABLED = "Disabled"
|
||||||
DELETED = "Deleted"
|
DELETED = "Deleted"
|
||||||
|
|
||||||
class Ps_Node(BaseModel):
|
|
||||||
|
class Ps_Node(Base):
|
||||||
id: int
|
id: int
|
||||||
ps_id: int
|
ps_id: int
|
||||||
node_type: NodeType
|
node_type: NodeType
|
||||||
|
27
api/api/services/auth.py
Normal file
27
api/api/services/auth.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from fastapi import Request, HTTPException
|
||||||
|
from typing import Optional
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||||
|
from api.db.logic.auth import get_user
|
||||||
|
|
||||||
|
# # from backend.schemas.users.token import TokenData
|
||||||
|
from api.schemas.account.account import User
|
||||||
|
from api.db.tables.account import AccountStatus
|
||||||
|
|
||||||
|
from api.utils.hasher import Hasher
|
||||||
|
|
||||||
|
|
||||||
|
async def get_current_user(request: Request) -> Optional[User]:
|
||||||
|
if not hasattr(request.state, "current_user"):
|
||||||
|
return HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
return request.state.current_user
|
||||||
|
|
||||||
|
|
||||||
|
async def authenticate_user(connection: AsyncConnection, username: str, password: str) -> Optional[User]:
|
||||||
|
sql_user, sql_password = await get_user(connection, username)
|
||||||
|
|
||||||
|
if not sql_user or sql_user.status != AccountStatus.ACTIVE:
|
||||||
|
return None
|
||||||
|
hasher = Hasher()
|
||||||
|
if not hasher.verify_data(password, sql_password.key_value):
|
||||||
|
return None
|
||||||
|
return sql_user
|
59
api/api/services/middleware.py
Normal file
59
api/api/services/middleware.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
|
from fastapi import (
|
||||||
|
Request,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from api.config import get_settings
|
||||||
|
|
||||||
|
import re
|
||||||
|
from re import escape
|
||||||
|
|
||||||
|
|
||||||
|
from fastapi_jwt_auth import AuthJWT
|
||||||
|
|
||||||
|
|
||||||
|
class MiddlewareAccessTokenValidadtion(BaseHTTPMiddleware):
|
||||||
|
def __init__(self, app):
|
||||||
|
super().__init__(app)
|
||||||
|
|
||||||
|
self.prefix = escape(get_settings().PATH_PREFIX)
|
||||||
|
self.excluded_routes = [
|
||||||
|
re.compile(r"^" + re.escape(self.prefix) + r"/auth/refresh/?$"),
|
||||||
|
re.compile(r"^" + re.escape(self.prefix) + r"/auth/?$"),
|
||||||
|
re.compile(r"^" + r"/swagger"),
|
||||||
|
re.compile(r"^" + r"/openapi"),
|
||||||
|
]
|
||||||
|
|
||||||
|
async def dispatch(self, request: Request, call_next):
|
||||||
|
if request.method not in ["GET", "POST", "PUT", "DELETE"]:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_405_METHOD_NOT_ALLOWED,
|
||||||
|
content={"detail": "Method not allowed"},
|
||||||
|
)
|
||||||
|
|
||||||
|
if any(pattern.match(request.url.path) for pattern in self.excluded_routes):
|
||||||
|
return await call_next(request)
|
||||||
|
|
||||||
|
auth_header = request.headers.get("Authorization")
|
||||||
|
if not auth_header:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
content={"detail": "Missing authorization header."},
|
||||||
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
token = auth_header.split(" ")[1]
|
||||||
|
Authorize = AuthJWT(request)
|
||||||
|
current_user = Authorize.get_jwt_subject()
|
||||||
|
request.state.current_user = current_user
|
||||||
|
except Exception:
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
content={"detail": "The access token is invalid or expired."},
|
||||||
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
|
)
|
||||||
|
|
||||||
|
return await call_next(request)
|
74
api/api/services/update_data_validation.py
Normal file
74
api/api/services/update_data_validation.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Optional
|
||||||
|
from api.schemas.endpoints.account import UserUpdate
|
||||||
|
from api.db.tables.account import KeyType, KeyStatus
|
||||||
|
from api.schemas.endpoints.account_keyring import AccountKeyringUpdate
|
||||||
|
from api.db.tables.account import AccountRole, AccountStatus
|
||||||
|
|
||||||
|
|
||||||
|
def update_user_data_changes(update_data: UserUpdate, user) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
Сравнивает данные для обновления с текущими значениями пользователя.
|
||||||
|
Возвращает:
|
||||||
|
- None, если нет изменений
|
||||||
|
- Словарь {поле: новое_значение} для измененных полей
|
||||||
|
"""
|
||||||
|
update_values = {}
|
||||||
|
changes = {}
|
||||||
|
|
||||||
|
for field, value in update_data.model_dump(exclude_unset=True).items():
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if isinstance(value, (AccountRole, AccountStatus)):
|
||||||
|
update_values[field] = value.value
|
||||||
|
else:
|
||||||
|
update_values[field] = value
|
||||||
|
|
||||||
|
for field, new_value in update_values.items():
|
||||||
|
if not hasattr(user, field):
|
||||||
|
continue
|
||||||
|
|
||||||
|
current_value = getattr(user, field)
|
||||||
|
|
||||||
|
if isinstance(current_value, Enum):
|
||||||
|
current_value = current_value.value
|
||||||
|
|
||||||
|
if current_value != new_value:
|
||||||
|
changes[field] = new_value
|
||||||
|
|
||||||
|
return changes if changes else None
|
||||||
|
|
||||||
|
|
||||||
|
def update_key_data_changes(update_data: AccountKeyringUpdate, key) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
Сравнивает данные для обновления с текущими значениями пользователя.
|
||||||
|
Возвращает:
|
||||||
|
- None, если нет изменений
|
||||||
|
- Словарь {поле: новое_значение} для измененных полей
|
||||||
|
"""
|
||||||
|
update_values = {}
|
||||||
|
changes = {}
|
||||||
|
|
||||||
|
for field, value in update_data.model_dump(exclude_unset=True).items():
|
||||||
|
if value is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if isinstance(value, (KeyType, KeyStatus)):
|
||||||
|
update_values[field] = value.value
|
||||||
|
else:
|
||||||
|
update_values[field] = value
|
||||||
|
|
||||||
|
for field, new_value in update_values.items():
|
||||||
|
if not hasattr(key, field):
|
||||||
|
continue
|
||||||
|
|
||||||
|
current_value = getattr(key, field)
|
||||||
|
|
||||||
|
if isinstance(current_value, Enum):
|
||||||
|
current_value = current_value.value
|
||||||
|
|
||||||
|
if current_value != new_value:
|
||||||
|
changes[field] = new_value
|
||||||
|
|
||||||
|
return changes if changes else None
|
13
api/api/services/user_role_validation.py
Normal file
13
api/api/services/user_role_validation.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from fastapi import (
|
||||||
|
HTTPException,
|
||||||
|
status,
|
||||||
|
)
|
||||||
|
from api.db.logic.account import get_user_by_login
|
||||||
|
from api.db.tables.account import AccountRole
|
||||||
|
|
||||||
|
|
||||||
|
async def db_user_role_validation(connection, current_user):
|
||||||
|
authorize_user = await get_user_by_login(connection, current_user)
|
||||||
|
if authorize_user.role not in {AccountRole.OWNER, AccountRole.ADMIN}:
|
||||||
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="You do not have enough permissions")
|
||||||
|
return authorize_user
|
16
api/api/utils/hasher.py
Normal file
16
api/api/utils/hasher.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import hashlib
|
||||||
|
|
||||||
|
# Хешер для работы с паролем.
|
||||||
|
|
||||||
|
|
||||||
|
class Hasher:
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def hash_data(self, password: str) -> str:
|
||||||
|
# Хеширует пароль с использованием SHA-256.
|
||||||
|
return hashlib.sha256(password.encode()).hexdigest()
|
||||||
|
|
||||||
|
def verify_data(self, password: str, hashed: str) -> bool:
|
||||||
|
# Проверяет пароль путем сравнения его хеша с сохраненным хешем.
|
||||||
|
return self.hash_data(password) == hashed
|
@@ -5,6 +5,7 @@ import secrets
|
|||||||
|
|
||||||
from api.db.connection.session import get_connection
|
from api.db.connection.session import get_connection
|
||||||
from api.db.tables.account import account_table, account_keyring_table, AccountRole, KeyType, KeyStatus
|
from api.db.tables.account import account_table, account_keyring_table, AccountRole, KeyType, KeyStatus
|
||||||
|
from api.utils.key_id_gen import KeyIdGenerator
|
||||||
|
|
||||||
INIT_LOCK_FILE = "../init.lock"
|
INIT_LOCK_FILE = "../init.lock"
|
||||||
DEFAULT_LOGIN = "vorkout"
|
DEFAULT_LOGIN = "vorkout"
|
||||||
@@ -39,6 +40,7 @@ async def init():
|
|||||||
create_key_query = account_keyring_table.insert().values(
|
create_key_query = account_keyring_table.insert().values(
|
||||||
owner_id=user_id,
|
owner_id=user_id,
|
||||||
key_type=KeyType.PASSWORD,
|
key_type=KeyType.PASSWORD,
|
||||||
|
key_id=KeyIdGenerator(),
|
||||||
key_value=hashed_password,
|
key_value=hashed_password,
|
||||||
status=KeyStatus.ACTIVE,
|
status=KeyStatus.ACTIVE,
|
||||||
)
|
)
|
||||||
|
10
api/api/utils/key_id_gen.py
Normal file
10
api/api/utils/key_id_gen.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# Генератор key_id для таблицы account_keyring
|
||||||
|
|
||||||
|
|
||||||
|
def KeyIdGenerator():
|
||||||
|
random_number = random.randint(1000, 9999)
|
||||||
|
result = f"{datetime.now().strftime('%Y-%m-%d')}-{random_number}"
|
||||||
|
return result
|
917
api/poetry.lock
generated
917
api/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "api"
|
name = "api"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [
|
authors = [
|
||||||
{name = "Vladislav",email = "vlad.dev@heado.ru"}
|
{name = "Vladislav",email = "vlad.dev@heado.ru"}
|
||||||
@@ -11,14 +11,24 @@ dependencies = [
|
|||||||
"sqlalchemy[pymysql,aiomysql] (>=2.0.39,<3.0.0)",
|
"sqlalchemy[pymysql,aiomysql] (>=2.0.39,<3.0.0)",
|
||||||
"alembic (>=1.15.1,<2.0.0)",
|
"alembic (>=1.15.1,<2.0.0)",
|
||||||
"aio-pika (>=9.5.5,<10.0.0)",
|
"aio-pika (>=9.5.5,<10.0.0)",
|
||||||
"fastapi[standart] (>=0.115.11,<0.116.0)",
|
"fastapi[standard] (>=0.115.11,<0.116.0)",
|
||||||
"uvicorn (>=0.34.0,<0.35.0)",
|
"uvicorn (>=0.34.0,<0.35.0)",
|
||||||
"loguru (>=0.7.3,<0.8.0)",
|
"loguru (>=0.7.3,<0.8.0)",
|
||||||
"pydantic-settings (>=2.8.1,<3.0.0)",
|
"pydantic-settings (>=2.8.1,<3.0.0)",
|
||||||
"cryptography (>=44.0.2,<45.0.0)",
|
"cryptography (>=44.0.2,<45.0.0)",
|
||||||
|
"pydantic[email] (>=2.11.3,<3.0.0)",
|
||||||
|
"python-multipart (>=0.0.20,<0.0.21)",
|
||||||
|
"fastapi-jwt-auth @ git+https://github.com/vvpreo/fastapi-jwt-auth",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
ruff = "^0.11.10"
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
line-length = 120
|
||||||
|
extend-exclude = ["alembic"]
|
||||||
|
95
client/package-lock.json
generated
95
client/package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.6.1",
|
"@ant-design/icons": "^5.6.1",
|
||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
"@types/react": "^19.0.11",
|
"@types/react": "^19.0.11",
|
||||||
"@types/react-dom": "^19.0.4",
|
"@types/react-dom": "^19.0.4",
|
||||||
"antd": "^5.24.7",
|
"antd": "^5.24.7",
|
||||||
|
"axios": "^1.9.0",
|
||||||
|
"axios-retry": "^4.5.0",
|
||||||
"i18next": "^25.0.1",
|
"i18next": "^25.0.1",
|
||||||
"i18next-browser-languagedetector": "^8.0.5",
|
"i18next-browser-languagedetector": "^8.0.5",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
@@ -26,7 +28,8 @@
|
|||||||
"react-router-dom": "^7.5.0",
|
"react-router-dom": "^7.5.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4",
|
||||||
|
"zustand": "^5.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@adobe/css-tools": {
|
"node_modules/@adobe/css-tools": {
|
||||||
@@ -5262,6 +5265,45 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "1.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz",
|
||||||
|
"integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.15.6",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/axios-retry": {
|
||||||
|
"version": "4.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-4.5.0.tgz",
|
||||||
|
"integrity": "sha512-aR99oXhpEDGo0UuAlYcn2iGRds30k366Zfa05XWScR9QaQD4JYiP3/1Qt1u7YlefUOK+cn0CcwoL1oefavQUlQ==",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"is-retry-allowed": "^2.2.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"axios": "0.x || 1.x"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/axios/node_modules/form-data": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"es-set-tostringtag": "^2.1.0",
|
||||||
|
"hasown": "^2.0.2",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/axobject-query": {
|
"node_modules/axobject-query": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz",
|
||||||
@@ -10063,6 +10105,18 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-retry-allowed": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/is-root": {
|
"node_modules/is-root": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-root/-/is-root-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-root/-/is-root-2.1.0.tgz",
|
||||||
@@ -14085,6 +14139,12 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/proxy-from-env": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/psl": {
|
"node_modules/psl": {
|
||||||
"version": "1.15.0",
|
"version": "1.15.0",
|
||||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",
|
"resolved": "https://registry.npmjs.org/psl/-/psl-1.15.0.tgz",
|
||||||
@@ -18743,6 +18803,35 @@
|
|||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zustand": {
|
||||||
|
"version": "5.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/zustand/-/zustand-5.0.5.tgz",
|
||||||
|
"integrity": "sha512-mILtRfKW9xM47hqxGIxCv12gXusoY/xTSHBYApXozR0HmQv299whhBeeAcRy+KrPPybzosvJBCOmVjq6x12fCg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.20.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/react": ">=18.0.0",
|
||||||
|
"immer": ">=9.0.6",
|
||||||
|
"react": ">=18.0.0",
|
||||||
|
"use-sync-external-store": ">=1.2.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"immer": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"react": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"use-sync-external-store": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "client",
|
"name": "client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^5.6.1",
|
"@ant-design/icons": "^5.6.1",
|
||||||
@@ -13,6 +13,8 @@
|
|||||||
"@types/react": "^19.0.11",
|
"@types/react": "^19.0.11",
|
||||||
"@types/react-dom": "^19.0.4",
|
"@types/react-dom": "^19.0.4",
|
||||||
"antd": "^5.24.7",
|
"antd": "^5.24.7",
|
||||||
|
"axios": "^1.9.0",
|
||||||
|
"axios-retry": "^4.5.0",
|
||||||
"i18next": "^25.0.1",
|
"i18next": "^25.0.1",
|
||||||
"i18next-browser-languagedetector": "^8.0.5",
|
"i18next-browser-languagedetector": "^8.0.5",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
@@ -21,7 +23,8 @@
|
|||||||
"react-router-dom": "^7.5.0",
|
"react-router-dom": "^7.5.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"typescript": "^4.9.5",
|
"typescript": "^4.9.5",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4",
|
||||||
|
"zustand": "^5.0.5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
3
client/public/icons/logo.svg
Normal file
3
client/public/icons/logo.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M52.0626 73.9965L52.0348 76.7513C51.9791 79.687 49.6 82.0452 46.6644 82.0452C43.8957 82.0452 41.6139 79.9444 41.3357 77.2383L41.3217 77.1965C41.3217 76.953 41.1269 76.7583 40.8835 76.7513C40.8835 76.7513 36.7235 76.1391 35.5548 75.8052C34.7757 75.5826 34.7061 73.9965 35.9722 73.9965H52.0696H52.0626ZM76.0904 73.9965L76.1183 76.7513C76.1739 79.687 78.5531 82.0452 81.4887 82.0452C84.2574 82.0452 86.5391 79.9444 86.8174 77.2383L86.8313 77.1965C86.8313 76.953 87.0261 76.7583 87.2696 76.7513C87.2696 76.7513 91.4296 76.1391 92.5983 75.8052C93.3774 75.5826 93.447 73.9965 92.1809 73.9965H76.0835H76.0904ZM58.233 127.979V103.123C54.6643 105.468 51.0957 105.085 50.4557 105.023V126.804C53.0157 127.353 55.6104 127.75 58.233 127.979ZM69.8157 103.123V128C72.4383 127.777 75.0331 127.388 77.593 126.845V105.023C76.953 105.085 73.3774 105.468 69.8157 103.123ZM127.993 64.1183C127.993 109.913 86.88 124.139 85.3704 124.668V96.2157H79.5339C72.6957 96.2157 67.1583 90.5809 67.1583 83.6313V73.9965H60.9948V83.6313C60.9948 90.5809 55.4574 96.2157 48.6191 96.2157H42.6783V124.591C26.6435 118.908 0 99.9861 0 64.1183C0 24.9252 32.4244 0 64 0C103.847 0 128 32.487 128 64.1183H127.993ZM56.5774 70.5948C56.5774 65.5443 52.5565 61.4539 47.5896 61.4539H35.4504C30.4835 61.4539 26.4626 65.5443 26.4626 70.5948V81.5652C26.4626 86.6226 30.4835 90.7061 35.4504 90.7061H47.5896C52.5565 90.7061 56.5774 86.6157 56.5774 81.5652V70.5948ZM79.5339 55.9444C79.5339 55.9444 87.8609 55.9652 93.1687 55.9861V43.4713C93.1687 33.6765 85.2452 25.7391 75.4644 25.7391H52.6539C42.88 25.7391 34.9496 33.6765 34.9496 43.4713V55.9861C40.2504 55.9722 48.6122 55.9444 48.6122 55.9444C55.2417 55.9444 60.633 61.2383 60.96 67.8957H67.1861C67.5131 61.2383 72.9044 55.9444 79.5339 55.9444ZM92.7026 90.6991C97.6696 90.6991 101.69 86.6087 101.69 81.5583V70.5878C101.69 65.5374 97.6696 61.447 92.7026 61.447H80.5635C75.5965 61.447 71.5757 65.5374 71.5757 70.5878V81.5583C71.5757 86.6087 75.5965 90.6991 80.5635 90.6991H92.7026ZM120.188 64.1113C120.188 33.0713 95.7009 7.81914 64 7.81914C32.2991 7.81914 7.81218 33.0713 7.81218 64.1113C7.81218 84.487 18.6783 102.372 34.9078 112.257V96.2087H31.9165C25.0852 96.2087 19.5409 90.5739 19.5409 83.6244V74.087H18.3165C17.5931 74.087 17.0017 73.5374 17.0017 72.8626V69.1478C17.0017 68.473 17.5931 67.9235 18.3165 67.9235H19.5617C19.7565 62.8035 22.8522 58.5461 27.2765 56.8V41.2313C27.2765 28.8348 37.3078 18.7896 49.6765 18.7896H78.4696C90.8383 18.7896 100.87 28.8348 100.87 41.2313V56.793C105.301 58.5322 108.41 62.7965 108.605 67.9235H109.85C110.574 67.9235 111.165 68.473 111.165 69.1478V72.8626C111.165 73.5374 110.574 74.087 109.85 74.087H108.626V83.6244C108.626 90.5739 103.089 96.2087 96.2505 96.2087H93.1548V112.383C109.503 102.525 120.188 84.5774 120.188 64.1113Z" fill="#333333"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
@@ -2,12 +2,13 @@ import React from 'react';
|
|||||||
import { Route, Routes } from 'react-router-dom';
|
import { Route, Routes } from 'react-router-dom';
|
||||||
import MainLayout from './pages/MainLayout';
|
import MainLayout from './pages/MainLayout';
|
||||||
import ProtectedRoute from './pages/ProtectedRoute';
|
import ProtectedRoute from './pages/ProtectedRoute';
|
||||||
|
import LoginPage from './pages/LoginPage';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/login" element={<div>login</div>} />
|
<Route path="/login" element={<LoginPage />} />
|
||||||
<Route element={<ProtectedRoute />}>
|
<Route element={<ProtectedRoute />}>
|
||||||
<Route path="*" element={<MainLayout />}></Route>
|
<Route path="*" element={<MainLayout />}></Route>
|
||||||
</Route>
|
</Route>
|
||||||
|
88
client/src/api/api.ts
Normal file
88
client/src/api/api.ts
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { Access, Auth } from '../types/auth';
|
||||||
|
import { User } from '../types/user';
|
||||||
|
import { AuthService } from '../services/auth';
|
||||||
|
import axiosRetry from 'axios-retry';
|
||||||
|
|
||||||
|
const baseURL = `${process.env.REACT_APP_HTTP_PROTOCOL}://${process.env.REACT_APP_API_URL}/api/v1`;
|
||||||
|
|
||||||
|
const base = axios.create({
|
||||||
|
baseURL,
|
||||||
|
withCredentials: true,
|
||||||
|
headers: {
|
||||||
|
accepts: 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
base.interceptors.request.use((config) => {
|
||||||
|
const token = localStorage.getItem('accessToken');
|
||||||
|
if (token) {
|
||||||
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
// axiosRetry(base, {
|
||||||
|
// retries: 3,
|
||||||
|
// retryDelay: (retryCount: number) => {
|
||||||
|
// console.log(`retry attempt: ${retryCount}`);
|
||||||
|
// return retryCount * 2000;
|
||||||
|
// },
|
||||||
|
// retryCondition: async (error: any) => {
|
||||||
|
// if (error.code === 'ERR_CANCELED') {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
base.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
async function (error) {
|
||||||
|
console.log('error', error);
|
||||||
|
const originalRequest = error.response.config;
|
||||||
|
console.log('originalRequest._retry', originalRequest);
|
||||||
|
const urlTokens = error?.request?.responseURL.split('/');
|
||||||
|
const url = urlTokens[urlTokens.length - 1];
|
||||||
|
console.log('url', url);
|
||||||
|
if (
|
||||||
|
error.response.status === 401 &&
|
||||||
|
!(originalRequest?._retry != null) &&
|
||||||
|
url !== 'login' &&
|
||||||
|
url !== 'refresh' &&
|
||||||
|
url !== 'logout'
|
||||||
|
) {
|
||||||
|
originalRequest._retry = true;
|
||||||
|
const res = await AuthService.refresh().catch(async () => {
|
||||||
|
await AuthService.logout();
|
||||||
|
});
|
||||||
|
console.log('res', res);
|
||||||
|
return await base(originalRequest);
|
||||||
|
}
|
||||||
|
return await Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const api = {
|
||||||
|
// auth
|
||||||
|
async login(auth: Auth): Promise<Access> {
|
||||||
|
console.log(auth);
|
||||||
|
const response = await base.post<Access>('/auth', auth);
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
|
||||||
|
async refreshToken(): Promise<Access> {
|
||||||
|
const response = await base.post<Access>('/auth/refresh');
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
|
||||||
|
// user
|
||||||
|
async getProfile(): Promise<User> {
|
||||||
|
const response = await base.get<User>('/profile');
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default api;
|
103
client/src/pages/LoginPage.tsx
Normal file
103
client/src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Form, Input, Button, Typography } from 'antd';
|
||||||
|
import {
|
||||||
|
EyeInvisibleOutlined,
|
||||||
|
EyeTwoTone,
|
||||||
|
UserOutlined,
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
import { AuthService } from '../services/auth';
|
||||||
|
import { Auth } from '../types/auth';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
const { Text, Link } = Typography;
|
||||||
|
|
||||||
|
export default function LoginPage() {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const onFinish = async (values: any) => {
|
||||||
|
await AuthService.login(values as Auth);
|
||||||
|
navigate('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: '100vh',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: '100%',
|
||||||
|
maxWidth: 472,
|
||||||
|
padding: 24,
|
||||||
|
background: '#fff',
|
||||||
|
textAlign: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ marginBottom: 32 }}>
|
||||||
|
<img
|
||||||
|
src="./icons/logo.svg"
|
||||||
|
alt="logo"
|
||||||
|
style={{ width: 128, height: 128, marginBottom: 16 }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Form name="login" onFinish={onFinish} layout="vertical">
|
||||||
|
<Form.Item
|
||||||
|
name="login"
|
||||||
|
rules={[{ required: true, message: 'Введите login' }]}
|
||||||
|
>
|
||||||
|
<Input size="large" placeholder="Логин" prefix={<UserOutlined />} />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="password"
|
||||||
|
rules={[{ required: true, message: 'Введите пароль' }]}
|
||||||
|
>
|
||||||
|
<Input.Password
|
||||||
|
size="large"
|
||||||
|
placeholder="Пароль"
|
||||||
|
iconRender={(visible) =>
|
||||||
|
visible ? <EyeTwoTone /> : <EyeInvisibleOutlined />
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
htmlType="submit"
|
||||||
|
block
|
||||||
|
size="large"
|
||||||
|
style={{
|
||||||
|
backgroundColor: '#C2DA3D',
|
||||||
|
borderColor: '#C2DA3D',
|
||||||
|
color: '#000',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Войти
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||||
|
Нажимая кнопку Войти, Вы полностью принимаете{' '}
|
||||||
|
<Link href="/offer" target="_blank">
|
||||||
|
Публичную оферту
|
||||||
|
</Link>{' '}
|
||||||
|
и{' '}
|
||||||
|
<Link href="/privacy" target="_blank">
|
||||||
|
Политику обработки персональных данных
|
||||||
|
</Link>
|
||||||
|
</Text>
|
||||||
|
</Form>
|
||||||
|
|
||||||
|
<div style={{ marginTop: 256 }}>
|
||||||
|
<Link href="/forgot-password">Забыли пароль?</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
@@ -9,6 +9,8 @@ import RunningProcessesPage from './RunningProcessesPage';
|
|||||||
import AccountsPage from './AccountsPage';
|
import AccountsPage from './AccountsPage';
|
||||||
import EventsListPage from './EventsListPage';
|
import EventsListPage from './EventsListPage';
|
||||||
import ConfigurationPage from './ConfigurationPage';
|
import ConfigurationPage from './ConfigurationPage';
|
||||||
|
import { useSetUserSelector } from '../store/user';
|
||||||
|
import { UserService } from '../services/user';
|
||||||
|
|
||||||
export default function MainLayout() {
|
export default function MainLayout() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -19,6 +21,8 @@ export default function MainLayout() {
|
|||||||
const [width, setWidth] = useState<number | string>('15%');
|
const [width, setWidth] = useState<number | string>('15%');
|
||||||
const [collapsedWidth, setCollapsedWidth] = useState(50);
|
const [collapsedWidth, setCollapsedWidth] = useState(50);
|
||||||
|
|
||||||
|
const setUser = useSetUserSelector()
|
||||||
|
|
||||||
const calculateWidths = () => {
|
const calculateWidths = () => {
|
||||||
const windowWidth = window.innerWidth;
|
const windowWidth = window.innerWidth;
|
||||||
const expanded = Math.min(Math.max(windowWidth * 0.15, 180), 240);
|
const expanded = Math.min(Math.max(windowWidth * 0.15, 180), 240);
|
||||||
@@ -54,6 +58,21 @@ export default function MainLayout() {
|
|||||||
navigate(key);
|
navigate(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const token = localStorage.getItem('accessToken');
|
||||||
|
if (!token) {
|
||||||
|
navigate('/login');
|
||||||
|
} else {
|
||||||
|
if (localStorage.getItem('user')) {
|
||||||
|
setUser(JSON.parse(localStorage.getItem('user') as string))
|
||||||
|
} else {
|
||||||
|
UserService.getProfile().then((user) => {
|
||||||
|
setUser(user);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ minHeight: '100vh' }}>
|
<Layout style={{ minHeight: '100vh' }}>
|
||||||
<Sider
|
<Sider
|
||||||
|
@@ -1,8 +1,19 @@
|
|||||||
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
// ProtectedRoute.js
|
// ProtectedRoute.js
|
||||||
import { Outlet } from 'react-router-dom';
|
import { Outlet, useNavigate } from 'react-router-dom';
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
|
import { useUserSelector } from '../store/user';
|
||||||
|
|
||||||
const ProtectedRoute = (): React.JSX.Element => {
|
const ProtectedRoute = (): React.JSX.Element => {
|
||||||
|
const user = useUserSelector();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user.id === null) {
|
||||||
|
navigate('/login');
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
return <Outlet />;
|
return <Outlet />;
|
||||||
};
|
};
|
||||||
export default ProtectedRoute;
|
export default ProtectedRoute;
|
||||||
|
22
client/src/services/auth.ts
Normal file
22
client/src/services/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import api from '../api/api';
|
||||||
|
import { useUserStore } from '../store/user';
|
||||||
|
import { Auth } from '../types/auth';
|
||||||
|
|
||||||
|
export class AuthService {
|
||||||
|
static async login(auth: Auth) {
|
||||||
|
const token = await api.login(auth);
|
||||||
|
console.log(token)
|
||||||
|
localStorage.setItem('accessToken', token.accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async logout() {
|
||||||
|
useUserStore.getState().removeUser();
|
||||||
|
localStorage.removeItem('userInfo');
|
||||||
|
localStorage.removeItem('accessToken');
|
||||||
|
}
|
||||||
|
|
||||||
|
static async refresh() {
|
||||||
|
const token = await api.refreshToken();
|
||||||
|
localStorage.setItem('accessToken', token.accessToken);
|
||||||
|
}
|
||||||
|
}
|
10
client/src/services/user.ts
Normal file
10
client/src/services/user.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import api from '../api/api';
|
||||||
|
import { User } from '../types/user';
|
||||||
|
|
||||||
|
export class UserService {
|
||||||
|
static async getProfile(): Promise<User> {
|
||||||
|
const user = api.getProfile();
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
38
client/src/store/user.ts
Normal file
38
client/src/store/user.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { devtools, persist } from 'zustand/middleware';
|
||||||
|
import { User } from '../types/user';
|
||||||
|
|
||||||
|
const userInfo = localStorage.getItem('userInfo');
|
||||||
|
|
||||||
|
type UserStoreState = {
|
||||||
|
user: User;
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UserStoreActions = {
|
||||||
|
setUser: (user: User) => void;
|
||||||
|
removeUser: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UserStore = UserStoreState & UserStoreActions;
|
||||||
|
|
||||||
|
export const useUserStore = create<UserStore>()(
|
||||||
|
devtools(
|
||||||
|
persist(
|
||||||
|
(set, get) => ({
|
||||||
|
user: userInfo != null ? JSON.parse(userInfo) : ({} as User),
|
||||||
|
loading: false,
|
||||||
|
setUser: (user: User) => set({ user }),
|
||||||
|
removeUser: () => set({ user: {} as User }),
|
||||||
|
}),
|
||||||
|
{ name: 'userInfo' }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const useUserSelector = () => {
|
||||||
|
return useUserStore((state) => state.user);
|
||||||
|
};
|
||||||
|
export const useSetUserSelector = () => {
|
||||||
|
return useUserStore((state) => state.setUser);
|
||||||
|
};
|
4
client/src/types/auth.ts
Normal file
4
client/src/types/auth.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { components } from './openapi-types';
|
||||||
|
|
||||||
|
export type Auth = components['schemas']['Auth'];
|
||||||
|
export type Access = components['schemas']['Access'];
|
692
client/src/types/openapi-types.ts
Normal file
692
client/src/types/openapi-types.ts
Normal file
@@ -0,0 +1,692 @@
|
|||||||
|
/**
|
||||||
|
* This file was auto-generated by openapi-typescript.
|
||||||
|
* Do not make direct changes to the file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface paths {
|
||||||
|
"/api/v1/auth": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
/**
|
||||||
|
* Login For Access Token
|
||||||
|
* @description Авторизирует, выставляет токены в куки.
|
||||||
|
*/
|
||||||
|
post: operations["login_for_access_token_api_v1_auth_post"];
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/auth/refresh": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
/** Refresh */
|
||||||
|
post: operations["refresh_api_v1_auth_refresh_post"];
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/profile": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/** Get Profile */
|
||||||
|
get: operations["get_profile_api_v1_profile_get"];
|
||||||
|
/** Update Profile */
|
||||||
|
put: operations["update_profile_api_v1_profile_put"];
|
||||||
|
post?: never;
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/account": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/** Get All Account */
|
||||||
|
get: operations["get_all_account_api_v1_account_get"];
|
||||||
|
put?: never;
|
||||||
|
/** Create Account */
|
||||||
|
post: operations["create_account_api_v1_account_post"];
|
||||||
|
delete?: never;
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/account/{user_id}": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/** Get Account */
|
||||||
|
get: operations["get_account_api_v1_account__user_id__get"];
|
||||||
|
/** Update Account */
|
||||||
|
put: operations["update_account_api_v1_account__user_id__put"];
|
||||||
|
post?: never;
|
||||||
|
/** Delete Account */
|
||||||
|
delete: operations["delete_account_api_v1_account__user_id__delete"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/api/v1/keyring/{user_id}/{key_id}": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
/** Get Keyring */
|
||||||
|
get: operations["get_keyring_api_v1_keyring__user_id___key_id__get"];
|
||||||
|
/** Update Keyring */
|
||||||
|
put: operations["update_keyring_api_v1_keyring__user_id___key_id__put"];
|
||||||
|
/** Create Keyring */
|
||||||
|
post: operations["create_keyring_api_v1_keyring__user_id___key_id__post"];
|
||||||
|
/** Delete Keyring */
|
||||||
|
delete: operations["delete_keyring_api_v1_keyring__user_id___key_id__delete"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export type webhooks = Record<string, never>;
|
||||||
|
export interface components {
|
||||||
|
schemas: {
|
||||||
|
/** Access */
|
||||||
|
Access: {
|
||||||
|
/** Accesstoken */
|
||||||
|
accessToken: string;
|
||||||
|
};
|
||||||
|
/** AccountKeyring */
|
||||||
|
AccountKeyring: {
|
||||||
|
/** Ownerid */
|
||||||
|
ownerId: number;
|
||||||
|
keyType: components["schemas"]["KeyType"];
|
||||||
|
/** Keyid */
|
||||||
|
keyId?: string | null;
|
||||||
|
/** Keyvalue */
|
||||||
|
keyValue: string;
|
||||||
|
/**
|
||||||
|
* Createdat
|
||||||
|
* Format: date-time
|
||||||
|
*/
|
||||||
|
createdAt: string;
|
||||||
|
/** Expiry */
|
||||||
|
expiry?: string | null;
|
||||||
|
status: components["schemas"]["KeyStatus"];
|
||||||
|
};
|
||||||
|
/** AccountKeyringUpdate */
|
||||||
|
AccountKeyringUpdate: {
|
||||||
|
/** Ownerid */
|
||||||
|
ownerId?: number | null;
|
||||||
|
keyType?: components["schemas"]["KeyType"] | null;
|
||||||
|
/** Keyid */
|
||||||
|
keyId?: string | null;
|
||||||
|
/** Keyvalue */
|
||||||
|
keyValue?: string | null;
|
||||||
|
/** Createdat */
|
||||||
|
createdAt?: string | null;
|
||||||
|
/** Expiry */
|
||||||
|
expiry?: string | null;
|
||||||
|
status?: components["schemas"]["KeyStatus"] | null;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* AccountRole
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
AccountRole: "OWNER" | "ADMIN" | "EDITOR" | "VIEWER";
|
||||||
|
/**
|
||||||
|
* AccountStatus
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
AccountStatus: "ACTIVE" | "DISABLED" | "BLOCKED" | "DELETED";
|
||||||
|
/** AllUser */
|
||||||
|
AllUser: {
|
||||||
|
/** Id */
|
||||||
|
id: number;
|
||||||
|
/** Name */
|
||||||
|
name: string;
|
||||||
|
/** Login */
|
||||||
|
login: string;
|
||||||
|
/** Email */
|
||||||
|
email?: string | null;
|
||||||
|
/** Bindtenantid */
|
||||||
|
bindTenantId?: string | null;
|
||||||
|
role: components["schemas"]["AccountRole"];
|
||||||
|
/**
|
||||||
|
* Createdat
|
||||||
|
* Format: date-time
|
||||||
|
*/
|
||||||
|
createdAt: string;
|
||||||
|
status: components["schemas"]["AccountStatus"];
|
||||||
|
};
|
||||||
|
/** AllUserResponse */
|
||||||
|
AllUserResponse: {
|
||||||
|
/** Users */
|
||||||
|
users: components["schemas"]["AllUser"][];
|
||||||
|
/** Amountcount */
|
||||||
|
amountCount: number;
|
||||||
|
/** Amountpages */
|
||||||
|
amountPages: number;
|
||||||
|
};
|
||||||
|
/** Auth */
|
||||||
|
Auth: {
|
||||||
|
/** Login */
|
||||||
|
login: string;
|
||||||
|
/** Password */
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
/** HTTPValidationError */
|
||||||
|
HTTPValidationError: {
|
||||||
|
/** Detail */
|
||||||
|
detail?: components["schemas"]["ValidationError"][];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* KeyStatus
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
KeyStatus: "ACTIVE" | "EXPIRED" | "DELETED";
|
||||||
|
/**
|
||||||
|
* KeyType
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
KeyType: "PASSWORD" | "ACCESS_TOKEN" | "REFRESH_TOKEN" | "API_KEY";
|
||||||
|
/** User */
|
||||||
|
User: {
|
||||||
|
/** Id */
|
||||||
|
id?: number | null;
|
||||||
|
/** Name */
|
||||||
|
name: string;
|
||||||
|
/** Login */
|
||||||
|
login: string;
|
||||||
|
/** Email */
|
||||||
|
email?: string | null;
|
||||||
|
/** Bindtenantid */
|
||||||
|
bindTenantId?: string | null;
|
||||||
|
role: components["schemas"]["AccountRole"];
|
||||||
|
/** Meta */
|
||||||
|
meta: {
|
||||||
|
[key: string]: unknown;
|
||||||
|
};
|
||||||
|
/** Creatorid */
|
||||||
|
creatorId?: number | null;
|
||||||
|
/**
|
||||||
|
* Createdat
|
||||||
|
* Format: date-time
|
||||||
|
*/
|
||||||
|
createdAt: string;
|
||||||
|
status: components["schemas"]["AccountStatus"];
|
||||||
|
};
|
||||||
|
/** UserUpdate */
|
||||||
|
UserUpdate: {
|
||||||
|
/** Id */
|
||||||
|
id?: number | null;
|
||||||
|
/** Name */
|
||||||
|
name?: string | null;
|
||||||
|
/** Login */
|
||||||
|
login?: string | null;
|
||||||
|
/** Email */
|
||||||
|
email?: string | null;
|
||||||
|
/** Bindtenantid */
|
||||||
|
bindTenantId?: string | null;
|
||||||
|
role?: components["schemas"]["AccountRole"] | null;
|
||||||
|
/** Meta */
|
||||||
|
meta?: {
|
||||||
|
[key: string]: unknown;
|
||||||
|
} | null;
|
||||||
|
/** Creatorid */
|
||||||
|
creatorId?: number | null;
|
||||||
|
/** Createdat */
|
||||||
|
createdAt?: string | null;
|
||||||
|
status?: components["schemas"]["AccountStatus"] | null;
|
||||||
|
};
|
||||||
|
/** ValidationError */
|
||||||
|
ValidationError: {
|
||||||
|
/** Location */
|
||||||
|
loc: (string | number)[];
|
||||||
|
/** Message */
|
||||||
|
msg: string;
|
||||||
|
/** Error Type */
|
||||||
|
type: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: never;
|
||||||
|
parameters: never;
|
||||||
|
requestBodies: never;
|
||||||
|
headers: never;
|
||||||
|
pathItems: never;
|
||||||
|
}
|
||||||
|
export type $defs = Record<string, never>;
|
||||||
|
export interface operations {
|
||||||
|
login_for_access_token_api_v1_auth_post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["Auth"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["Access"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
refresh_api_v1_auth_refresh_post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["Access"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
get_profile_api_v1_profile_get: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
update_profile_api_v1_profile_put: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["UserUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
get_all_account_api_v1_account_get: {
|
||||||
|
parameters: {
|
||||||
|
query?: {
|
||||||
|
page?: number;
|
||||||
|
limit?: number;
|
||||||
|
};
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AllUserResponse"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
create_account_api_v1_account_post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["UserUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
get_account_api_v1_account__user_id__get: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
update_account_api_v1_account__user_id__put: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["UserUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
delete_account_api_v1_account__user_id__delete: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["User"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
get_keyring_api_v1_keyring__user_id___key_id__get: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
key_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyring"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
update_keyring_api_v1_keyring__user_id___key_id__put: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
key_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyringUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyring"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
create_keyring_api_v1_keyring__user_id___key_id__post: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
key_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody: {
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyringUpdate"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyring"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
delete_keyring_api_v1_keyring__user_id___key_id__delete: {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path: {
|
||||||
|
user_id: number;
|
||||||
|
key_id: string;
|
||||||
|
};
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description Successful Response */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["AccountKeyring"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/** @description Validation Error */
|
||||||
|
422: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content: {
|
||||||
|
"application/json": components["schemas"]["HTTPValidationError"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
3
client/src/types/user.ts
Normal file
3
client/src/types/user.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { components } from "./openapi-types"
|
||||||
|
|
||||||
|
export type User = components["schemas"]["User"];
|
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "connect",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
1
package.json
Normal file
1
package.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
Reference in New Issue
Block a user