internal 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of internal might be problematic. Click here for more details.
- {internal-0.1.0 → internal-0.1.2}/PKG-INFO +2 -3
- {internal-0.1.0 → internal-0.1.2}/pyproject.toml +2 -3
- {internal-0.1.0 → internal-0.1.2}/src/internal/base_factory.py +30 -4
- internal-0.1.2/src/internal/exception/base_exception.py +11 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/model/base_model.py +3 -3
- {internal-0.1.0 → internal-0.1.2}/src/internal/utils.py +4 -1
- internal-0.1.0/src/internal/exception/base_exception.py +0 -9
- {internal-0.1.0 → internal-0.1.2}/README.md +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/base_config.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/const.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/database.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/exception/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/ext/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/ext/amazon/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/ext/amazon/aws/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/ext/amazon/aws/const.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/http/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/http/requests.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/model/__init__.py +0 -0
- {internal-0.1.0 → internal-0.1.2}/src/internal/model/operate.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: internal
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Ray
|
|
6
|
-
Author-email: ray@
|
|
6
|
+
Author-email: ray@cruisys.com
|
|
7
7
|
Requires-Python: >=3.11,<4.0
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -12,7 +12,6 @@ Requires-Dist: arrow (>=1.3.0,<2.0.0)
|
|
|
12
12
|
Requires-Dist: beanie (>=1.24.0,<2.0.0)
|
|
13
13
|
Requires-Dist: fastapi (>=0.109.0,<0.110.0)
|
|
14
14
|
Requires-Dist: httpx (>=0.26.0,<0.27.0)
|
|
15
|
-
Requires-Dist: motor (>=3.3.2,<4.0.0)
|
|
16
15
|
Requires-Dist: pydantic-settings (>=2.1.0,<3.0.0)
|
|
17
16
|
Requires-Dist: watchtower (>=3.0.1,<4.0.0)
|
|
18
17
|
Description-Content-Type: text/markdown
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "internal"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
4
|
description = ""
|
|
5
|
-
authors = ["Ray <ray@
|
|
5
|
+
authors = ["Ray <ray@cruisys.com>"]
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
packages = [{include = "internal", from = "src"}]
|
|
8
8
|
|
|
@@ -12,7 +12,6 @@ fastapi = "^0.109.0"
|
|
|
12
12
|
arrow = "^1.3.0"
|
|
13
13
|
pydantic-settings = "^2.1.0"
|
|
14
14
|
watchtower = "^3.0.1"
|
|
15
|
-
motor = "^3.3.2"
|
|
16
15
|
httpx = "^0.26.0"
|
|
17
16
|
beanie = "^1.24.0"
|
|
18
17
|
|
|
@@ -6,13 +6,16 @@ from abc import ABCMeta, abstractmethod
|
|
|
6
6
|
|
|
7
7
|
import dotenv
|
|
8
8
|
import watchtower
|
|
9
|
-
from fastapi import FastAPI
|
|
9
|
+
from fastapi import FastAPI, status
|
|
10
10
|
from fastapi.middleware.cors import CORSMiddleware
|
|
11
11
|
from fastapi.responses import JSONResponse
|
|
12
|
+
from starlette.requests import Request
|
|
13
|
+
from beanie import init_beanie
|
|
12
14
|
|
|
13
15
|
from . import database
|
|
14
16
|
from .base_config import get_app_config
|
|
15
17
|
from .const import LOG_FMT, LOG_FMT_NO_DT, LOG_DT_FMT, DEFAULT_LOGGER_NAME
|
|
18
|
+
from .exception.base_exception import InternalBaseException
|
|
16
19
|
from .utils import update_dict_with_cast
|
|
17
20
|
from .ext.amazon import aws
|
|
18
21
|
|
|
@@ -24,7 +27,13 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
24
27
|
@abstractmethod
|
|
25
28
|
def init_modules(self, app):
|
|
26
29
|
"""
|
|
27
|
-
Each factory should define what modules it
|
|
30
|
+
Each factory should define what modules it wants.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
async def get_document_model_list(self) -> list:
|
|
35
|
+
"""
|
|
36
|
+
Each factory should define what model it wants.
|
|
28
37
|
"""
|
|
29
38
|
|
|
30
39
|
def create_app(self, title=DEFAULT_APP_NAME) -> FastAPI:
|
|
@@ -50,6 +59,8 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
50
59
|
@app.on_event("startup")
|
|
51
60
|
async def startup_db_client():
|
|
52
61
|
await mongodb.connect()
|
|
62
|
+
document_model_list = await self.get_document_model_list()
|
|
63
|
+
await init_beanie(database=app.state.db.db_name, document_models=document_model_list)
|
|
53
64
|
app.state.logger.info("Database connected")
|
|
54
65
|
|
|
55
66
|
@app.on_event("shutdown")
|
|
@@ -57,11 +68,27 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
57
68
|
await mongodb.close()
|
|
58
69
|
app.state.logger.info("Database disconnected")
|
|
59
70
|
|
|
60
|
-
app.db = mongodb
|
|
71
|
+
app.state.db = mongodb
|
|
61
72
|
|
|
62
73
|
self.__init_modules(app)
|
|
63
74
|
self.__init_builtin_api(app)
|
|
64
75
|
|
|
76
|
+
@app.exception_handler(InternalBaseException)
|
|
77
|
+
async def http_exception_handler(request: Request, exc: InternalBaseException):
|
|
78
|
+
return JSONResponse(
|
|
79
|
+
status_code=exc.status_code,
|
|
80
|
+
content=exc.detail
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
@app.exception_handler(Exception)
|
|
84
|
+
async def http_exception_handler(request: Request, exc: Exception):
|
|
85
|
+
app.state.logger.warn(f"Exception, request:{request.__dict__}, exc:{exc}")
|
|
86
|
+
detail = {"code": status.HTTP_500_INTERNAL_SERVER_ERROR, "message": "Internal server error"}
|
|
87
|
+
return JSONResponse(
|
|
88
|
+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
89
|
+
content=detail
|
|
90
|
+
)
|
|
91
|
+
|
|
65
92
|
return app
|
|
66
93
|
|
|
67
94
|
def __load_local_config(self):
|
|
@@ -118,7 +145,6 @@ class BaseFactory(metaclass=ABCMeta):
|
|
|
118
145
|
boto3_client=logs_client, create_log_group=False)
|
|
119
146
|
watchtower_handler.setFormatter(logging.Formatter(fmt=LOG_FMT_NO_DT, datefmt=LOG_DT_FMT))
|
|
120
147
|
app.state.logger.addHandler(watchtower_handler)
|
|
121
|
-
logging.getLogger('sqlalchemy').addHandler(watchtower_handler)
|
|
122
148
|
|
|
123
149
|
def __init_builtin_api(self, app):
|
|
124
150
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from fastapi import HTTPException
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class InternalBaseException(HTTPException):
|
|
5
|
+
def __init__(self, status_code: int = None, code: str = "SUCCESS", message: str = "success", **kwargs):
|
|
6
|
+
detail = {
|
|
7
|
+
"code": code,
|
|
8
|
+
"message": message,
|
|
9
|
+
"data": kwargs,
|
|
10
|
+
}
|
|
11
|
+
super().__init__(status_code=status_code, detail=detail)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
|
+
from beanie import Document
|
|
3
|
+
from pydantic import Field
|
|
2
4
|
|
|
3
|
-
from pydantic import BaseModel, Field
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
class InternalBaseModel(BaseModel):
|
|
6
|
+
class InternalBaseModel(Document):
|
|
7
7
|
create_time: datetime = Field(default_factory=datetime.utcnow)
|
|
8
8
|
update_time: datetime = Field(default_factory=datetime.utcnow)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import hashlib
|
|
3
|
+
import json
|
|
3
4
|
|
|
4
5
|
import arrow
|
|
5
6
|
|
|
@@ -41,4 +42,6 @@ def export_time_format(date, fmt=ARR_EXPORT_DATETIME_FMT):
|
|
|
41
42
|
def update_dict_with_cast(curr_settings: BaseConfig, new_conf: dict):
|
|
42
43
|
for key, value in new_conf.items():
|
|
43
44
|
if hasattr(curr_settings, key):
|
|
44
|
-
|
|
45
|
+
key_type = type(getattr(curr_settings, key))
|
|
46
|
+
cast_func = key_type if key_type in (str, int) else json.loads
|
|
47
|
+
setattr(curr_settings, key, cast_func(value))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|