Remove unused files and update run.sh
This commit is contained in:
parent
9ed84540f6
commit
6a49957eec
|
@ -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
|
|
@ -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
|
|
@ -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)},
|
||||
)
|
|
@ -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;"]
|
|
@ -2,3 +2,4 @@ POSTGRES_USER=user
|
|||
POSTGRES_PASS=password
|
||||
POSTGRES_DB=api_dev
|
||||
APP_SETTINGS=src.config.DevelopmentConfig
|
||||
ENVIRONMENT=dev
|
|
@ -1,4 +1,5 @@
|
|||
POSTGRES_USER=user
|
||||
POSTGRES_PASS=password
|
||||
POSTGRES_DB=api_prod
|
||||
APP_SETTINGS=src.config.ProductionConfig
|
||||
APP_SETTINGS=src.config.ProductionConfig
|
||||
ENVIRONMENT=prod
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
python src/api/main.py run -h 0.0.0.0
|
4
run.sh
4
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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue