diff --git a/authentication/.env b/authentication/.env deleted file mode 100644 index 1ee35a6..0000000 --- a/authentication/.env +++ /dev/null @@ -1,3 +0,0 @@ -POSTGRES_USER=appuser -POSTGRES_PASSWORD=testpwd -POSTGRES_DB=jcloud-authentification-service-db \ No newline at end of file diff --git a/authentication/Dockerfile b/authentication/Dockerfile deleted file mode 100644 index eaee6d4..0000000 --- a/authentication/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.13-slim -WORKDIR /app -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt -COPY . . -EXPOSE 1234 -CMD ["python3", "main.py"] \ No newline at end of file diff --git a/authentication/Makefile b/authentication/Makefile deleted file mode 100644 index 55bc8bc..0000000 --- a/authentication/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -build: - podman-compose build - -reload: - podman rm authentication_app_1 - podman rm authentication_db_1 - podman rm authentication_migration_1 - -up: - podman-compose up --build - -down: - podman-compose down - -restart: - make down up - -migrate: - cp ../../../server/data/users/auth_data/basis_data/data.db database-migration/data.db -# make reload -# podman-compose -f docker-compose.yml -f docker-compose.migration.yml up --build - podman-compose -f docker-compose.migration.yml up --build - -migrate-test: - podman-compose -f docker-compose.migration.yml up --build \ No newline at end of file diff --git a/authentication/__pycache__/main.cpython-313.pyc b/authentication/__pycache__/main.cpython-313.pyc deleted file mode 100644 index 05037b8..0000000 Binary files a/authentication/__pycache__/main.cpython-313.pyc and /dev/null differ diff --git a/authentication/database-migration/Dockerfile b/authentication/database-migration/Dockerfile deleted file mode 100644 index 0d7072a..0000000 --- a/authentication/database-migration/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM python:3.13-slim -WORKDIR /app/ -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt -COPY . . -CMD ["python3", "db_migration_test2.py"] \ No newline at end of file diff --git a/authentication/database-migration/data.db b/authentication/database-migration/data.db deleted file mode 100644 index c5ed391..0000000 Binary files a/authentication/database-migration/data.db and /dev/null differ diff --git a/authentication/database-migration/db_migration.py b/authentication/database-migration/db_migration.py deleted file mode 100644 index 142a165..0000000 --- a/authentication/database-migration/db_migration.py +++ /dev/null @@ -1,38 +0,0 @@ -print('RUNNING!') - -import sqlite3 -import os -import psycopg - -print(os.getcwd()) -print(os.listdir()) - -with open('data.db', 'rb') as f: - data = f.read() - print(f'[DEBUG] Begin SQLite database') - print(data) - print(f'[DEBUG] End SQLite database') - - -conn = psycopg.connect( - host = 'db', - port = 5432, - dbname = os.getenv('POSTGRES_DB'), - user = os.getenv('POSTGRES_USER'), - password = os.getenv('POSTGRES_PASSWORD') -) - -cursor = conn.cursor() - -with sqlite3.connect('data.db') as sqlite3_conn: - sqlite_cursor = sqlite3_conn.cursor() - sqlite_cursor.execute('SELECT COUNT(*) FROM data') - number_of_users = sqlite_cursor.fetchone()[0] - for user in range(1, number_of_users + 1): - print(f'Migrating user {user} ...') - sqlite_cursor.execute('SELECT (id, email, remail, phone, password) FROM data WHERE id = ?', (user,)) - cursor.execute('INSERT INTO users (id, email, remail, phone, password) VALUES (%s, %s, %s, %s, %s)', tuple(sqlite_cursor.fetchone())) - cursor.execute('SELECT setval(pg_get_serial_sequence(\'users\', \'id\'), (SELECT MAX(id) FROM users), true)') - sqlite_cursor.close() - -print('[INFO] Migration completed') \ No newline at end of file diff --git a/authentication/database-migration/migration.py b/authentication/database-migration/migration.py deleted file mode 100644 index 8b13789..0000000 --- a/authentication/database-migration/migration.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/authentication/database-migration/requirements.txt b/authentication/database-migration/requirements.txt deleted file mode 100644 index 0308453..0000000 --- a/authentication/database-migration/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -psycopg \ No newline at end of file diff --git a/authentication/docker-compose.migration.yml b/authentication/docker-compose.migration.yml deleted file mode 100644 index 60c2eab..0000000 --- a/authentication/docker-compose.migration.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: "3.9" - -services: - db: - image: postgres:15 - environment: - - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} - env_file: - - .env - volumes: - - /srv/data/db/services/authentication:/var/lib/postgresql/data - migration: - build: database-migration - image: python:3.11-slim - environment: - - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} - env_file: - - .env - depends_on: - - db - command: python3 db_migration_test1.py \ No newline at end of file diff --git a/authentication/docker-compose.yml b/authentication/docker-compose.yml deleted file mode 100644 index 3dc542b..0000000 --- a/authentication/docker-compose.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: "3.9" - -services: - app: - build: . - image: python:3.11-slim - working_dir: /app - volumes: - - .:/app - command: python3 main.py - ports: - - "1234:1234" - depends_on: - - db - environment: - - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} - env_file: - - .env - - db: - image: postgres:15 - environment: - - DB_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB} - env_file: - - .env - volumes: - - /srv/data/db/services/authentication:/var/lib/postgresql/data \ No newline at end of file diff --git a/authentication/main.py b/authentication/main.py deleted file mode 100644 index e9da286..0000000 --- a/authentication/main.py +++ /dev/null @@ -1,85 +0,0 @@ -from fastapi import FastAPI, Depends -from psycopg_pool import AsyncConnectionPool -import uvicorn -import os -from pydantic import BaseModel - -class Item(BaseModel): - name: str - description: str - reporter: str - priority: int - is_stupid: bool - -app = FastAPI() -pool: AsyncConnectionPool - - -@app.on_event('startup') -async def on_startup(): - global pool - pool = AsyncConnectionPool( - os.getenv('DB_URL'), - min_size=5, - max_size=40 - ) - await pool.open() - print('[INFO] Started connection pool') - - async with pool.connection() as conn: - async with conn.cursor() as cursor: - await cursor.execute('CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, email VARCHAR(64), remail VARCHAR(64), phone VARCHAR(16), password VARCHAR(128))') - print('[INFO] Database initialized') - await conn.commit() - -@app.on_event('shutdown') -async def on_shutdown(): - await pool.close() - print('[INFO] Closed connection pool') - -async def get_conn(): - async with pool.connection() as conn: - yield conn - -@app.get('/') -def read_root(): - return { - 'message': 'microservice is running' - } - -@app.post('/item') -async def create_item(item: Item, conn = Depends(get_conn)): - async with conn.cursor() as cursor: - await cursor.execute('INSERT INTO items (name, description, reporter, priority, is_stupid) VALUES (%s, %s, %s, %s, %s) RETURNING *', (item.name, item.description, item.reporter, item.priority, item.is_stupid)) - i = await cursor.fetchone() - return {'id': i[0], 'description' : i[1], 'reporter': i[2], 'priority': i[3], 'is_stupid': i[4]} - -@app.get('/item/{item_id}') -async def read_item(item_id, conn = Depends(get_conn)): - async with conn.cursor() as cursor: - await cursor.execute('SELECT * FROM items WHERE id = %s', (item_id,)) - i = await cursor.fetchone() - return {'id': i[0], 'name' : i[1], 'description': i[2], 'reporter': i[3], 'priority': i[4], 'is_stupid': i[5]} - -@app.get('/items') -async def read_item(conn = Depends(get_conn)): - async with conn.cursor() as cursor: - await cursor.execute('SELECT * FROM items') - items = await cursor.fetchall() - return [{'id': i[0], 'description' : i[1], 'reporter': i[2], 'priority': i[3], 'is_stupid': i[4]} for i in items] - -@app.get('/datadir') -async def get_datadir(conn = Depends(get_conn)): - async with conn.cursor() as cursor: - await cursor.execute('SHOW data_directory') - return {'res': await cursor.fetchall()} - -if __name__ == '__main__': - uvicorn.run( - 'main:app', - host = '0.0.0.0', - port = 1234, - reload = True, - reload_dirs = ['/app'], - server_header = False - ) \ No newline at end of file diff --git a/authentication/requirements.txt b/authentication/requirements.txt deleted file mode 100644 index c62b07c..0000000 --- a/authentication/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -fastapi -psycopg_pool -uvicorn -psycopg[binary] -pydantic \ No newline at end of file