Skip to content

Commit e61f9ed

Browse files
Refactor: cosmetic (#900)
1 parent 433e3f8 commit e61f9ed

17 files changed

Lines changed: 91 additions & 54 deletions

File tree

.docker/lint.Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ ENV VIRTUAL_ENV=/venvs/.venv \
2929

3030
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
3131

32-
COPY app /app
33-
COPY pyproject.toml ./
32+
COPY . /app

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Load image
4242
run: docker load -i /tmp/linter_image.tar
4343
- name: Run ruff check
44-
run: docker run linter:latest ruff check --output-format=github .
44+
run: docker run linter:latest ruff check --output-format=github
4545

4646
run_ruff_format:
4747
runs-on: ubuntu-latest

Makefile

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
help: ## show help message
33
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
44

5-
before_pr:
6-
ruff format ./app
7-
ruff check ./app --fix --unsafe-fixes
8-
mypy ./app
5+
before_pr: ## format, lint and type-check code
6+
ruff format
7+
ruff check --fix --unsafe-fixes
8+
mypy .
99

1010
build: ## build app and manually generate self-signed cert
1111
make down
@@ -15,29 +15,35 @@ build_test:
1515
docker compose -f docker-compose.test.yml build
1616

1717
up: ## run tty container with related services, use with run command
18-
make down; docker compose up
18+
make down
19+
docker compose up
1920

2021
test: ## run tests
2122
docker compose -f docker-compose.test.yml down --remove-orphans
22-
make down;
23+
make down
2324
docker compose -f docker-compose.test.yml up --no-log-prefix --attach test --exit-code-from test
2425

2526
run: ## runs server 386/636 port
2627
clear;docker exec -it multidirectory sh -c "python ."
2728

2829
launch: ## run standalone app without tty container
29-
docker compose down;
30-
docker compose run sh -c "alembic upgrade head && python ."
30+
docker compose down
31+
docker compose run sh -c "python multidirectory.py --migrate && python ."
3132

32-
downgrade: ## re-run migration
33-
docker exec -it multidirectory_api sh -c\
34-
"alembic downgrade -1; alembic upgrade head;"
33+
rerun_last_migration: ## re-run migration
34+
docker exec -it multidirectory_api sh -c "alembic downgrade -1; python multidirectory.py --migrate;"
3535

3636
down: ## shutdown services
3737
docker compose -f docker-compose.test.yml down --remove-orphans
3838
docker compose down --remove-orphans
3939
docker volume prune -f
4040

41+
migrations: ## generate migration file
42+
docker compose run ldap_server alembic revision --autogenerate
43+
44+
migrate: ## upgrade db
45+
docker compose run ldap_server python multidirectory.py --migrate
46+
4147
# server stage/development commands
4248

4349
stage_gen_cert: ## generate self-signed cert
@@ -48,28 +54,21 @@ stage_build: ## build stage server
4854
docker compose -f docker-compose.dev.yml build
4955

5056
stage_up: ## run app and detach
51-
make stage_down;
57+
make stage_down
5258
docker compose -f docker-compose.dev.yml up -d
5359

5460
stage_down: ## stop all services
5561
docker compose -f docker-compose.dev.yml down --remove-orphans
5662

5763
stage_update: ## update service
58-
make stage_down;
59-
make stage_build;
60-
docker compose -f docker-compose.dev.yml pull;
61-
make stage_up;
62-
docker exec -it multidirectory-ldap sh -c\
63-
"alembic downgrade -1; alembic upgrade head; python -m extra.setup_dev"
64+
make stage_down
65+
make stage_build
66+
docker compose -f docker-compose.dev.yml pull
67+
make stage_up
68+
docker exec -it multidirectory-ldap sh -c "alembic downgrade -1; python multidirectory.py --migrate; python -m extra.setup_dev"
6469

6570
krb_client_build: ## build krb client service
6671
docker build -f integration_tests/kerberos/Dockerfile . -t krbclient:runtime
6772

6873
krb_client: ## run krb client bash
6974
docker run --rm --init -it --name krbclient --network multidirectory_default krbclient:runtime bash
70-
71-
migrations: ## generate migration file
72-
docker compose run ldap_server alembic revision --autogenerate
73-
74-
migrate: ## upgrade db
75-
docker compose run ldap_server alembic upgrade head

app/alembic/versions/6c858cc05da7_add_default_admin_name.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ def upgrade(container: AsyncContainer) -> None: # noqa: ARG001
5555

5656
def downgrade(container: AsyncContainer) -> None:
5757
"""Downgrade."""
58-
# Откатывать не нужно
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Drop unused Directory.password_policy_id column.
2+
3+
Revision ID: ec45e3e8aa0f
4+
Revises: a1b2c3d4e5f6
5+
Create Date: 2026-01-20 14:33:36.236135
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
from dishka import AsyncContainer
12+
13+
# revision identifiers, used by Alembic.
14+
revision: None | str = "ec45e3e8aa0f"
15+
down_revision: None | str = "a1b2c3d4e5f6"
16+
branch_labels: None | list[str] = None
17+
depends_on: None | list[str] = None
18+
19+
20+
def upgrade(container: AsyncContainer) -> None: # noqa: ARG001
21+
"""Upgrade."""
22+
op.drop_constraint(
23+
op.f("Directory_password_policy_id_fkey"),
24+
"Directory",
25+
type_="foreignkey",
26+
)
27+
op.drop_column("Directory", "password_policy_id")
28+
29+
30+
def downgrade(container: AsyncContainer) -> None: # noqa: ARG001
31+
"""Downgrade."""
32+
op.add_column(
33+
"Directory",
34+
sa.Column(
35+
"password_policy_id",
36+
sa.INTEGER(),
37+
autoincrement=False,
38+
nullable=True,
39+
),
40+
)
41+
op.create_foreign_key(
42+
op.f("Directory_password_policy_id_fkey"),
43+
"Directory",
44+
"PasswordPolicies",
45+
["password_policy_id"],
46+
["id"],
47+
)

app/api/exception_handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ async def handle_auth_error(
2929
exc: Exception,
3030
) -> NoReturn:
3131
"""Handle Auth error."""
32-
# fastapi-error-map doesn't handle exceptions from dependencie,
33-
# (get_ldap_session) потому ловим так
32+
# fastapi-error-map doesn't handle exceptions from dependencies
33+
# (get_ldap_session), so we catch them manually here
3434
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail=str(exc))

app/entities.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class Directory:
202202
)
203203
updated_at: datetime | None = field(default=None)
204204
depth: int = field(default=0)
205-
password_policy_id: int | None = None
206205
path: list[str] = field(default_factory=list)
207206

208207
parent: Directory | None = field(default=None, repr=False, compare=False)

app/errors/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from enum import IntEnum
88

99

10-
class BaseDomainException(Exception): # noqa N818
10+
class BaseDomainException(Exception): # noqa: N818
1111
"""Base exception."""
1212

1313
code: IntEnum

app/ldap_protocol/utils/pagination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def get(
104104
session: AsyncSession,
105105
) -> Self:
106106
"""Get paginator."""
107-
if query._order_by_clause is None or len(query._order_by_clause) == 0: # noqa SLF001
107+
if query._order_by_clause is None or len(query._order_by_clause) == 0: # noqa: SLF001
108108
raise ValueError("Select query must have an order_by clause.")
109109

110110
metadata = PaginationMetadata(

app/repo/pg/tables.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ def _compile_create_uc(
147147
),
148148
Column("depth", Integer, nullable=True),
149149
Column("objectSid", String, nullable=True, key="object_sid"),
150-
Column(
151-
"password_policy_id",
152-
Integer,
153-
ForeignKey("PasswordPolicies.id"),
154-
nullable=True,
155-
),
156150
Column(
157151
"objectGUID",
158152
PG_UUID(as_uuid=True),

0 commit comments

Comments
 (0)