diff --git a/API_ROUTER/app/common/config.py b/API_ROUTER/app/common/config.py index 98e4af68..cf1d8d40 100644 --- a/API_ROUTER/app/common/config.py +++ b/API_ROUTER/app/common/config.py @@ -1,10 +1,11 @@ +import json +import logging.config import os from functools import lru_cache from typing import Union from pydantic import BaseSettings, SecretStr, PostgresDsn, validator - base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) print(f"base_dir :: {base_dir}") @@ -79,11 +80,11 @@ class LocalSettings(Settings): DB_ECHO: bool = True RELOAD: bool = False - DB_INFO = PGInfo( - HOST="192.168.100.126", PORT="25432", USER="dpmanager", PASS="hello.dp12#$", BASE="dataportal", SCHEMA="sitemng" - ) + # DB_INFO = PGInfo( + # HOST="192.168.100.126", PORT="25432", USER="dpmanager", PASS="hello.dp12#$", BASE="dataportal", SCHEMA="sitemng" + # ) - # DB_INFO: TiberoInfo = TiberoInfo(HOST="192.168.101.164", PORT="8629", USER="dhub", PASS="dhub1234", BASE="tibero") + DB_INFO: TiberoInfo = TiberoInfo(HOST="192.168.101.164", PORT="8629", USER="dhub", PASS="dhub1234", BASE="tibero") class TestSettings(LocalSettings): @@ -101,6 +102,6 @@ def get_settings(): settings = get_settings() -# with open(os.path.join(base_dir, "logging.json")) as f: -# log_config = json.load(f) -# logging.config.dictConfig(log_config) +with open(os.path.join(base_dir, "logging.json")) as f: + log_config = json.load(f) + logging.config.dictConfig(log_config) diff --git a/API_ROUTER/app/common/const.py b/API_ROUTER/app/common/const.py index dc9b4c89..45ee8d1d 100644 --- a/API_ROUTER/app/common/const.py +++ b/API_ROUTER/app/common/const.py @@ -5,12 +5,12 @@ class RouteTable: - api_list_table = "tb_api_info" - api_server_info_table = "tb_api_server_info" - main_key = "ctgry" - join_key = "nm" + api_list_table = "api_item_bas" + api_server_info_table = "api_item_server_dtl" + main_key = "srvr_nm" + join_key = "srvr_nm" url_key = "route_url" - method_key = "meth" + method_key = "mthd" @staticmethod def get_query_data(route_path, method) -> dict: diff --git a/API_ROUTER/app/database/conn.py b/API_ROUTER/app/database/conn.py index ce8ece65..2833e3f5 100644 --- a/API_ROUTER/app/database/conn.py +++ b/API_ROUTER/app/database/conn.py @@ -1,8 +1,8 @@ -from sqlalchemy.orm import declarative_base +from sqlalchemy.ext.automap import automap_base from app.common.config import settings -Base = declarative_base() +Base = automap_base() db = None if settings.DB_INFO.type == "tibero": from libs.database.tibero import TiberoConnector diff --git a/API_ROUTER/app/routes/index.py b/API_ROUTER/app/routes/index.py index 55b5110d..8976dfeb 100644 --- a/API_ROUTER/app/routes/index.py +++ b/API_ROUTER/app/routes/index.py @@ -18,7 +18,7 @@ @router.get("/route/common/me") async def me(request: Request): - return {"result": 1, "errorMesage": "", "data": request.scope["client"][0]} + return {"result": 1, "errorMessage": "", "data": request.scope["client"][0]} @router.api_route("{route_path:path}", methods=["GET", "POST"]) diff --git a/API_ROUTER/gunicorn.conf.py b/API_ROUTER/gunicorn.conf.py index 3b1d2cdc..04219261 100644 --- a/API_ROUTER/gunicorn.conf.py +++ b/API_ROUTER/gunicorn.conf.py @@ -144,10 +144,10 @@ # # A string of "debug", "info", "warning", "error", "critical" # -logfile = "./router.log" -errorlog = "./router-error.log" +logfile = "./log/router.log" +errorlog = "./log/router-error.log" loglevel = "info" -accesslog = "./router.log" +accesslog = "./log/router.log" access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' # diff --git a/API_ROUTER/logging.json b/API_ROUTER/logging.json index 27da2456..2723b6ff 100644 --- a/API_ROUTER/logging.json +++ b/API_ROUTER/logging.json @@ -11,12 +11,31 @@ "class": "logging.StreamHandler", "level": "DEBUG", "formatter": "default" + }, + "file": { + "class": "logging.handlers.RotatingFileHandler", + "level": "DEBUG", + "formatter": "default", + "filename": "./log/router.log", + "mode": "a", + "maxBytes": 20000000, + "backupCount": 10 } }, "loggers": { "root": { "level": "DEBUG", - "handlers": ["console"], + "handlers": ["console", "file"], + "propagate": false + }, + "uvicorn.access": { + "level": "INFO", + "handlers": ["console", "file"], + "propagate": false + }, + "sqlalchemy.engine": { + "level": "INFO", + "handlers": ["console", "file"], "propagate": false } } diff --git a/API_ROUTER/requirements.txt b/API_ROUTER/requirements.txt index c06e9fe4..8c109c7b 100644 --- a/API_ROUTER/requirements.txt +++ b/API_ROUTER/requirements.txt @@ -1,22 +1,37 @@ aiohttp==3.8.4 aiosignal==1.3.1 anyio==3.6.2 +APScheduler==3.10.1 async-timeout==4.0.2 attrs==23.1.0 +bcrypt==4.0.1 +certifi==2022.12.7 +cffi==1.15.1 charset-normalizer==3.1.0 click==8.1.3 +cryptography==40.0.2 +elastic-transport==8.4.0 +elasticsearch==8.7.0 fastapi==0.95.1 frozenlist==1.3.3 gunicorn==20.1.0 h11==0.14.0 idna==3.4 multidict==6.0.4 -psycopg2==2.9.6 +passlib==1.7.4 +psycopg2-binary==2.9.6 +pycparser==2.21 pydantic==1.10.7 +PyJWT==2.7.0 +pyodbc==4.0.39 python-dotenv==1.0.0 +pytz==2023.3 +six==1.16.0 sniffio==1.3.0 SQLAlchemy==2.0.9 starlette==0.26.1 typing_extensions==4.5.0 +tzlocal==5.0.1 +urllib3==1.26.15 uvicorn==0.21.1 yarl==1.8.2 diff --git a/API_SERVICE/common_service/common/config.py b/API_SERVICE/common_service/common/config.py index d6a8e1db..b2721049 100644 --- a/API_SERVICE/common_service/common/config.py +++ b/API_SERVICE/common_service/common/config.py @@ -78,14 +78,14 @@ class LocalSettings(Settings): DB_ECHO: bool = True RELOAD: bool = False - # DB_INFO = PGInfo( - # HOST="192.168.100.126", PORT="25432", USER="dpsi", PASS="hello.sitemng12#$", BASE="ktportal", SCHEMA="sitemng" - # ) - - DB_INFO: TiberoInfo = TiberoInfo( - HOST="192.168.101.164", PORT="8629", USER="dhub", PASS="dhub1234", BASE="tibero", SCHEMA="DHUB" + DB_INFO = PGInfo( + HOST="192.168.100.126", PORT="25432", USER="dpsi", PASS="hello.sitemng12#$", BASE="ktportal", SCHEMA="sitemng" ) + # DB_INFO: TiberoInfo = TiberoInfo( + # HOST="192.168.101.164", PORT="8629", USER="dhub", PASS="dhub1234", BASE="tibero", SCHEMA="DHUB" + # ) + class TestSettings(LocalSettings): ... diff --git a/API_SERVICE/common_service/common/const.py b/API_SERVICE/common_service/common/const.py index b96be432..a4e32d17 100644 --- a/API_SERVICE/common_service/common/const.py +++ b/API_SERVICE/common_service/common/const.py @@ -1,4 +1,5 @@ NOT_ALLOWED_TABLES = ["USR_MGMT"] +INSERT_NOT_ALLOWED_TABLES = [""] SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" ALGORITHM = "HS256" EXPIRE_DELTA = 1 diff --git a/API_SERVICE/common_service/database/conn.py b/API_SERVICE/common_service/database/conn.py index 44013bcc..2833e3f5 100644 --- a/API_SERVICE/common_service/database/conn.py +++ b/API_SERVICE/common_service/database/conn.py @@ -1,29 +1,14 @@ -from fastapi import FastAPI -from sqlalchemy import MetaData from sqlalchemy.ext.automap import automap_base -from sqlalchemy.orm import declarative_base -from common_service.common.config import settings -from libs.database.tibero import TiberoConnector -from libs.database.orm import SQLAlchemyConnector +from app.common.config import settings +Base = automap_base() +db = None +if settings.DB_INFO.type == "tibero": + from libs.database.tibero import TiberoConnector -# TODO: SQLAlchemy version 수정필요 -class SQLAlchemyForCommon(SQLAlchemyConnector): - def __init__(self, app: FastAPI = None, **kwargs): - self._table_dict = None - if app is not None: - self.init_app(app=app, **kwargs) + db = TiberoConnector() +elif settings.DB_INFO.type == "orm": + from libs.database.orm import SQLAlchemyConnector - metadata = MetaData() - for schema in kwargs.get("PG_SCHEMA").split(","): - metadata.reflect(bind=self.engine, views=True, schema=schema) - - self._Base = automap_base(metadata=metadata) - self._Base.prepare() - - # self._table_dict = dict(metadata.tables) - - -Base = declarative_base() -db = SQLAlchemyForCommon(Base) if settings.DB_INFO.type != "tibero" else TiberoConnector() + db = SQLAlchemyConnector(Base) diff --git a/API_SERVICE/common_service/gunicorn.conf.py b/API_SERVICE/common_service/gunicorn.conf.py index 8d3a8b45..3340c025 100644 --- a/API_SERVICE/common_service/gunicorn.conf.py +++ b/API_SERVICE/common_service/gunicorn.conf.py @@ -144,10 +144,10 @@ # # A string of "debug", "info", "warning", "error", "critical" # -logfile = "./log/common.log" +logfile = "./log/commom.log" errorlog = "./log/common-error.log" loglevel = "info" -accesslog = "./log/common.log" +accesslog = "./log/commom.log" access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' # diff --git a/API_SERVICE/common_service/requirements.txt b/API_SERVICE/common_service/requirements.txt index 2077cf10..8c109c7b 100644 --- a/API_SERVICE/common_service/requirements.txt +++ b/API_SERVICE/common_service/requirements.txt @@ -1,8 +1,10 @@ aiohttp==3.8.4 aiosignal==1.3.1 anyio==3.6.2 +APScheduler==3.10.1 async-timeout==4.0.2 attrs==23.1.0 +bcrypt==4.0.1 certifi==2022.12.7 cffi==1.15.1 charset-normalizer==3.1.0 @@ -16,17 +18,20 @@ gunicorn==20.1.0 h11==0.14.0 idna==3.4 multidict==6.0.4 -psycopg2==2.9.6 +passlib==1.7.4 psycopg2-binary==2.9.6 pycparser==2.21 pydantic==1.10.7 PyJWT==2.7.0 pyodbc==4.0.39 python-dotenv==1.0.0 +pytz==2023.3 +six==1.16.0 sniffio==1.3.0 SQLAlchemy==2.0.9 starlette==0.26.1 typing_extensions==4.5.0 +tzlocal==5.0.1 urllib3==1.26.15 uvicorn==0.21.1 yarl==1.8.2 diff --git a/API_SERVICE/common_service/routes/v1/execute.py b/API_SERVICE/common_service/routes/v1/execute.py index 9e5ac91a..89bcdd4d 100644 --- a/API_SERVICE/common_service/routes/v1/execute.py +++ b/API_SERVICE/common_service/routes/v1/execute.py @@ -1,16 +1,15 @@ import logging from typing import Dict, List, Optional +import jwt from fastapi import APIRouter, Depends, Request from pydantic import BaseModel from starlette.responses import JSONResponse -from common_service.common.const import ALGORITHM, NOT_ALLOWED_TABLES, SECRET_KEY +from common_service.common.const import ALGORITHM, NOT_ALLOWED_TABLES, SECRET_KEY from common_service.database.conn import db -import jwt from libs.database.connector import Executor - logger = logging.getLogger() @@ -28,11 +27,13 @@ class CommonExecute(BaseModel): async def common_execute(request: Request, params: List[CommonExecute], session: Executor = Depends(db.get_db)): try: for param in params: - if param.table_nm in NOT_ALLOWED_TABLES: + table_nm = param.table_nm + method = param.method + if table_nm in NOT_ALLOWED_TABLES: roleidx = get_roleidx_from_token(request) if roleidx != "0": return JSONResponse(content={"result": 0, "errorMessage": "NotAllowedTable"}) - elif param.table_nm == "USR_MGMT" and param.method == "INSERT": + elif table_nm == "USR_MGMT" and method == "INSERT": return JSONResponse(content={"result": 0, "errorMessage": "use register api"}) session.execute(**param.dict()) return JSONResponse(content={"result": 1, "errorMessage": ""}, status_code=200) diff --git a/API_SERVICE/common_service/routes/v1/select.py b/API_SERVICE/common_service/routes/v1/select.py index b73ede26..ce909995 100644 --- a/API_SERVICE/common_service/routes/v1/select.py +++ b/API_SERVICE/common_service/routes/v1/select.py @@ -51,27 +51,6 @@ class CommonSelect(BaseModel): @router.post("/common-select") async def common_select(params: CommonSelect, session: Executor = Depends(db.get_db)): - """ - { - "table_nm":"banr_adm_bas", - "where_info":[ - { - "key":"banr_div", - "value":"T", - "table_nm":"banr_adm_bas", - "compare_op":"Equal","op":"" - }, - { - "key":"pstng_fns_date", - "compare_op":">=", - "value":"2023-04-12 00:00:00", - "table_nm":"banr_adm_bas", - "op":"AND" - } - ] - } - {"table_nm":"vw_srhwd_find_tmscnt_sum","order_info":{"key":"find_tmscnt","value":"DESC","table_nm":"vw_srhwd_find_tmscnt_sum","order":"DESC"},"page_info":{"per_page":10,"cur_page":1}} - """ try: rows = session.query(**params.dict()).all() return JSONResponse( diff --git a/API_SERVICE/login_service/database/conn.py b/API_SERVICE/login_service/database/conn.py index 67e8ee34..2833e3f5 100644 --- a/API_SERVICE/login_service/database/conn.py +++ b/API_SERVICE/login_service/database/conn.py @@ -1,8 +1,14 @@ -from sqlalchemy.orm import declarative_base +from sqlalchemy.ext.automap import automap_base -from login_service.common.config import settings -from libs.database.tibero import TiberoConnector -from libs.database.orm import SQLAlchemyConnector +from app.common.config import settings -Base = declarative_base() -db = SQLAlchemyConnector(Base) if settings.DB_INFO.type != "tibero" else TiberoConnector() +Base = automap_base() +db = None +if settings.DB_INFO.type == "tibero": + from libs.database.tibero import TiberoConnector + + db = TiberoConnector() +elif settings.DB_INFO.type == "orm": + from libs.database.orm import SQLAlchemyConnector + + db = SQLAlchemyConnector(Base) diff --git a/API_SERVICE/login_service/requirements.txt b/API_SERVICE/login_service/requirements.txt index 75074285..8c109c7b 100644 --- a/API_SERVICE/login_service/requirements.txt +++ b/API_SERVICE/login_service/requirements.txt @@ -1,6 +1,7 @@ aiohttp==3.8.4 aiosignal==1.3.1 anyio==3.6.2 +APScheduler==3.10.1 async-timeout==4.0.2 attrs==23.1.0 bcrypt==4.0.1 @@ -17,17 +18,20 @@ gunicorn==20.1.0 h11==0.14.0 idna==3.4 multidict==6.0.4 -psycopg2==2.9.6 +passlib==1.7.4 psycopg2-binary==2.9.6 pycparser==2.21 pydantic==1.10.7 PyJWT==2.7.0 pyodbc==4.0.39 python-dotenv==1.0.0 +pytz==2023.3 +six==1.16.0 sniffio==1.3.0 SQLAlchemy==2.0.9 starlette==0.26.1 typing_extensions==4.5.0 +tzlocal==5.0.1 urllib3==1.26.15 uvicorn==0.21.1 yarl==1.8.2