internal 0.1.58__py3-none-any.whl → 0.1.60__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.

Potentially problematic release.


This version of internal might be problematic. Click here for more details.

internal/base_config.py CHANGED
@@ -37,12 +37,5 @@ class BaseConfig(BaseSettings):
37
37
  THIRD_PARTY_BASE_URL: str = ""
38
38
  SCHEDULER_BASE_URL: str = ""
39
39
 
40
- # JWT
41
- JWT_ALGORITHM: str = 'HS512'
42
- JWT_SECRET_KEY: str = ""
43
- JWT_ACCESS_TOKEN_EXPIRES_SECONDS: int = 86400
44
- JWT_REFRESH_TOKEN_EXPIRES_SECONDS: int = 604800 # 7days
45
- JWT_ERROR_MESSAGE_KEY: str = "message"
46
-
47
40
  class Config:
48
41
  case_sensitive = False
internal/http/requests.py CHANGED
@@ -5,10 +5,18 @@ from fastapi import FastAPI
5
5
  from ..exception.internal_exception import GatewayTimeoutException, BadGatewayException
6
6
 
7
7
 
8
- async def async_request(app: FastAPI, method, url, **kwargs):
8
+ async def async_request(app: FastAPI, method, url, token, **kwargs):
9
9
  timeout = httpx.Timeout(connect=app.state.config.REQUEST_CONN_TIMEOUT, read=app.state.config.REQUEST_READ_TIMEOUT,
10
10
  write=app.state.config.REQUEST_WRITE_TIMEOUT, pool=app.state.config.REQUEST_POOL_TIMEOUT)
11
11
 
12
+ if token:
13
+ if "headers" in kwargs.keys():
14
+ kwargs.get("headers")["Authorization"] = f"Bearer {token}"
15
+ else:
16
+ kwargs["headers"] = {
17
+ "Authorization": f"Bearer {token}"
18
+ }
19
+
12
20
  try:
13
21
  async with httpx.AsyncClient(timeout=timeout) as client:
14
22
  response = await client.request(method, url, **kwargs)
@@ -24,7 +24,7 @@ async def async_response(data=None, message=None, code=None, page_no=None, total
24
24
  return data
25
25
 
26
26
  if isinstance(data, httpx.Response):
27
- return data
27
+ return JSONResponse(status_code=status_code, content=data.json())
28
28
 
29
29
  ret = {}
30
30
  if isinstance(data, list):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 0.1.58
3
+ Version: 0.1.60
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,5 +1,5 @@
1
1
  internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- internal/base_config.py,sha256=GFuigDWbvG257qOc2cfdz3KgHUIKiXOU0E7pnD5zOQA,1247
2
+ internal/base_config.py,sha256=M2HMhJAerOHppSqy1O2J0tGrC5cTGmouf3Cyu0YfIXo,1020
3
3
  internal/base_factory.py,sha256=vgJogtay7GHUqPdGFm9iGRUEvRCncl4KskweviZTk58,6434
4
4
  internal/const.py,sha256=U1S9r7bjtHgad2oYQoHO19s8D4V0WDUG-L-haV4UaIw,1025
5
5
  internal/database.py,sha256=MyRLlb0W8FB8Odq0UQpN3R7OD3yUPWgJXsZRuDWQC_w,1010
@@ -11,18 +11,14 @@ internal/ext/amazon/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
11
11
  internal/ext/amazon/aws/__init__.py,sha256=2YFjb-rHG1JaZGZiZffYDesgTAJjDshOqQbswOYzhP8,834
12
12
  internal/ext/amazon/aws/const.py,sha256=l4WMg5bKWujwOKABBkCO2zclNg3abnYOfbhD7DG8GsA,109
13
13
  internal/http/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- internal/http/requests.py,sha256=Np0uIzHJjJ4S0yeet3dgTJEkQaDo9BkW3gLdqsahCeA,1040
15
- internal/http/responses.py,sha256=qo5cxLaJ2RdmscqweINC-RXEJ2NzKwjyM6LjXfQjjjM,1507
14
+ internal/http/requests.py,sha256=b4VwkVh4jBzZAl6rKLtHRjNXI_F-QLBpjzMPHEPB39Q,1285
15
+ internal/http/responses.py,sha256=JW6CA11MDhM_RwIvZzr0mThUdga3EyYsuG9dfTAxZxw,1561
16
16
  internal/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  internal/interface/base_interface.py,sha256=R5MmO5oa5-ORPV_adkegLVCwsVio2zFOuQFGiby3khs,340
18
- internal/jwt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- internal/jwt/const.py,sha256=s8MMB4RJycBBvC4ahd7vcDT-1aTKO3GeaSTUK_DWpwM,65
20
- internal/jwt/interface.py,sha256=dtynYvsE4OojmdgUYH3LEz2FCeYa0ZmlrejwbZT8UxQ,1129
21
- internal/jwt/service.py,sha256=iLB5W_wN5I5vYXfyq5GQttcQmngSF-jT4OSkotIsFzI,2531
22
18
  internal/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
19
  internal/model/base_model.py,sha256=gNbixWuGiK8Tbe78wHuLneZ8p3fwMwQRKurBDrGoh6s,1874
24
20
  internal/model/operate.py,sha256=3mOs7eQ2CPnCB6i6UQBOp8VdTPmVnayaUFqUEDOKoTY,1493
25
21
  internal/utils.py,sha256=0SubS0iUhDvjSX1F4TykasA5-enYJzt2VH-f7_0BnjI,1509
26
- internal-0.1.58.dist-info/METADATA,sha256=cXGiOMza3RablSkZ1YbE8nS5AQtUAdZfqeG31cJWZX8,625
27
- internal-0.1.58.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
28
- internal-0.1.58.dist-info/RECORD,,
22
+ internal-0.1.60.dist-info/METADATA,sha256=lbtD1Q28xOIkxRhfftkwkPaqWUJUpfH9VT_tXY8H0MM,625
23
+ internal-0.1.60.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
24
+ internal-0.1.60.dist-info/RECORD,,
internal/jwt/__init__.py DELETED
File without changes
internal/jwt/const.py DELETED
@@ -1,2 +0,0 @@
1
- JWT_AES_KEY = "aEJkxXqO1HOlq2dJ"
2
- JWT_AES_IV = "c0K38tnJIQu5C7DC"
internal/jwt/interface.py DELETED
@@ -1,58 +0,0 @@
1
- from dataclasses import dataclass
2
-
3
- from ..interface.base_interface import InternalBaseInterface
4
-
5
-
6
- @dataclass
7
- class JWTUserInterface(InternalBaseInterface):
8
- id: str
9
- name: str
10
- phone: str
11
- mobile: str
12
- email: str
13
- title: str
14
- organization_parent: str
15
- organization_id: str
16
- ext_user_id: str
17
- ext_dealer_code: str
18
- ext_dept_code: str
19
- ext_dept_name: str
20
- line_id: str
21
- line_url: str
22
- role: str
23
- avatar: str = None
24
-
25
- def __init__(self, **kwargs):
26
- super().__init__(**kwargs)
27
-
28
-
29
- @dataclass
30
- class JWTCustomerInterface(InternalBaseInterface):
31
- id: str
32
- ccid: str
33
- name: str
34
- phone: str
35
- mobile: str
36
- email: str
37
- title: str
38
- organization_parent: str
39
- organization_id: str
40
- ext_user_id: str
41
- ext_dealer_code: str
42
- ext_dept_code: str
43
- ext_dept_name: str
44
- line_id: str
45
- line_url: str
46
- role: str
47
- avatar: str = None
48
-
49
- def __init__(self, **kwargs):
50
- super().__init__(**kwargs)
51
-
52
-
53
- @dataclass
54
- class JWTTokenInterface(InternalBaseInterface):
55
- data: str
56
-
57
- def __init__(self, **kwargs):
58
- super().__init__(**kwargs)
internal/jwt/service.py DELETED
@@ -1,57 +0,0 @@
1
- # import base64
2
- # import json
3
- # from typing import Union
4
- #
5
- # from cryptography.hazmat.backends import default_backend
6
- # from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
7
- # from fastapi import HTTPException
8
- # from fastapi.security import OAuth2PasswordBearer
9
- # from jose import JWTError, jwt
10
- #
11
- # from jwt.const import JWT_AES_KEY, JWT_AES_IV
12
- # from jwt.interface import JWTUserInterface, JWTTokenInterface
13
- #
14
- # oauth2_scheme_user = OAuth2PasswordBearer(tokenUrl=f"auth/user/cruisys_token")
15
- #
16
- #
17
- # class JWTService:
18
- # @staticmethod
19
- # async def create_jwt_token(data: dict, app_config) -> str:
20
- # jwt_user_interface = JWTUserInterface(**data)
21
- # cipher_str = await JWTService.encrypt_aes_plain(jwt_user_interface)
22
- # jwt_token_interface = JWTTokenInterface(data=cipher_str)
23
- # token = jwt.encode(jwt_token_interface.to_dict(), app_config.JWT_SECRET_KEY,
24
- # algorithm=app_config.JWT_ALGORITHM)
25
- # return token
26
- #
27
- # @staticmethod
28
- # async def decode_jwt_token(token: str, app_config) -> Union[dict, JWTUserInterface, HTTPException]:
29
- # try:
30
- # payload = jwt.decode(token, app_config.JWT_SECRET_KEY, algorithms=[app_config.JWT_ALGORITHM])
31
- # plain_obj = await JWTService.decrypt_aes_cipher(JWTTokenInterface(**payload))
32
- # jwt_user_interface = JWTUserInterface(**plain_obj)
33
- # return jwt_user_interface
34
- # except JWTError:
35
- # raise HTTPException(status_code=401, detail="Invalid token")
36
- #
37
- # @staticmethod
38
- # async def encrypt_aes_plain(interface: JWTUserInterface):
39
- # plaintext = json.dumps(interface.to_dict()).encode('utf-8')
40
- #
41
- # cipher = Cipher(algorithms.AES(JWT_AES_KEY.encode('utf-8')), modes.CFB(JWT_AES_IV.encode('utf-8')),
42
- # backend=default_backend())
43
- # encryptor = cipher.encryptor()
44
- # ciphertext = encryptor.update(plaintext) + encryptor.finalize()
45
- #
46
- # return base64.b64encode(ciphertext).decode('utf-8')
47
- #
48
- # @staticmethod
49
- # async def decrypt_aes_cipher(interface: JWTTokenInterface):
50
- # ciphertext = base64.b64decode(interface.data)
51
- #
52
- # cipher = Cipher(algorithms.AES(JWT_AES_KEY.encode('utf-8')), modes.CFB(JWT_AES_IV.encode('utf-8')),
53
- # backend=default_backend())
54
- # decryptor = cipher.decryptor()
55
- # plaintext = decryptor.update(ciphertext) + decryptor.finalize()
56
- #
57
- # return json.loads(plaintext.decode('utf-8'))