From 6a49957eecc0333507323752884c8652011aefc5 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Thu, 9 Nov 2023 22:56:31 -0300 Subject: [PATCH] Remove unused files and update run.sh --- auth-domain/user-manager/entrypoint.sh | 11 -- auth-domain/user-manager/src/api/crud.py | 34 ----- auth-domain/user-manager/src/api/models.py | 116 ------------------ browser-domain/Dockerfile | 12 -- flights-domain/.env.dev.example | 1 + flights-domain/.env.prod.example | 3 +- gateway/entrypoint.sh | 3 - run.sh | 4 +- .../subscription-manager/entrypoint.sh | 11 -- 9 files changed, 4 insertions(+), 191 deletions(-) delete mode 100755 auth-domain/user-manager/entrypoint.sh delete mode 100644 auth-domain/user-manager/src/api/crud.py delete mode 100644 auth-domain/user-manager/src/api/models.py delete mode 100644 browser-domain/Dockerfile delete mode 100755 gateway/entrypoint.sh delete mode 100755 subscription-domain/subscription-manager/entrypoint.sh diff --git a/auth-domain/user-manager/entrypoint.sh b/auth-domain/user-manager/entrypoint.sh deleted file mode 100755 index 4a8fd57..0000000 --- a/auth-domain/user-manager/entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -echo "Waiting for postgres..." - -while ! nc -z usermanager-db 5432; do - sleep 0.1 -done - -echo "PostgreSQL started" - -python manage.py run -h 0.0.0.0 diff --git a/auth-domain/user-manager/src/api/crud.py b/auth-domain/user-manager/src/api/crud.py deleted file mode 100644 index ddc831d..0000000 --- a/auth-domain/user-manager/src/api/crud.py +++ /dev/null @@ -1,34 +0,0 @@ -from src import db -from src.api.models import User - - -def get_all_users(): - return User.query.all() - - -def get_user_by_id(user_id): - return User.query.filter_by(id=user_id).first() - - -def get_user_by_email(email): - return User.query.filter_by(email=email).first() - - -def add_user(username, email, password): - user = User(username=username, email=email, password=password) - db.session.add(user) - db.session.commit() - return user - - -def update_user(user, username, email): - user.username = username - user.email = email - db.session.commit() - return user - - -def delete_user(user): - db.session.delete(user) - db.session.commit() - return user diff --git a/auth-domain/user-manager/src/api/models.py b/auth-domain/user-manager/src/api/models.py deleted file mode 100644 index d44b126..0000000 --- a/auth-domain/user-manager/src/api/models.py +++ /dev/null @@ -1,116 +0,0 @@ -import datetime - -import jwt -from flask import current_app -from flask_restx import fields -from sqlalchemy.sql import func - -from src import bcrypt, db - - -class User(db.Model): - __tablename__ = "users" - - id = db.Column(db.Integer, primary_key=True, autoincrement=True) - username = db.Column(db.String(128), nullable=False) - email = db.Column(db.String(128), nullable=False) - password = db.Column(db.String(255), nullable=False) - active = db.Column(db.Boolean(), default=True, nullable=False) - created_date = db.Column(db.DateTime, default=func.now(), nullable=False) - - def __init__(self, username, email, password): - self.username = username - self.email = email - self.password = bcrypt.generate_password_hash( - password, current_app.config.get("BCRYPT_LOG_ROUNDS") - ).decode() - - @staticmethod - def encode_token(user_id, token_type): - print(f"encode_token(user_id={user_id}, token_type={token_type}):") - if token_type == "access": - seconds = current_app.config.get("ACCESS_TOKEN_EXPIRATION") - else: - seconds = current_app.config.get("REFRESH_TOKEN_EXPIRATION") - - payload = { - "exp": datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds), - "iat": datetime.datetime.utcnow(), - "sub": user_id, - } - return jwt.encode( - payload, current_app.config.get("SECRET_KEY"), algorithm="HS256" - ) - - @staticmethod - def decode_token(token): - decoded = jwt.decode( - token, current_app.config.get("SECRET_KEY"), algorithms=["HS256"] - ) - return decoded["sub"] - - @classmethod - def get_api_user_model(cls, namespace): - return namespace.model( - "User", - { - "id": fields.Integer(readOnly=True), - "username": fields.String(required=True), - "email": fields.String(required=True), - "created_date": fields.DateTime, - }, - ) - - @classmethod - def get_api_user_post_model(cls, namespace): - return namespace.inherit( - "User Post", - cls.get_api_user_model(namespace), - { - "password": fields.String(required=False), - }, - ) - - @classmethod - def get_api_auth_user_model(cls, namespace): - return namespace.model( - "User", - { - "username": fields.String(required=True), - "email": fields.String(required=True), - }, - ) - - @classmethod - def get_api_auth_full_user_model(cls, namespace): - return namespace.clone( - "User Full", - cls.get_api_auth_user_model(namespace), - { - "password": fields.String(required=True), - }, - ) - - @classmethod - def get_api_auth_login_model(cls, namespace): - return namespace.model( - "User", - { - "password": fields.String(required=True), - "email": fields.String(required=True), - }, - ) - - @classmethod - def get_api_auth_refresh_model(cls, namespace): - return namespace.model( - "Refresh", {"refresh_token": fields.String(required=True)} - ) - - @classmethod - def get_api_auth_tokens_model(cls, namespace): - return namespace.clone( - "Access and Refresh Token", - cls.get_api_auth_refresh_model(namespace), - {"access_token": fields.String(required=True)}, - ) diff --git a/browser-domain/Dockerfile b/browser-domain/Dockerfile deleted file mode 100644 index 12fc50c..0000000 --- a/browser-domain/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM node:17.9.1 AS app -WORKDIR /app -COPY . . -RUN npm install && npm run build - -FROM nginx:alpine -WORKDIR /usr/share/nginx/html -RUN rm -rf ./* -COPY --from=app /app/build . -COPY nginx/default.conf /etc/nginx/conf.d/default.conf -EXPOSE 80 -ENTRYPOINT ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/flights-domain/.env.dev.example b/flights-domain/.env.dev.example index 7dd898d..e65205d 100644 --- a/flights-domain/.env.dev.example +++ b/flights-domain/.env.dev.example @@ -2,3 +2,4 @@ POSTGRES_USER=user POSTGRES_PASS=password POSTGRES_DB=api_dev APP_SETTINGS=src.config.DevelopmentConfig +ENVIRONMENT=dev \ No newline at end of file diff --git a/flights-domain/.env.prod.example b/flights-domain/.env.prod.example index 27670b4..c3eed66 100644 --- a/flights-domain/.env.prod.example +++ b/flights-domain/.env.prod.example @@ -1,4 +1,5 @@ POSTGRES_USER=user POSTGRES_PASS=password POSTGRES_DB=api_prod -APP_SETTINGS=src.config.ProductionConfig \ No newline at end of file +APP_SETTINGS=src.config.ProductionConfig +ENVIRONMENT=prod \ No newline at end of file diff --git a/gateway/entrypoint.sh b/gateway/entrypoint.sh deleted file mode 100755 index 3f1bd2d..0000000 --- a/gateway/entrypoint.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -python src/api/main.py run -h 0.0.0.0 diff --git a/run.sh b/run.sh index 4ee77c0..447b3c3 100755 --- a/run.sh +++ b/run.sh @@ -64,10 +64,8 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then if [ -n "$tests" ]; then docker build $USER_MANAGER -f $USER_MANAGER/Dockerfile.test -t $USER/user-manager:test export API_IMAGE=$USER/user-manager:test - docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.prod down + docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev down docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev up --abort-on-container-exit - docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.prod exec usermanager-api-dev python manage.py recreate_db - docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.prod exec usermanager-api-dev python manage.py seed_db else export API_IMAGE=$USER/user-manager:prod docker compose -f auth-domain/docker-compose.yml --env-file auth-domain/.env.prod down diff --git a/subscription-domain/subscription-manager/entrypoint.sh b/subscription-domain/subscription-manager/entrypoint.sh deleted file mode 100755 index 6c6f67f..0000000 --- a/subscription-domain/subscription-manager/entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -echo "Waiting for postgres..." - -while ! nc -z api-db 5432; do - sleep 0.1 -done - -echo "PostgreSQL started" - -python src/api/main.py run -h 0.0.0.0