Compare commits

..

7 Commits

Author SHA1 Message Date
b2f65ba21f chore: update the patch version to 0.0.2 2025-04-07 16:33:57 +05:00
45effe5a33 Merge pull request 'VORKOUT-10' (#4) from VORKOUT-10 into master
Reviewed-on: #4
Reviewed-by: cyrussmeat <dr.cyrill@gmail.com>
Reviewed-by: ivan.dev <ivan.dev@heado.ru>
2025-04-07 16:32:36 +05:00
83b723f5b9 feat: add init project to Makefile 2025-04-03 12:26:54 +05:00
8b62b8b7a6 refactor(docker-compose): rename containers to prevent duplicate names 2025-04-03 11:12:28 +05:00
ff265ce1d4 Merge pull request 'feat VORKOUT-3: added sql tables, db connection, schemas' (#2) from VORKOUT-3 into master
Reviewed-on: #2
Reviewed-by: Vladislav Syrochkin <vlad.dev@heado.ru>
Reviewed-by: cyrussmeat <dr.cyrill@gmail.com>
2025-04-02 11:55:32 +05:00
7b9ce61733 Merge pull request 'VORKOUT-2' (#3) from VORKOUT-2 into master
Reviewed-on: #3
2025-03-28 18:42:39 +05:00
de184b9bb8 fix(Makefile): fix error No rule to make target '<arg>' 2025-03-28 18:41:45 +05:00
5 changed files with 78 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
venv/ venv/
node_modules/ node_modules/
init.lock
.idea/ .idea/
.vscode/ .vscode/
*.swp *.swp

View File

@ -36,3 +36,15 @@ revision:
source .venv/bin/activate && \ source .venv/bin/activate && \
cd $(API_APPLICATION_NAME)/db && \ cd $(API_APPLICATION_NAME)/db && \
PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic revision --autogenerate PYTHONPATH='../..' ALEMBIC_MIGRATIONS=True alembic revision --autogenerate
venv-api:
cd api && \
poetry install
install:
make migrate head && \
cd api && \
poetry run python3 api/utils/init.py
%::
echo $(MESSAGE)

60
api/api/utils/init.py Normal file
View File

@ -0,0 +1,60 @@
import os
import asyncio
import hashlib
import secrets
from api.db.connection.session import get_connection
from api.db.tables.account import account_table, account_keyring_table, AccountRole, KeyType, KeyStatus
INIT_LOCK_FILE = "../init.lock"
DEFAULT_LOGIN = "vorkout"
def hash_password(password: str) -> str:
return hashlib.sha256(password.encode()).hexdigest()
def generate_password() -> str:
return secrets.token_urlsafe(20)
async def init():
if os.path.exists(INIT_LOCK_FILE):
print("Sorry, service is already initialized")
return
async with get_connection() as conn:
password = generate_password()
hashed_password = hash_password(password)
create_user_query = account_table.insert().values(
name=DEFAULT_LOGIN,
login=DEFAULT_LOGIN,
role=AccountRole.OWNER,
)
res = await conn.execute(create_user_query)
user_id = res.lastrowid
create_key_query = account_keyring_table.insert().values(
owner_id=user_id,
key_type=KeyType.PASSWORD,
key_value=hashed_password,
status=KeyStatus.ACTIVE,
)
await conn.execute(create_key_query)
await conn.commit()
await conn.close()
with open(INIT_LOCK_FILE, "w") as lock_file:
lock_file.write("initialized\n")
print(f"Login: {DEFAULT_LOGIN}")
print(f"Password: {password}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(init())

View File

@ -1,6 +1,6 @@
[project] [project]
name = "api" name = "api"
version = "0.0.1" version = "0.0.2"
description = "" description = ""
authors = [ authors = [
{name = "Vladislav",email = "vlad.dev@heado.ru"} {name = "Vladislav",email = "vlad.dev@heado.ru"}

View File

@ -3,13 +3,13 @@ version: "3.1"
services: services:
rabbitmq: rabbitmq:
image: rabbitmq:4-management-alpine image: rabbitmq:4-management-alpine
container_name: rabbitmq container_name: rabbitmq-connect
ports: ports:
- 5672:5672 - 5672:5672
- 15672:15672 - 15672:15672
db: db:
image: mysql:8.0 image: mysql:8.0
container_name: mysql container_name: mysql-connect
environment: environment:
MYSQL_ROOT_PASSWORD: hackme MYSQL_ROOT_PASSWORD: hackme
MYSQL_DATABASE: connect_test MYSQL_DATABASE: connect_test
@ -21,7 +21,7 @@ services:
- "3306:3306" - "3306:3306"
redis: redis:
image: redis:7-alpine image: redis:7-alpine
container_name: redis container_name: redis-connect
command: redis-server --requirepass password command: redis-server --requirepass password
environment: environment:
REDIS_PASSWORD: hackme REDIS_PASSWORD: hackme