Commit 1df069bc authored by arun.uday's avatar arun.uday

Merge branch '1-arun-uday-asset-manager-v1-0' into 'master'

1 arun uday asset manager v1 0

See merge request !2
parents 16af59f4 0f326899
MONGO_URI=mongodb://localhost:27017 MONGO_URI=mongodb://localhost:27017
DB_NAME=userDB DB_NAME=userDB
SERVICE_HOST=0.0.0.0 REDIS_URI=redis://127.0.0.1:6379
REDIS_LOGIN_DB=10
SERVICE_HOST=127.0.0.1
SERVICE_PORT=8671 SERVICE_PORT=8671
PROJECT_NAME=AssetManager PROJECT_NAME=AssetManager
PROJECT_ID=1256
base_path=scripts/ BASE_PATH=scripts/
sub_path=log/ SUB_PATH=log/
ENCODING_TYPE=utf-8 ENCODING_TYPE=utf-8
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Author: Arun Uday Author: Arun Uday
Email: arun.uday@knowledgelens.com Email: arun.uday@knowledgelens.com
Asset Manager Login For Normal User Login Asset Manager Login / Registration
--------------------------------------------------------- ---------------------------------------------------------
""" """
......
uvicorn~=0.21.0 uvicorn==0.21.1
python-dotenv~=1.0.0 python-dotenv~=1.0.0
pydantic~=1.10.6 pydantic~=1.10.6
fastapi~=0.94.1 fastapi==0.95.0
passlib~=1.7.4 passlib~=1.7.4
pymongo~=4.3.3 pymongo~=4.3.3
bcrypt~=4.0.1 bcrypt~=4.0.1
\ No newline at end of file email-validator~=1.3.1
pycryptodomex~=3.17
PyJWT~=2.6.0
validate_email~=1.3
redis~=4.5.2
\ No newline at end of file
...@@ -8,7 +8,6 @@ class _Services(BaseSettings): ...@@ -8,7 +8,6 @@ class _Services(BaseSettings):
HOST: str = Field(default="127.0.0.1", env="service_host") HOST: str = Field(default="127.0.0.1", env="service_host")
PORT: int = Field(default=8000, env="service_port") PORT: int = Field(default=8000, env="service_port")
PROJECT_NAME = Field(default="AssetManager", env="project_name") PROJECT_NAME = Field(default="AssetManager", env="project_name")
PROJECT_ID = Field(default="1256", env="project_id")
ENCODING_TYPE = Field(default="utf-8", env="encoding_type") ENCODING_TYPE = Field(default="utf-8", env="encoding_type")
ENABLE_CORS: bool = True ENABLE_CORS: bool = True
CORS_URLS: list[str] = ["*.ilens.io"] CORS_URLS: list[str] = ["*.ilens.io"]
...@@ -17,15 +16,13 @@ class _Services(BaseSettings): ...@@ -17,15 +16,13 @@ class _Services(BaseSettings):
CORS_ALLOW_HEADERS: list[str] = ["*"] CORS_ALLOW_HEADERS: list[str] = ["*"]
LOG_LEVEL: Literal["INFO", "DEBUG", "ERROR", "QTRACE"] = "INFO" LOG_LEVEL: Literal["INFO", "DEBUG", "ERROR", "QTRACE"] = "INFO"
ENABLE_FILE_LOGGING: bool = False ENABLE_FILE_LOGGING: bool = False
KEY_ENCRYPTION = "kliLensKLiLensKL"
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30
class _Databases(BaseSettings): class _Databases(BaseSettings):
MONGO_URI: str MONGO_URI: str
DB_NAME: str DB_NAME: str
REDIS_URI: str
REDIS_LOGIN_DB: int
class _BasePathConf(BaseSettings): class _BasePathConf(BaseSettings):
...@@ -37,12 +34,23 @@ class _PathConf: ...@@ -37,12 +34,23 @@ class _PathConf:
LOG_PATH: pathlib.Path = BASE_PATH / "log/" LOG_PATH: pathlib.Path = BASE_PATH / "log/"
class _Secrets(BaseSettings):
ACCESS_TOKEN_EXPIRE_MINUTES = 30
leeway_in_minutes: int = 10
KEY_ENCRYPTION = "kliLensKLiLensKL"
issuer: str = "iotManager"
SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7"
ALGORITHM = "HS256"
Services = _Services() Services = _Services()
Databases = _Databases() Databases = _Databases()
PathConf = _PathConf() PathConf = _PathConf()
Secrets = _Secrets()
__all__ = [ __all__ = [
"Services", "Services",
"Databases", "Databases",
"PathConf", "PathConf",
"Secrets"
] ]
from pydantic import BaseSettings, Field
PROJECT_NAME = "IotManager"
class _Services(BaseSettings):
HOST: str = Field(default="127.0.0.1", env="service_host")
PORT: int = Field(default=8000, env="service_port")
class _Databases(BaseSettings):
MONGO_URI: str
Services = _Services()
Databases = _Databases()
__all__ = [
"PROJECT_NAME",
"Services",
"Databases",
]
...@@ -3,7 +3,19 @@ class ApiEndPoints: ...@@ -3,7 +3,19 @@ class ApiEndPoints:
version = "/v1" version = "/v1"
# common # common
asset_manager_submit: str = "/submit" submit: str = "/submit"
create: str = "/create"
insert: str = "/insert"
update: str = "/update"
delete: str = "/delete"
# login-management # login-management
asset_manager_login: str = "/login" asset_manager_login: str = "/login"
asset_manager_submit: str = asset_manager_login + submit
# user-registration
asset_manager_user_registration: str = "/register"
asset_manager_user_add: str = asset_manager_user_registration + create
asset_manager_user_update: str = asset_manager_user_registration + update
asset_manager_user_delete: str = asset_manager_user_registration + delete
from __future__ import annotations from scripts.core.handlers.normal_login import NormalLogin
from fastapi.responses import JSONResponse
import base64 from fastapi import status
import datetime
from Cryptodome.Cipher import AES
from passlib.context import CryptContext
from scripts.config import Services
from scripts.database.mongo.mongo_login import MongoUser
from scripts.errors import ErrorMessages from scripts.errors import ErrorMessages
from scripts.logging.logger import logger from scripts.schemas.default_responses import DefaultFailureResponse, DefaultResponse
from scripts.utils.mongo_default_queries import MongoQueries from scripts.utils.security.password_decryption_util import DecryptPassword
class LoginHandlers: class LoginHandlers:
def __init__(self): def __init__(self):
self.mongo_user = MongoUser() self.obj_login_handler = NormalLogin()
self.mongo_queries = MongoQueries() self.pass_decrypt = DecryptPassword()
self.pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") self.login_type = ""
self.db_user_data = None
self.db_user_data = None def normal_login(self, user_data, request):
self.dt = datetime.datetime.now() self.login_type = "normal"
self.time_dt = datetime.datetime.now() # decrypting the password from the UI
decrypted_password = self.pass_decrypt.password_decrypt(user_data.password)
@staticmethod
def un_pad(s): # validating the received inputs empty or not
# un_padding the encrypted password response = self.obj_login_handler.user_data_validation(
return s[:-ord(s[len(s) - 1:])] user_data.username,
decrypted_password)
def password_decrypt(self, password):
try: # Account is not registered
# encoding the Key if response is not None:
key = Services.KEY_ENCRYPTION.encode(Services.ENCODING_TYPE) return JSONResponse(content=DefaultFailureResponse(error=response).dict(),
# decoding the received password status_code=status.HTTP_400_BAD_REQUEST)
enc = base64.b64decode(password) # checking for the account and password matching
# mode for the decryption response, data = self.obj_login_handler.db_password_matching(self.login_type, user_data,
mode = AES.MODE_CBC decrypted_password)
# getting the initialization vector # if the passwords doesn't match with the db data
iv = enc[:AES.block_size] if response is not None:
# decoding with AES return JSONResponse(content=DefaultFailureResponse(error=data).dict(),
cipher = AES.new(key, mode, iv) status_code=status.HTTP_401_UNAUTHORIZED)
# decoding the password
data = cipher.decrypt(enc[AES.block_size:]) # generating the access tokens
if len(data) == 0: response = self.obj_login_handler.generate_cookie_tokens(user_data, request)
raise ValueError("Decrypted data is empty") # token generation unsuccessful
# removing the padding to get the password if response is None:
data = self.un_pad(data) return JSONResponse(
return data.decode('utf-8') content=DefaultFailureResponse(message="Access Unsuccessful",
except Exception as e: error=ErrorMessages.ERROR_TOKEN_GENERATION).dict(),
logger.exception(e) status_code=status.HTTP_403_FORBIDDEN)
# sending successful response to UI
@staticmethod return JSONResponse(
def user_data_validation(username, password) -> dict | None: content=DefaultResponse(message="Login Successful", data=response).dict(),
try: status_code=status.HTTP_200_OK)
# checking for valid username
if username == "" or username == "user@example.com": # v1
return {"message": ErrorMessages.ERROR_INVALID_USERNAME, "data": username} def google_login(self, request):
# checking for valid password pass
if password == "" or password == "string":
return {"message": ErrorMessages.ERROR_INVALID_PASSWORD, "data": password} # v2
return None def microsoft_login(self, request):
except Exception as e: pass
logger.exception(e)
def new_user_login(self, login_data, password):
# check the domain of the email the user has entered
if login_data.username.split("@")[-1] == "knowledgelens.com":
# hash the password
hashed_password = self.pwd_context.hash(password)
# Enter the user as a guest user to the db
if self.mongo_user.insert_user(
self.mongo_queries.insert_user_query(
login_data,
Services.PROJECT_ID,
hashed_password,
self.time_dt)):
return True
return False
def db_data_validation(self, login_data, password):
try:
# fetching the data based on the username
self.db_user_data = MongoUser().fetch_user_details(login_data.username)
# if the user is not available
if not self.db_user_data:
# if the domain of the user email is knowledge lens create the user as a guest user
if self.new_user_login(login_data, password):
return True, {"message": "new_user", "username": login_data.username, "role": "guest"}
else:
return False, {"message": ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN,
"data": {"username": login_data.username}}
# Check the project id from the request body
if self.db_user_data["project_id"] != Services.PROJECT_ID or Services.PROJECT_ID != login_data.project_id:
return False, {"message": ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN, "data": login_data.username}
# if the user exist
return None, {"message": True}
except Exception as e:
logger.exception(e)
def db_password_matching(self, login_data, password):
try:
# getting the response after checking for the user data in db
response, message = self.db_data_validation(login_data, password)
if response and message["message"] == "new_user":
return None, message
# if the response is false then an error message is send back
if response is not None:
return response, message
# if the user exists in db then password is matched
if not self.pwd_context.verify(password, self.db_user_data["password"]):
return False, {"message": ErrorMessages.ERROR_PASSWORD_MISMATCH,
"data": {"username": login_data.username}}
# if the password is correct
return None, {"username": login_data.username, "role": self.db_user_data["user_role"]}
except Exception as e:
logger.exception(e)
from __future__ import annotations
from datetime import datetime
from passlib.context import CryptContext
from validate_email import validate_email
from scripts.database.mongo.mongo_login import MongoUser
from scripts.errors import ErrorMessages
from scripts.logging.logger import logger
from scripts.utils.security.apply_encrytion_util import create_token
class NormalLogin:
def __init__(self):
self.pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
self.db_user_data = None
self.db_user_data = None
self.dt = datetime.now()
self.time_dt = datetime.now()
@staticmethod
def user_data_validation(username, password) -> dict | None:
try:
# checking for valid username
if username == "" or username == "user@example.com" or validate_email(username) is not True:
return {"message": ErrorMessages.ERROR_INVALID_USERNAME, "data": username}
# checking for valid password
if password == "" or password == "string":
return {"message": ErrorMessages.ERROR_INVALID_PASSWORD, "data": password}
return None
except Exception as e:
logger.exception(e)
def db_data_validation(self, login_type, username):
try:
# fetching the data based on the username
self.db_user_data = MongoUser().fetch_user_details(username)
# if the user is not available
if not self.db_user_data:
return False, {"message": ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN,
"data": {"username": username}}
# if the user is not registered through normal login
if self.db_user_data["login_type"] != login_type:
return False, {"message": ErrorMessages.ERROR_LOGIN_TYPE_INVALID,
"data": {"username": username, "Use Login": self.db_user_data["login_type"]}}
# if the user exist
return None, {"message": True}
except Exception as e:
logger.exception(e)
def db_password_matching(self, login_type, user_data, password):
try:
# getting the response after checking for the user data in db
response, message = self.db_data_validation(login_type, user_data.username)
# if the response is false then an error message is send back
if response is not None:
return response, message
# if the user exists in db then password is matched
if not self.pwd_context.verify(password, self.db_user_data["password"]):
return False, {"message": ErrorMessages.ERROR_PASSWORD_MISMATCH,
"data": {"username": user_data.username}}
# if the password is correct
return None, {"username": user_data.username, "role": self.db_user_data["user_role"]}
except Exception as e:
logger.exception(e)
@staticmethod
def generate_cookie_tokens(user_data, request):
try:
# creating the access token
access_token = create_token(
user_id=user_data.username,
ip=request.ip_address
)
# returning the login token
if access_token:
return {"user_id": access_token, "token_type": "bearer"}
else:
return None
except Exception as e:
logger.exception(e)
from scripts.config import Databases from scripts.config import Databases
from scripts.utils.mongo_utils import MongoConnect from scripts.utils.mongo_utils import MongoConnect
# creating the mongo connection
mongo_obj = MongoConnect(uri=Databases.MONGO_URI) mongo_obj = MongoConnect(uri=Databases.MONGO_URI)
mongo_client = mongo_obj() mongo_client = mongo_obj()
CollectionBaseClass = mongo_obj.get_base_class() CollectionBaseClass = mongo_obj.get_base_class()
...@@ -27,12 +27,14 @@ class MongoUser(CollectionBaseClass): ...@@ -27,12 +27,14 @@ class MongoUser(CollectionBaseClass):
def __init__(self): def __init__(self):
super().__init__(mongo_client, Databases.DB_NAME, collection_name) super().__init__(mongo_client, Databases.DB_NAME, collection_name)
# fetching the user details based on the email id
def fetch_user_details(self, email): def fetch_user_details(self, email):
if user := self.find_one(query={self.key_email: email}): if user := self.find_one(query={self.key_email: email}):
return user return user
return None return None
def insert_user(self, query): # updating the login time
if user := self.insert_one(data=query): def update_user(self, update, query):
if user := self.update_one(query=update, data=query):
return user return user
return None return None
import redis
from scripts.config import Databases
# creating the redis connection
redis_uri = Databases.REDIS_URI
# user login db
login_db = redis.from_url(
redis_uri, db=int(Databases.REDIS_LOGIN_DB), decode_responses=True
)
...@@ -7,5 +7,7 @@ class ErrorMessages: ...@@ -7,5 +7,7 @@ class ErrorMessages:
ERROR_INVALID_USERNAME = "Invalid Username" ERROR_INVALID_USERNAME = "Invalid Username"
ERROR_INVALID_PASSWORD = "Invalid Password" ERROR_INVALID_PASSWORD = "Invalid Password"
ERROR_UNAUTHORIZED_USER_LOGIN = "Account is not available" ERROR_UNAUTHORIZED_USER_LOGIN = "Account is not available"
ERROR_LOGIN_TYPE_INVALID = "Invalid Login Method"
ERROR_USER_NOT_REGISTERED = "Account is not registered in the portal." ERROR_USER_NOT_REGISTERED = "Account is not registered in the portal."
ERROR_PASSWORD_MISMATCH = "Passwords Authentication Failed. Please enter the correct password" ERROR_PASSWORD_MISMATCH = "Passwords Authentication Failed. Please enter the correct password"
ERROR_TOKEN_GENERATION = "Unsuccessful token generation"
...@@ -25,3 +25,942 @@ TypeError: Object of type set is not JSON serializable ...@@ -25,3 +25,942 @@ TypeError: Object of type set is not JSON serializable
2023-03-20 15:09:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671 2023-03-20 15:09:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-20 15:09:36 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671 2023-03-20 15:09:36 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-20 15:10:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671 2023-03-20 15:10:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:33:43 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:33:43 - ERROR - [MainThread:<module>(): 41] - invalid syntax (jose.py, line 546)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 5, in <module>
from scripts.core.handlers.login_handler import LoginHandlers
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 6, in <module>
from jose import jwt
File "E:\Git\meta-services\venv\lib\site-packages\jose.py", line 546
print decrypt(deserialize_compact(jwt), {'k':key},
^
SyntaxError: invalid syntax
2023-03-21 10:33:53 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:33:53 - ERROR - [MainThread:<module>(): 41] - invalid syntax (jose.py, line 546)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 5, in <module>
from scripts.core.handlers.login_handler import LoginHandlers
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 6, in <module>
from jose import jwt
File "E:\Git\meta-services\venv\lib\site-packages\jose.py", line 546
print decrypt(deserialize_compact(jwt), {'k':key},
^
SyntaxError: invalid syntax
2023-03-21 10:35:00 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:35:01 - ERROR - [MainThread:<module>(): 41] - invalid syntax (jose.py, line 546)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 5, in <module>
from scripts.core.handlers.login_handler import LoginHandlers
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 6, in <module>
from jose import jwt
File "E:\Git\meta-services\venv\lib\site-packages\jose.py", line 546
print decrypt(deserialize_compact(jwt), {'k':key},
^
SyntaxError: invalid syntax
2023-03-21 10:35:51 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:35:52 - ERROR - [MainThread:<module>(): 41] - type object 'datetime.datetime' has no attribute 'datetime'
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 14, in <module>
obj_login_handler = LoginHandlers()
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 24, in __init__
self.dt = datetime.datetime.now()
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
2023-03-21 10:36:26 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:37:03 - ERROR - [AnyIO worker thread:login_default(): 44] - Object of type datetime is not JSON serializable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 37, in login_default
response = obj_login_handler.generate_tokens(login_data, data)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 133, in generate_tokens
access_token = self.create_access_token(
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 128, in create_access_token
encoded_jwt = jwt.encode(to_encode, Services.SECRET_KEY, algorithm=Services.ALGORITHM)
File "E:\Git\meta-services\venv\lib\site-packages\jwt\api_jwt.py", line 63, in encode
json_payload = json.dumps(
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 234, in dumps
return cls(
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable
2023-03-21 10:40:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:40:46 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 10:46:22 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:45:54 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:46:19 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:46:48 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:47:24 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:48:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:51:13 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:51:16 - ERROR - [MainThread:user_data_validation(): 64] - value is not a valid email address
Traceback (most recent call last):
File "pydantic\networks.py", line 729, in pydantic.networks.validate_email
File "E:\Git\meta-services\venv\lib\site-packages\email_validator\__init__.py", line 304, in validate_email
raise EmailSyntaxError("The email address is not valid. It must have exactly one @-sign.")
email_validator.EmailSyntaxError: The email address is not valid. It must have exactly one @-sign.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 57, in user_data_validation
if username == "" or username == "user@example.com" or validate_email(username):
File "pydantic\networks.py", line 731, in pydantic.networks.validate_email
pydantic.errors.EmailError: value is not a valid email address
2023-03-21 14:51:36 - ERROR - [MainThread:user_data_validation(): 64] - value is not a valid email address
Traceback (most recent call last):
File "pydantic\networks.py", line 729, in pydantic.networks.validate_email
File "E:\Git\meta-services\venv\lib\site-packages\email_validator\__init__.py", line 304, in validate_email
raise EmailSyntaxError("The email address is not valid. It must have exactly one @-sign.")
email_validator.EmailSyntaxError: The email address is not valid. It must have exactly one @-sign.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 57, in user_data_validation
if username == "" or username == "user@example.com" or validate_email(username):
File "pydantic\networks.py", line 731, in pydantic.networks.validate_email
pydantic.errors.EmailError: value is not a valid email address
2023-03-21 14:52:48 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:52:51 - ERROR - [MainThread:user_data_validation(): 64] - The email address is not valid. It must have exactly one @-sign.
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 57, in user_data_validation
if username == "" or username == "user@example.com" or validate_email(username):
File "E:\Git\meta-services\venv\lib\site-packages\email_validator\__init__.py", line 304, in validate_email
raise EmailSyntaxError("The email address is not valid. It must have exactly one @-sign.")
email_validator.EmailSyntaxError: The email address is not valid. It must have exactly one @-sign.
2023-03-21 14:56:51 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:57:15 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:57:56 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 14:58:25 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:01:38 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:01:41 - ERROR - [MainThread:db_data_validation(): 80] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 69, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data.username)
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:01:41 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 85, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:01:41 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:15 - ERROR - [MainThread:db_data_validation(): 80] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 69, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data.username)
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:02:15 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 85, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:15 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:36 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:02:39 - ERROR - [MainThread:db_data_validation(): 80] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 69, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data.username)
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:02:39 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 85, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:39 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:02:59 - ERROR - [MainThread:db_data_validation(): 80] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 69, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data.username)
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:02:59 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 85, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:02:59 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:04:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:04:55 - ERROR - [MainThread:db_password_matching(): 98] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 94, in db_password_matching
"data": {"username": login_data.username}}
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:04:55 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:06:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:07:19 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:07:44 - ERROR - [MainThread:db_data_validation(): 80] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 73, in db_data_validation
"data": {"username": login_data.username}}
AttributeError: 'dict' object has no attribute 'username'
2023-03-21 15:07:44 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 85, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:07:44 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:14:20 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:14:24 - ERROR - [MainThread:db_password_matching(): 98] - string indices must be integers
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 86, in db_password_matching
if response and message["message"] == "new_user":
TypeError: string indices must be integers
2023-03-21 15:14:24 - ERROR - [MainThread:login_default(): 32] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-21 15:15:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:15:24 - ERROR - [MainThread:login_default(): 32] - string indices must be integers
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 19, in login_default
return obj_login_handler.normal_login(request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 26, in normal_login
if response is not None and data["message"] == ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN:
TypeError: string indices must be integers
2023-03-21 15:17:34 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:17:57 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:28:58 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:30:05 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 15:30:58 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 18:06:53 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 18:06:54 - ERROR - [MainThread:<module>(): 41] - 'list' object is not callable
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 14, in <module>
@router.routes(ApiEndPoints.asset_manager_submit)
TypeError: 'list' object is not callable
2023-03-21 18:07:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-21 18:08:38 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 09:55:22 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 09:55:45 - ERROR - [MainThread:create_access_token(): 114] - Algorithm 'RS256' could not be found. Do you have cryptography installed?
Traceback (most recent call last):
File "E:\Git\meta-services\venv\lib\site-packages\jwt\api_jws.py", line 88, in get_algorithm_by_name
return self._algorithms[alg_name]
KeyError: 'RS256'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 111, in create_access_token
encoded_jwt = jwt.encode(to_encode, Secrets.SECRET_KEY, algorithm=Secrets.ALGORITHM)
File "E:\Git\meta-services\venv\lib\site-packages\jwt\api_jwt.py", line 67, in encode
return api_jws.encode(json_payload, key, algorithm, headers, json_encoder)
File "E:\Git\meta-services\venv\lib\site-packages\jwt\api_jws.py", line 152, in encode
alg_obj = self.get_algorithm_by_name(algorithm_)
File "E:\Git\meta-services\venv\lib\site-packages\jwt\api_jws.py", line 91, in get_algorithm_by_name
raise NotImplementedError(
NotImplementedError: Algorithm 'RS256' could not be found. Do you have cryptography installed?
2023-03-22 09:57:43 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 10:56:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 10:58:59 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 10:59:38 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:23:37 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:27:35 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:43:20 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:44:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:45:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:45:35 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:45:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:46:34 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:48:03 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:50:47 - ERROR - [AnyIO worker thread:validate(): 40] - Exception while validating JWT: '_Secrets' object has no attribute 'leeway_in_mins'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\jwt_util.py", line 35, in validate
leeway=Secrets.leeway_in_mins,
AttributeError: '_Secrets' object has no attribute 'leeway_in_mins'
2023-03-22 11:50:47 - ERROR - [AnyIO worker thread:__call__(): 66] -
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 64, in __call__
logger.exception(e)
fastapi.exceptions.HTTPException
2023-03-22 11:52:02 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:52:05 - ERROR - [AnyIO worker thread:validate(): 40] - Exception while validating JWT: '_Secrets' object has no attribute 'leeway_in_mins'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\jwt_util.py", line 35, in validate
leeway=Secrets.leeway_in_mins,
AttributeError: '_Secrets' object has no attribute 'leeway_in_mins'
2023-03-22 11:52:05 - ERROR - [AnyIO worker thread:__call__(): 63] -
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 61, in __call__
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
fastapi.exceptions.HTTPException
2023-03-22 11:52:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:54:31 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:56:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:57:13 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 11:57:54 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:06:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:07:51 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:07:52 - ERROR - [MainThread:<module>(): 41] - 'await' outside async function (decorators.py, line 48)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 9, in <module>
from scripts.utils.security.decorators import MetaInfoSchema, auth
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 48
payload = await request.json()
^
SyntaxError: 'await' outside async function
2023-03-22 12:08:04 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:12:16 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:12:17 - ERROR - [MainThread:<module>(): 41] - 'await' outside async function (decorators.py, line 48)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 9, in <module>
from scripts.utils.security.decorators import MetaInfoSchema, auth
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 48
payload = await request.body()
^
SyntaxError: 'await' outside async function
2023-03-22 12:12:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:13:10 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:13:24 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:19:14 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:21:15 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:21:22 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:21:27 - ERROR - [MainThread:__call__(): 83] - 'project_id'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 77, in __call__
if not payload["project_id"] or not payload["login_type"] or not payload["payload"]:
KeyError: 'project_id'
2023-03-22 12:39:57 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 12:40:05 - ERROR - [MainThread:__call__(): 83] - 'project_id'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\decorators.py", line 77, in __call__
if not payload["project_id"] or not payload["login_type"] or not payload["payload"]:
KeyError: 'project_id'
2023-03-22 12:43:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:43:31 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:43:54 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:48:45 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:49:00 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:49:22 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:49:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:49:54 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:50:14 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:53:46 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:54:04 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 14:54:29 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 15:07:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 15:07:12 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 15:09:59 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 15:10:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 15:11:18 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:33:21 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:33:23 - ERROR - [MainThread:<module>(): 41] - '_Secrets' object has no attribute 'LOCK_OUT_TIME_MINS'
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 6, in <module>
from scripts.core.handlers.login_handler import LoginHandlers
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 1, in <module>
from scripts.core.handlers.normal_login import NormalLogin
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 15, in <module>
from scripts.utils.security.apply_encrytion_util import create_token
File "E:\Git\meta-services\scripts\utils\security\apply_encrytion_util.py", line 14, in <module>
age=Secrets.LOCK_OUT_TIME_MINS,
AttributeError: '_Secrets' object has no attribute 'LOCK_OUT_TIME_MINS'
2023-03-22 18:34:00 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:34:00 - ERROR - [MainThread:<module>(): 41] - expected an indented block (iot_manager_services.py, line 36)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 36
except Exception as e:
^
IndentationError: expected an indented block
2023-03-22 18:35:06 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:35:12 - ERROR - [MainThread:generate_cookie_tokens(): 113] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 105, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:35:59 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:36:04 - ERROR - [MainThread:generate_cookie_tokens(): 113] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 105, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:37:04 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:37:15 - ERROR - [MainThread:generate_cookie_tokens(): 113] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 105, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:37:32 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:37:36 - ERROR - [MainThread:generate_cookie_tokens(): 113] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 105, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:37:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:37:56 - ERROR - [MainThread:generate_cookie_tokens(): 114] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 106, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:38:14 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:38:18 - ERROR - [MainThread:generate_cookie_tokens(): 116] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 103, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:38:48 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:38:51 - ERROR - [MainThread:generate_cookie_tokens(): 116] - 'MetaInfoSchema' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 103, in generate_cookie_tokens
request['ip_address'],
TypeError: 'MetaInfoSchema' object is not subscriptable
2023-03-22 18:39:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:39:25 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:39:30 - ERROR - [MainThread:generate_cookie_tokens(): 116] - unsupported type for timedelta minutes component: str
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 106, in generate_cookie_tokens
access_token = create_token(
File "E:\Git\meta-services\scripts\utils\security\apply_encrytion_util.py", line 25, in create_token
exp = datetime.now(timezone.utc) + timedelta(minutes=age)
TypeError: unsupported type for timedelta minutes component: str
2023-03-22 18:40:45 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:55:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:57:14 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 18:59:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 19:02:32 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 19:02:59 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 19:06:01 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-22 19:14:25 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:41:43 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:43:55 - ERROR - [MainThread:db_data_validation(): 81] - 'dict' object has no attribute 'username'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 77, in db_data_validation
return False, {"message": ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN, "data": login_data.username}
AttributeError: 'dict' object has no attribute 'username'
2023-03-23 09:43:55 - ERROR - [MainThread:db_password_matching(): 97] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 86, in db_password_matching
response, message = self.db_data_validation(project_id, login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:43:55 - ERROR - [MainThread:login_default(): 37] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 24, in login_default
return obj_login_handler.normal_login(user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 22, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:51:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:51:24 - ERROR - [MainThread:login_default(): 37] - db_password_matching() takes 3 positional arguments but 4 were given
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 24, in login_default
return obj_login_handler.normal_login(user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 25, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: db_password_matching() takes 3 positional arguments but 4 were given
2023-03-23 09:51:53 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:51:57 - ERROR - [MainThread:db_data_validation(): 82] - string indices must be integers
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 71, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data["username"])
TypeError: string indices must be integers
2023-03-23 09:51:57 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 87, in db_password_matching
response, message = self.db_data_validation(login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:51:57 - ERROR - [MainThread:login_default(): 37] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 24, in login_default
return obj_login_handler.normal_login(user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 25, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:52:29 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:52:34 - ERROR - [MainThread:db_data_validation(): 82] - string indices must be integers
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 71, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data["username"])
TypeError: string indices must be integers
2023-03-23 09:52:34 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 87, in db_password_matching
response, message = self.db_data_validation(login_data)
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:52:34 - ERROR - [MainThread:login_default(): 37] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 24, in login_default
return obj_login_handler.normal_login(user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 25, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.project_id,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:53:43 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 09:53:48 - ERROR - [MainThread:db_data_validation(): 82] - string indices must be integers
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 71, in db_data_validation
self.db_user_data = MongoUser().fetch_user_details(login_data["username"])
TypeError: string indices must be integers
2023-03-23 09:53:48 - ERROR - [MainThread:db_password_matching(): 98] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 87, in db_password_matching
response, message = self.db_data_validation(payload["username"])
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:53:48 - ERROR - [MainThread:login_default(): 37] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 24, in login_default
return obj_login_handler.normal_login(user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 25, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.payload,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 09:54:58 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:36:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:46:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:46:55 - ERROR - [MainThread:password_decrypt(): 51] - Invalid base64-encoded string: number of data characters (57) cannot be 1 more than a multiple of 4
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 36, in password_decrypt
enc = base64.b64decode(password)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (57) cannot be 1 more than a multiple of 4
2023-03-23 10:46:55 - ERROR - [MainThread:db_password_matching(): 101] - secret must be unicode or bytes, not None
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 95, in db_password_matching
if not self.pwd_context.verify(password, self.db_user_data["password"]):
File "E:\Git\meta-services\venv\lib\site-packages\passlib\context.py", line 2347, in verify
return record.verify(secret, hash, **kwds)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 787, in verify
validate_secret(secret)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 122, in validate_secret
raise exc.ExpectedStringError(secret, "secret")
TypeError: secret must be unicode or bytes, not None
2023-03-23 10:46:55 - ERROR - [MainThread:login_default(): 35] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 28, in login_default
return login_mapper[user_data.login_type](user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 25, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.payload,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 10:49:33 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:49:55 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:50:09 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:50:39 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:51:04 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:51:20 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:51:29 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:52:19 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:52:20 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:52:25 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:55:06 - ERROR - [MainThread:password_decrypt(): 51] - 'utf-8' codec can't decode byte 0xab in position 1: invalid start byte
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 49, in password_decrypt
return data.decode(Services.ENCODING_TYPE)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xab in position 1: invalid start byte
2023-03-23 10:55:06 - ERROR - [MainThread:db_password_matching(): 103] - secret must be unicode or bytes, not None
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 97, in db_password_matching
if not self.pwd_context.verify(password, self.db_user_data["password"]):
File "E:\Git\meta-services\venv\lib\site-packages\passlib\context.py", line 2347, in verify
return record.verify(secret, hash, **kwds)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 787, in verify
validate_secret(secret)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 122, in validate_secret
raise exc.ExpectedStringError(secret, "secret")
TypeError: secret must be unicode or bytes, not None
2023-03-23 10:55:06 - ERROR - [MainThread:login_default(): 35] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 28, in login_default
return login_mapper[user_data.login_type](user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 28, in normal_login
response, data = self.obj_login_handler.db_password_matching(login_data.payload,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 10:57:32 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 10:59:57 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:15:51 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:17:30 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:29:07 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:37:00 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:38:07 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:38:52 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:45:28 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:45:33 - ERROR - [MainThread:login_default(): 38] - 'LoginRequest' object is not subscriptable
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 31, in login_default
return login_mapper[login_type](user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 16, in normal_login
decrypted_password = self.obj_login_handler.password_decrypt(user_data["password"])
TypeError: 'LoginRequest' object is not subscriptable
2023-03-23 11:48:14 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:49:01 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:49:48 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:58:26 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 11:58:29 - ERROR - [MainThread:password_decrypt(): 37] - '_Services' object has no attribute 'ENCODING_TYPE'
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\utils\security\password_decryption_util.py", line 20, in password_decrypt
key = Secrets.KEY_ENCRYPTION.encode(Services.ENCODING_TYPE)
AttributeError: '_Services' object has no attribute 'ENCODING_TYPE'
2023-03-23 11:58:29 - ERROR - [MainThread:db_password_matching(): 67] - secret must be unicode or bytes, not None
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\core\handlers\normal_login.py", line 61, in db_password_matching
if not self.pwd_context.verify(password, self.db_user_data["password"]):
File "E:\Git\meta-services\venv\lib\site-packages\passlib\context.py", line 2347, in verify
return record.verify(secret, hash, **kwds)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 787, in verify
validate_secret(secret)
File "E:\Git\meta-services\venv\lib\site-packages\passlib\utils\handlers.py", line 122, in validate_secret
raise exc.ExpectedStringError(secret, "secret")
TypeError: secret must be unicode or bytes, not None
2023-03-23 11:58:29 - ERROR - [MainThread:login_default(): 38] - cannot unpack non-iterable NoneType object
Traceback (most recent call last):
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 31, in login_default
return login_mapper[login_type](user_data, request)
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 30, in normal_login
response, data = self.obj_login_handler.db_password_matching(self.login_type, user_data,
TypeError: cannot unpack non-iterable NoneType object
2023-03-23 12:01:23 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 12:01:24 - ERROR - [MainThread:<module>(): 41] - cannot import name 'Services' from 'scripts.constants' (E:\Git\meta-services\scripts\constants\__init__.py)
Traceback (most recent call last):
File "E:\Git\meta-services\app.py", line 39, in <module>
uvicorn.run("main:app", host=arguments["bind"], port=int(arguments["port"]))
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\main.py", line 568, in run
server.run()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 59, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
return future.result()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\server.py", line 66, in serve
config.load()
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\config.py", line 471, in load
self.loaded_app = import_from_string(self.app)
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 24, in import_from_string
raise exc from None
File "E:\Git\meta-services\venv\lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
module = importlib.import_module(module_str)
File "C:\Users\arun.uday\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "E:\Git\meta-services\main.py", line 17, in <module>
from scripts.services import router
File "E:\Git\meta-services\scripts\services\__init__.py", line 2, in <module>
from scripts.services import v1
File "E:\Git\meta-services\scripts\services\v1\__init__.py", line 3, in <module>
from scripts.services.v1 import iot_manager_services
File "E:\Git\meta-services\scripts\services\v1\iot_manager_services.py", line 4, in <module>
from scripts.core.handlers.login_handler import LoginHandlers
File "E:\Git\meta-services\scripts\core\handlers\login_handler.py", line 6, in <module>
from scripts.utils.security.password_decryption_util import DecryptPassword
File "E:\Git\meta-services\scripts\utils\security\password_decryption_util.py", line 6, in <module>
from scripts.constants import Services
ImportError: cannot import name 'Services' from 'scripts.constants' (E:\Git\meta-services\scripts\constants\__init__.py)
2023-03-23 12:01:37 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 18:42:17 - INFO - [MainThread:<module>(): 37] - App Starting at 0.0.0.0:8671
2023-03-23 19:09:29 - INFO - [MainThread:<module>(): 37] - App Starting at 127.0.0.1:8671
2023-03-23 19:09:51 - INFO - [MainThread:<module>(): 37] - App Starting at 127.0.0.1:8671
2023-03-23 19:33:49 - INFO - [MainThread:<module>(): 37] - App Starting at 127.0.0.1:8671
2023-03-23 19:34:12 - INFO - [MainThread:<module>(): 37] - App Starting at 127.0.0.1:8671
...@@ -7,7 +7,7 @@ from pydantic import BaseModel ...@@ -7,7 +7,7 @@ from pydantic import BaseModel
class DefaultResponse(BaseModel): class DefaultResponse(BaseModel):
status: bool = True status: bool = True
message: Optional[str] message: Optional[str]
payload: Optional[Any] data: Optional[Any]
# default failure responses # default failure responses
......
from typing import Union
from pydantic import BaseModel, EmailStr
# model for normal login
class NormalLogin(BaseModel):
username: Union[EmailStr, None] = None
password: Union[str, None] = None
project_id: Union[str, None] = None
from typing import Union
from pydantic import BaseModel
# model for login request
class LoginRequest(BaseModel):
username: Union[str, None] = None
password: Union[str, None] = None
class RegistrationData:
name: Union[str, None] = None
email: Union[str: None] = None
password: Union[str: None] = None
user_role: Union[str: None] = None
is_alive: Union[bool: None] = None
created_at: Union[str: None] = None
from fastapi import APIRouter, status from fastapi import APIRouter, HTTPException, status, Depends
from fastapi.responses import JSONResponse
from scripts.constants.api import ApiEndPoints from scripts.constants.api import ApiEndPoints
from scripts.core.handlers.login_handler import LoginHandlers from scripts.core.handlers.login_handler import LoginHandlers
from scripts.errors import ErrorMessages
from scripts.logging.logger import logger from scripts.logging.logger import logger
from scripts.schemas.default_responses import DefaultResponse, DefaultFailureResponse from scripts.schemas.project_schema import LoginRequest
from scripts.schemas.login_schema import NormalLogin from scripts.utils.security.decorators import MetaInfoSchema, auth
# creating the login api # creating the login api
router = APIRouter(prefix=ApiEndPoints.version) router = APIRouter(prefix=ApiEndPoints.version)
...@@ -14,29 +12,35 @@ router = APIRouter(prefix=ApiEndPoints.version) ...@@ -14,29 +12,35 @@ router = APIRouter(prefix=ApiEndPoints.version)
obj_login_handler = LoginHandlers() obj_login_handler = LoginHandlers()
@router.post(ApiEndPoints.asset_manager_submit) @router.post(ApiEndPoints.asset_manager_login)
def login_default(login_data: NormalLogin): async def login_default(
login_type: str,
user_data: LoginRequest,
request: MetaInfoSchema = Depends(auth)
):
try: try:
# decrypting the password from the UI # mapper for login types
decrypted_password = obj_login_handler.password_decrypt(login_data.password) login_mapper = {
# validating the received inputs empty or not "normal": obj_login_handler.normal_login,
response = obj_login_handler.user_data_validation(login_data.username, decrypted_password) "google": obj_login_handler.google_login,
# Account is not registered "microsoft": obj_login_handler.microsoft_login
if response is not None: }
return JSONResponse(content=DefaultFailureResponse(error=response["message"]).dict(),
status_code=status.HTTP_400_BAD_REQUEST) # getting the functions based on the login types
# checking for the account and password matching if login_type in login_mapper:
response, data = obj_login_handler.db_password_matching(login_data, decrypted_password) return login_mapper[login_type](user_data, request)
if response is not None and data["message"] == ErrorMessages.ERROR_UNAUTHORIZED_USER_LOGIN: else:
return JSONResponse(content=DefaultFailureResponse(error=data).dict(), return HTTPException(
status_code=status.HTTP_404_NOT_FOUND) status_code=status.HTTP_403_FORBIDDEN,
if response is not None: detail="Invalid Request")
return JSONResponse(content=DefaultFailureResponse(error=data).dict(),
status_code=status.HTTP_401_UNAUTHORIZED)
# sending successful response to UI
return JSONResponse(
content=DefaultResponse(message="Login Successful", payload=data).dict(),
status_code=status.HTTP_200_OK)
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
@router.post(ApiEndPoints.asset_manager_user_registration)
async def user_register(
user_data: LoginRequest,
request: MetaInfoSchema = Depends(auth)
):
print(user_data, request)
class MongoQueries:
@staticmethod
def insert_user_query(login_data, project_id, hashed_password, time_dt):
query = {"project_id": project_id, "name": "", "email": login_data.username,
"password": hashed_password,
"user_role": "guest",
"is_alive": True, "created_at": time_dt,
"updated_at": time_dt}
return query
from datetime import datetime, timedelta
from scripts.config import Secrets
from scripts.database.mongo.mongo_login import MongoUser
from scripts.database.redis.redis_conn import login_db
from scripts.utils.security.jwt_util import JWT
jwt = JWT()
mongo_user = MongoUser()
def create_token(
user_id,
ip,
age=Secrets.ACCESS_TOKEN_EXPIRE_MINUTES,
):
"""
This method is to create a cookie
"""
# creating the payload
payload = {"ip": ip, "user_id": user_id, "token": Secrets.SECRET_KEY, "age": age}
# getting the current time
current_time = datetime.now()
# generating the expiry time of the token
exp = current_time + timedelta(minutes=age)
# creating the dictionary with issuer and expiry time
_extras = {"iss": Secrets.issuer, "exp": exp}
_payload = payload | _extras
# encoding the token
new_token = jwt.encode(_payload)
# Add session to redis
login_db.set(user_id, new_token)
login_db.expire(user_id, timedelta(minutes=age))
# Add updated time to mongo db
mongo_user.update_user({"email": user_id}, {"updated_at": current_time})
return user_id
from fastapi import HTTPException, Request, Response, status
from fastapi.openapi.models import APIKey, APIKeyIn
from fastapi.security import APIKeyCookie
from fastapi.security.api_key import APIKeyBase
from pydantic import BaseModel, Field
from scripts.config import Services
from scripts.database.redis.redis_conn import login_db
from scripts.errors import ErrorMessages
from scripts.logging.logger import logger
from scripts.utils.security.jwt_util import JWT
class MetaInfoSchema(BaseModel):
user_id: str = ""
ip_address: str = ""
login_type: str = ""
login_token: str = Field(alias="login-token")
class Config:
allow_population_by_field_name = True
class _CookieAuthentication(APIKeyBase):
"""
Authentication backend using a cookie.
Internally, uses a JWT token to store the data.
"""
scheme: APIKeyCookie
cookie_name: str
cookie_secure: bool
def __init__(
self,
cookie_name: str = "login-token",
):
super().__init__()
self.model: APIKey = APIKey(**{"in": APIKeyIn.cookie}, name=cookie_name)
self.scheme_name = self.__class__.__name__
self.cookie_name = cookie_name
self.scheme = APIKeyCookie(name=self.cookie_name, auto_error=False)
self.login_redis = login_db
self.jwt = JWT()
def __call__(self, request: Request, response: Response) -> MetaInfoSchema:
# getting the cookie from the request
cookies = request.cookies
# checking if the request has valid cookie
login_token = cookies.get(self.cookie_name) or request.headers.get(
self.cookie_name
)
if not login_token or login_token != Services.PROJECT_NAME:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
# if the cookie name is same as the service name
if login_token == Services.PROJECT_NAME:
return MetaInfoSchema(
ip_address=request.client.host, # type: ignore
login_token=cookies.get("login-token"),
)
# getting the token stored in redis based on the cookie value
jwt_token = self.login_redis.get(login_token)
if not jwt_token:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
try:
# validating the token
decoded_token = self.jwt.validate(token=jwt_token)
if not decoded_token:
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
except Exception as e:
logger.exception(e)
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ErrorMessages.UNKNOWN_ERROR,
)
# checking if the token has necessary fields
user_id = decoded_token.get("user_id")
if not user_id:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Token doesn't have required fields",
)
return MetaInfoSchema(
user_id=user_id,
ip_address=request.client.host, # type: ignore
login_token=cookies.get("login-token"),
)
CookieAuthentication = auth = _CookieAuthentication()
import logging
import jwt
from scripts.config import Secrets
class JWT:
def __init__(self) -> None:
self.max_login_age: int = Secrets.ACCESS_TOKEN_EXPIRE_MINUTES
self.issuer: str = Secrets.issuer
self.alg: str = Secrets.ALGORITHM
self.key = Secrets.SECRET_KEY
# encoding the payload
def encode(self, payload) -> str:
try:
return jwt.encode(payload, self.key, algorithm=self.alg)
except Exception as e:
logging.exception(f"Exception while encoding JWT: {str(e)}")
raise
# decoding the payload
def decode(self, token):
try:
return jwt.decode(token, self.key, algorithms=self.alg)
except Exception as e:
logging.exception(f"Exception while encoding JWT: {str(e)}")
raise
# validate the payload
def validate(self, token):
try:
return jwt.decode(
token,
self.key,
algorithms=self.alg,
leeway=Secrets.leeway_in_minutes,
options={"require": ["exp", "iss"]},
)
except Exception as e:
logging.exception(f"Exception while validating JWT: {str(e)}")
import base64
from Cryptodome.Cipher import AES
from scripts.config import Secrets, Services
from scripts.logging.logger import logger
class DecryptPassword:
@staticmethod
def un_pad(s):
# un_padding the encrypted password
return s[:-ord(s[len(s) - 1:])]
def password_decrypt(self, password):
try:
# encoding the Key
key = Secrets.KEY_ENCRYPTION.encode(Services.ENCODING_TYPE)
# decoding the received password
enc = base64.b64decode(password)
# mode for the decryption
mode = AES.MODE_CBC
# getting the initialization vector
iv = enc[:AES.block_size]
# decoding with AES
cipher = AES.new(key, mode, iv)
# decoding the password
data = cipher.decrypt(enc[AES.block_size:])
if len(data) == 0:
raise ValueError("Decrypted data is empty")
# removing the padding to get the password
data = self.un_pad(data)
return data.decode(Services.ENCODING_TYPE)
except Exception as e:
logger.exception(e)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment