aiteamutils 0.2.18__py3-none-any.whl → 0.2.20__py3-none-any.whl

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.
aiteamutils/config.py CHANGED
@@ -4,15 +4,28 @@ from .database import init_database_service
4
4
 
5
5
  class Settings:
6
6
  """기본 설정 클래스"""
7
- def __init__(self, jwt_secret: str, jwt_algorithm: str = "HS256"):
7
+ def __init__(
8
+ self,
9
+ jwt_secret: str,
10
+ jwt_algorithm: str = "HS256",
11
+ access_token_expire_minutes: int = 30,
12
+ token_issuer: str = "ai-team",
13
+ token_audience: str = "ai-team"
14
+ ):
8
15
  self.JWT_SECRET = jwt_secret
9
16
  self.JWT_ALGORITHM = jwt_algorithm
17
+ self.ACCESS_TOKEN_EXPIRE_MINUTES = access_token_expire_minutes
18
+ self.TOKEN_ISSUER = token_issuer
19
+ self.TOKEN_AUDIENCE = token_audience
10
20
 
11
21
  _settings: Union[Settings, None] = None
12
22
 
13
23
  def init_settings(
14
24
  jwt_secret: str,
15
25
  jwt_algorithm: str = "HS256",
26
+ access_token_expire_minutes: int = 30,
27
+ token_issuer: str = "ai-team",
28
+ token_audience: str = "ai-team",
16
29
  db_url: str = None,
17
30
  db_echo: bool = False,
18
31
  db_pool_size: int = 5,
@@ -25,6 +38,9 @@ def init_settings(
25
38
  Args:
26
39
  jwt_secret (str): JWT 시크릿 키
27
40
  jwt_algorithm (str, optional): JWT 알고리즘. Defaults to "HS256".
41
+ access_token_expire_minutes (int, optional): 액세스 토큰 만료 시간(분). Defaults to 30.
42
+ token_issuer (str, optional): 토큰 발급자. Defaults to "ai-team".
43
+ token_audience (str, optional): 토큰 대상자. Defaults to "ai-team".
28
44
  db_url (str, optional): 데이터베이스 URL
29
45
  db_echo (bool, optional): SQL 로깅 여부
30
46
  db_pool_size (int, optional): DB 커넥션 풀 크기
@@ -33,7 +49,13 @@ def init_settings(
33
49
  db_pool_recycle (int, optional): 커넥션 재활용 시간
34
50
  """
35
51
  global _settings
36
- _settings = Settings(jwt_secret, jwt_algorithm)
52
+ _settings = Settings(
53
+ jwt_secret=jwt_secret,
54
+ jwt_algorithm=jwt_algorithm,
55
+ access_token_expire_minutes=access_token_expire_minutes,
56
+ token_issuer=token_issuer,
57
+ token_audience=token_audience
58
+ )
37
59
 
38
60
  if db_url:
39
61
  init_database_service(
aiteamutils/database.py CHANGED
@@ -85,7 +85,7 @@ class DatabaseService:
85
85
  pool_pre_ping=True,
86
86
  poolclass=QueuePool,
87
87
  )
88
- self.async_session = sessionmaker(
88
+ self.session_factory = sessionmaker(
89
89
  bind=self.engine,
90
90
  class_=AsyncSession,
91
91
  expire_on_commit=False
@@ -93,7 +93,11 @@ class DatabaseService:
93
93
  self.db = None
94
94
  elif session:
95
95
  self.engine = session.bind
96
- self.async_session = None
96
+ self.session_factory = sessionmaker(
97
+ bind=self.engine,
98
+ class_=AsyncSession,
99
+ expire_on_commit=False
100
+ )
97
101
  self.db = session
98
102
  else:
99
103
  raise ValueError("Either db_url or session must be provided")
@@ -788,9 +792,13 @@ class DatabaseService:
788
792
  CustomException: 데이터베이스 작업 중 오류 발생 시
789
793
  """
790
794
  try:
791
- async with self.db as session:
792
- result = await session.execute(query)
795
+ if self.db:
796
+ result = await self.db.execute(query)
793
797
  return result
798
+ else:
799
+ async with self.session_factory() as session:
800
+ result = await session.execute(query)
801
+ return result
794
802
  except Exception as e:
795
803
  raise CustomException(
796
804
  ErrorCode.DB_QUERY_ERROR,
@@ -2,6 +2,7 @@ from typing import Type, Dict, Tuple, Any, Callable
2
2
  from fastapi import Depends, status
3
3
  from fastapi.security import OAuth2PasswordBearer
4
4
  from jose import JWTError, jwt
5
+ from sqlalchemy.ext.asyncio import AsyncSession
5
6
 
6
7
  from .database import DatabaseService, get_database_service
7
8
  from .exceptions import CustomException, ErrorCode
@@ -59,7 +60,8 @@ def get_service(name: str):
59
60
  Returns:
60
61
  Callable: 서비스 인스턴스를 반환하는 의존성 함수
61
62
  """
62
- def _get_service(db_service: DatabaseService = Depends(get_database_service)):
63
+ def _get_service(db: AsyncSession = Depends(get_db)):
64
+ db_service = DatabaseService(session=db)
63
65
  repository_class, service_class = service_registry.get(name)
64
66
  repository = repository_class(db_service)
65
67
  return service_class(repository, db_service)
aiteamutils/version.py CHANGED
@@ -1,2 +1,2 @@
1
1
  """버전 정보"""
2
- __version__ = "0.2.18"
2
+ __version__ = "0.2.20"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiteamutils
3
- Version: 0.2.18
3
+ Version: 0.2.20
4
4
  Summary: AI Team Utilities
5
5
  Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
6
  Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
@@ -3,14 +3,14 @@ aiteamutils/base_model.py,sha256=ODEnjvUVoxQ1RPCfq8-uZTfTADIA4c7Z3E6G4EVsSX0,270
3
3
  aiteamutils/base_repository.py,sha256=qdwQ7Sj2fUqxpDg6cWM48n_QbwPK_VUlG9zTSem8iCk,18968
4
4
  aiteamutils/base_service.py,sha256=E4dHGE0DvhmRyFplh46SwKJOSF_nUL7OAsCkf_ZJF_8,24733
5
5
  aiteamutils/cache.py,sha256=tr0Yn8VPYA9QHiKCUzciVlQ2J1RAwNo2K9lGMH4rY3s,1334
6
- aiteamutils/config.py,sha256=1rqsrEiYEHbZAtDwS43139jDvPQYEFMn3GKPnZFR9cs,1843
7
- aiteamutils/database.py,sha256=09ihgJgKlCTouWPnb2dMhWqNH75n7lwB5GauEtr3oiQ,33226
8
- aiteamutils/dependencies.py,sha256=S6OWV4d3TONKKW9tRUP9whQlVX5DFfOq7U-7VUyPktA,3928
6
+ aiteamutils/config.py,sha256=7pJHBml8RRXC9FpoRBx0emofFkvtxsyk9_Rcur2F9hI,2724
7
+ aiteamutils/database.py,sha256=XSkyjzerqS6OOo-xACmx3la4KiUsuF32JRXcCA8mjfU,33516
8
+ aiteamutils/dependencies.py,sha256=gy1G4DFb-UooFDFZOSIThEDDCUtsJn9odnm5dKV1kQM,4000
9
9
  aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
10
10
  aiteamutils/exceptions.py,sha256=YV-ISya4wQlHk4twvGo16I5r8h22-tXpn9wa-b3WwDM,15231
11
11
  aiteamutils/security.py,sha256=2k5j8iV4jkp0IGRmOtEbVyoeuoDHbguzaYju0Wm-mmI,12715
12
12
  aiteamutils/validators.py,sha256=3N245cZFjgwtW_KzjESkizx5BBUDaJLbbxfNO4WOFZ0,7764
13
- aiteamutils/version.py,sha256=Sg4iiIem99YPfKGAPuPMcjzOHo_0DUVkFzUVuKBGb3E,44
14
- aiteamutils-0.2.18.dist-info/METADATA,sha256=rYXv8IYNGPEbLVPK_5EGOfpu_YmKQ7_YWgGV7Tnwt1k,1718
15
- aiteamutils-0.2.18.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- aiteamutils-0.2.18.dist-info/RECORD,,
13
+ aiteamutils/version.py,sha256=QU8rgwUP0RFiPXTax1Klj3C2oOhVbZIxSTH48xXwJiA,44
14
+ aiteamutils-0.2.20.dist-info/METADATA,sha256=rluy_nzwvsfEouI6DLMLsefZz7w9zDzINHoPXIeLcLk,1718
15
+ aiteamutils-0.2.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
+ aiteamutils-0.2.20.dist-info/RECORD,,