Add linters configs

This commit is contained in:
2022-01-09 02:00:00 +03:00
parent 0aca5399ef
commit 89fe884ae8
15 changed files with 801 additions and 50 deletions

View File

@@ -1,18 +1,21 @@
from alembic import context
import sys, os
import os
import sys
from alembic import context
from sqlalchemy.engine import create_engine
from core.db import DATABASE_URL
myPath = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, myPath + '/../../')
sys.path.insert(0, myPath + "/../../")
config = context.config
from app.models import BaseMeta
target_metadata = BaseMeta.metadata
@@ -62,4 +65,3 @@ if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -10,19 +10,22 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '738a796c3f0a'
down_revision = '7a76c257df70'
revision = "738a796c3f0a"
down_revision = "7a76c257df70"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('privileged', sa.Boolean(), server_default='f', nullable=False))
op.add_column(
"services",
sa.Column("privileged", sa.Boolean(), server_default="f", nullable=False),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('services', 'privileged')
# ### end Alembic commands ###
op.drop_column("services", "privileged")
# ### end Alembic commands ###

View File

@@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7a76c257df70'
revision = "7a76c257df70"
down_revision = None
branch_labels = None
depends_on = None
@@ -18,19 +18,20 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('services',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('token', sa.String(length=128), nullable=False),
sa.Column('user', sa.BigInteger(), nullable=False),
sa.Column('status', sa.String(length=12), nullable=True),
sa.Column('created_time', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('token')
op.create_table(
"services",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("token", sa.String(length=128), nullable=False),
sa.Column("user", sa.BigInteger(), nullable=False),
sa.Column("status", sa.String(length=12), nullable=True),
sa.Column("created_time", sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("token"),
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('services')
# ### end Alembic commands ###
op.drop_table("services")
# ### end Alembic commands ###

View File

@@ -10,21 +10,30 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '85ece6cfed22'
down_revision = '738a796c3f0a'
revision = "85ece6cfed22"
down_revision = "738a796c3f0a"
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('cache', sa.String(length=12), nullable=True))
op.drop_column('services', 'privileged')
op.add_column("services", sa.Column("cache", sa.String(length=12), nullable=True))
op.drop_column("services", "privileged")
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('services', sa.Column('privileged', sa.BOOLEAN(), server_default=sa.text('false'), autoincrement=False, nullable=False))
op.drop_column('services', 'cache')
# ### end Alembic commands ###
op.add_column(
"services",
sa.Column(
"privileged",
sa.BOOLEAN(),
server_default=sa.text("false"),
autoincrement=False,
nullable=False,
),
)
op.drop_column("services", "cache")
# ### end Alembic commands ###

View File

@@ -6,4 +6,6 @@ from core.config import env_config
async def check_token(api_key: str = Security(default_security)):
if api_key != env_config.API_KEY:
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Wrong api key!")
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, detail="Wrong api key!"
)

View File

@@ -1,5 +1,5 @@
from enum import Enum
from datetime import datetime
from enum import Enum
import ormar
@@ -26,10 +26,14 @@ class CachePrivileges(str, Enum):
class Service(ormar.Model):
class Meta(BaseMeta):
tablename = "services"
id: int = ormar.Integer(primary_key=True) # type: ignore
token: str = ormar.String(max_length=128, unique=True) # type: ignore
user: int = ormar.BigInteger() # type: ignore
status: str = ormar.String(max_length=12, choices=list(Statuses), default=Statuses.pending) # type: ignore
cache: str = ormar.String(max_length=12, choices=list(CachePrivileges), default=CachePrivileges.no_cache) # type: ignore
status: str = ormar.String(
max_length=12, choices=list(Statuses), default=Statuses.pending
) # type: ignore
cache: str = ormar.String(
max_length=12, choices=list(CachePrivileges), default=CachePrivileges.no_cache
) # type: ignore
created_time = ormar.DateTime(timezone=True, default=datetime.now)

View File

@@ -1,16 +1,14 @@
from fastapi import APIRouter, HTTPException, status, Depends
from app.depends import check_token
from app.serializers import ServiceCreate, ServiceDetail
from app.models import CachePrivileges, Service, Statuses
from app.serializers import ServiceCreate, ServiceDetail
# TODO: add redis cache
router = APIRouter(
dependencies=[Depends(check_token)]
)
router = APIRouter(dependencies=[Depends(check_token)])
@router.get("/", response_model=list[ServiceDetail])
@@ -24,7 +22,7 @@ async def get_service(id: int):
if service is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
return service
@@ -42,7 +40,7 @@ async def update_service_state(id: int, new_status: Statuses):
service.status = new_status
await service.update(['status'])
await service.update(["status"])
return service
@@ -56,6 +54,6 @@ async def update_service_cache(id: int, new_cache: CachePrivileges):
service.cache = new_cache
await service.update(['cache'])
await service.update(["cache"])
return service