internal 0.1.59__tar.gz → 0.1.60__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.

Files changed (28) hide show
  1. {internal-0.1.59 → internal-0.1.60}/PKG-INFO +1 -1
  2. {internal-0.1.59 → internal-0.1.60}/pyproject.toml +1 -1
  3. {internal-0.1.59 → internal-0.1.60}/src/internal/base_config.py +0 -7
  4. {internal-0.1.59 → internal-0.1.60}/src/internal/http/requests.py +9 -1
  5. internal-0.1.59/src/internal/jwt/const.py +0 -2
  6. internal-0.1.59/src/internal/jwt/interface.py +0 -58
  7. internal-0.1.59/src/internal/jwt/service.py +0 -57
  8. internal-0.1.59/src/internal/model/__init__.py +0 -0
  9. {internal-0.1.59 → internal-0.1.60}/README.md +0 -0
  10. {internal-0.1.59 → internal-0.1.60}/src/internal/__init__.py +0 -0
  11. {internal-0.1.59 → internal-0.1.60}/src/internal/base_factory.py +0 -0
  12. {internal-0.1.59 → internal-0.1.60}/src/internal/const.py +0 -0
  13. {internal-0.1.59 → internal-0.1.60}/src/internal/database.py +0 -0
  14. {internal-0.1.59 → internal-0.1.60}/src/internal/exception/__init__.py +0 -0
  15. {internal-0.1.59 → internal-0.1.60}/src/internal/exception/base_exception.py +0 -0
  16. {internal-0.1.59 → internal-0.1.60}/src/internal/exception/internal_exception.py +0 -0
  17. {internal-0.1.59 → internal-0.1.60}/src/internal/ext/__init__.py +0 -0
  18. {internal-0.1.59 → internal-0.1.60}/src/internal/ext/amazon/__init__.py +0 -0
  19. {internal-0.1.59 → internal-0.1.60}/src/internal/ext/amazon/aws/__init__.py +0 -0
  20. {internal-0.1.59 → internal-0.1.60}/src/internal/ext/amazon/aws/const.py +0 -0
  21. {internal-0.1.59 → internal-0.1.60}/src/internal/http/__init__.py +0 -0
  22. {internal-0.1.59 → internal-0.1.60}/src/internal/http/responses.py +0 -0
  23. {internal-0.1.59 → internal-0.1.60}/src/internal/interface/__init__.py +0 -0
  24. {internal-0.1.59 → internal-0.1.60}/src/internal/interface/base_interface.py +0 -0
  25. {internal-0.1.59/src/internal/jwt → internal-0.1.60/src/internal/model}/__init__.py +0 -0
  26. {internal-0.1.59 → internal-0.1.60}/src/internal/model/base_model.py +0 -0
  27. {internal-0.1.59 → internal-0.1.60}/src/internal/model/operate.py +0 -0
  28. {internal-0.1.59 → internal-0.1.60}/src/internal/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 0.1.59
3
+ Version: 0.1.60
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "internal"
3
- version = "0.1.59"
3
+ version = "0.1.60"
4
4
  description = ""
5
5
  authors = ["Ray <ray@cruisys.com>"]
6
6
  readme = "README.md"
@@ -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
@@ -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)
@@ -1,2 +0,0 @@
1
- JWT_AES_KEY = "aEJkxXqO1HOlq2dJ"
2
- JWT_AES_IV = "c0K38tnJIQu5C7DC"
@@ -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)
@@ -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'))
File without changes
File without changes