microservice-chassis-grupo2 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of microservice-chassis-grupo2 might be problematic. Click here for more details.
- microservice_chassis_grupo2/__init__.py +0 -0
- microservice_chassis_grupo2/core/__init__.py +0 -0
- microservice_chassis_grupo2/core/config.py +8 -0
- microservice_chassis_grupo2/core/dependencies.py +40 -0
- microservice_chassis_grupo2/core/rabbitmq_core.py +17 -0
- microservice_chassis_grupo2/core/router_utils.py +18 -0
- microservice_chassis_grupo2/core/security.py +26 -0
- microservice_chassis_grupo2/sql/__init__.py +0 -0
- microservice_chassis_grupo2/sql/database.py +24 -0
- microservice_chassis_grupo2/sql/models.py +30 -0
- {microservice_chassis_grupo2-0.1.1.dist-info → microservice_chassis_grupo2-0.1.2.dist-info}/METADATA +1 -1
- microservice_chassis_grupo2-0.1.2.dist-info/RECORD +14 -0
- microservice_chassis_grupo2-0.1.2.dist-info/top_level.txt +1 -0
- microservice_chassis_grupo2-0.1.1.dist-info/RECORD +0 -4
- microservice_chassis_grupo2-0.1.1.dist-info/top_level.txt +0 -1
- {microservice_chassis_grupo2-0.1.1.dist-info → microservice_chassis_grupo2-0.1.2.dist-info}/WHEEL +0 -0
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from fastapi import Depends, HTTPException, status
|
|
3
|
+
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
|
4
|
+
from security import decode_token
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
auth_scheme = HTTPBearer()
|
|
8
|
+
|
|
9
|
+
# Database #########################################################################################
|
|
10
|
+
async def get_db():
|
|
11
|
+
"""Generates database sessions and closes them when finished."""
|
|
12
|
+
from sql.database import SessionLocal
|
|
13
|
+
logger.debug("Getting database SessionLocal")
|
|
14
|
+
db = SessionLocal()
|
|
15
|
+
try:
|
|
16
|
+
yield db
|
|
17
|
+
await db.commit()
|
|
18
|
+
except:
|
|
19
|
+
await db.rollback()
|
|
20
|
+
finally:
|
|
21
|
+
await db.close()
|
|
22
|
+
|
|
23
|
+
async def get_current_user(
|
|
24
|
+
credentials: HTTPAuthorizationCredentials = Depends(auth_scheme)
|
|
25
|
+
):
|
|
26
|
+
"""
|
|
27
|
+
Decodifica el JWT y obtiene el usuario actual desde la base de datos.
|
|
28
|
+
"""
|
|
29
|
+
token = credentials.credentials
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
payload = decode_token(token)
|
|
33
|
+
except ValueError:
|
|
34
|
+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Token inválido")
|
|
35
|
+
|
|
36
|
+
user_id = payload.get("user_id")
|
|
37
|
+
if not user_id:
|
|
38
|
+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Token inválido")
|
|
39
|
+
|
|
40
|
+
return user_id
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from aio_pika import connect_robust, ExchangeType
|
|
2
|
+
from config import settings
|
|
3
|
+
|
|
4
|
+
async def get_channel():
|
|
5
|
+
connection = await connect_robust(settings.RABBITMQ_HOST)
|
|
6
|
+
channel = await connection.channel()
|
|
7
|
+
|
|
8
|
+
return channel
|
|
9
|
+
|
|
10
|
+
async def declare_exchange(channel):
|
|
11
|
+
exchange = channel.declare_exchange(
|
|
12
|
+
settings.EXCHANGE_NAME,
|
|
13
|
+
ExchangeType.TOPIC,
|
|
14
|
+
durable=True
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return exchange
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Util/Helper functions for router definitions."""
|
|
3
|
+
import logging
|
|
4
|
+
from fastapi import HTTPException
|
|
5
|
+
|
|
6
|
+
ORDER_SERVICE_URL = "https://order:5000"
|
|
7
|
+
MACHINE_SERVICE_URL = "https://machine:5001"
|
|
8
|
+
DELIVERY_SERVICE_URL = "https://delivery:5002"
|
|
9
|
+
PAYMENT_SERVICE_URL = "https://payment:5003"
|
|
10
|
+
AUTH_SERVICE_URL = "https://auth:5004"
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def raise_and_log_error(my_logger, status_code: int, message: str):
|
|
16
|
+
"""Raises HTTPException and logs an error."""
|
|
17
|
+
my_logger.error(message)
|
|
18
|
+
raise HTTPException(status_code, message)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import jwt
|
|
2
|
+
import os
|
|
3
|
+
from fastapi import HTTPException
|
|
4
|
+
#from config import settings
|
|
5
|
+
|
|
6
|
+
PUBLIC_KEY_PATH = "/home/pyuser/code/auth_public.pem"
|
|
7
|
+
|
|
8
|
+
def read_public_pem():
|
|
9
|
+
if not os.path.exists(PUBLIC_KEY_PATH):
|
|
10
|
+
print("no hay")
|
|
11
|
+
print(PUBLIC_KEY_PATH)
|
|
12
|
+
raise ValueError(f"Public key not found at {PUBLIC_KEY_PATH}")
|
|
13
|
+
with open(PUBLIC_KEY_PATH, "r", encoding="utf-8") as f:
|
|
14
|
+
return f.read()
|
|
15
|
+
|
|
16
|
+
def decode_token(token: str) -> dict:
|
|
17
|
+
try:
|
|
18
|
+
public_pem = read_public_pem()
|
|
19
|
+
payload = jwt.decode(token, public_pem, algorithms=["RS256"])
|
|
20
|
+
return payload
|
|
21
|
+
except FileNotFoundError as e:
|
|
22
|
+
raise HTTPException(status_code=500, detail="Public key file not found")
|
|
23
|
+
except ValueError as e:
|
|
24
|
+
raise HTTPException(status_code=401, detail=str(e))
|
|
25
|
+
except Exception as e:
|
|
26
|
+
raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}")
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
3
|
+
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
|
4
|
+
|
|
5
|
+
SQLALCHEMY_DATABASE_URL = os.getenv(
|
|
6
|
+
'SQLALCHEMY_DATABASE_URL',
|
|
7
|
+
"sqlite+aiosqlite:///./default.db"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
engine = create_async_engine(
|
|
11
|
+
SQLALCHEMY_DATABASE_URL,
|
|
12
|
+
connect_args={"check_same_thread": False},
|
|
13
|
+
echo=False
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
SessionLocal = sessionmaker(
|
|
17
|
+
autocommit=False,
|
|
18
|
+
autoflush=False,
|
|
19
|
+
bind=engine,
|
|
20
|
+
class_=AsyncSession,
|
|
21
|
+
future=True
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
Base = declarative_base()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from sqlalchemy import Column, DateTime
|
|
2
|
+
from sqlalchemy.sql import func
|
|
3
|
+
from .database import Base
|
|
4
|
+
|
|
5
|
+
class BaseModel(Base):
|
|
6
|
+
"""Base database table representation to reuse."""
|
|
7
|
+
__abstract__ = True
|
|
8
|
+
creation_date = Column(DateTime(timezone=True), server_default=func.now())
|
|
9
|
+
update_date = Column(DateTime, nullable=False, server_default=func.now(), onupdate=func.now())
|
|
10
|
+
|
|
11
|
+
def __repr__(self):
|
|
12
|
+
fields = ""
|
|
13
|
+
for column in self.__table__.columns:
|
|
14
|
+
if fields == "":
|
|
15
|
+
fields = f"{column.name}='{getattr(self, column.name)}'"
|
|
16
|
+
# fields = "{}='{}'".format(column.name, getattr(self, column.name))
|
|
17
|
+
else:
|
|
18
|
+
fields = f"{fields}, {column.name}='{getattr(self, column.name)}'"
|
|
19
|
+
# fields = "{}, {}='{}'".format(fields, column.name, getattr(self, column.name))
|
|
20
|
+
return f"<{self.__class__.__name__}({fields})>"
|
|
21
|
+
# return "<{}({})>".format(self.__class__.__name__, fields)
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
def list_as_dict(items):
|
|
25
|
+
"""Returns list of items as dict."""
|
|
26
|
+
return [i.as_dict() for i in items]
|
|
27
|
+
|
|
28
|
+
def as_dict(self):
|
|
29
|
+
"""Return the item as dict."""
|
|
30
|
+
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
microservice_chassis_grupo2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
microservice_chassis_grupo2/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
microservice_chassis_grupo2/core/config.py,sha256=bkjF0txKEAXOV_J619bfGr1D5F98gpbu_-A0JO1qcGQ,154
|
|
4
|
+
microservice_chassis_grupo2/core/dependencies.py,sha256=F3Q0ywvF0BS7lm-cmDq0PLLG7qlXTjQcR79Z43Isd28,1244
|
|
5
|
+
microservice_chassis_grupo2/core/rabbitmq_core.py,sha256=4-UgMegDB9JlQ1X5jv9W7M96n-Mbp8sVi61fSzmiGgA,417
|
|
6
|
+
microservice_chassis_grupo2/core/router_utils.py,sha256=QFsCu4lNJIGKs-oz5_oRqjXya03qqstK_aljtINCuI4,575
|
|
7
|
+
microservice_chassis_grupo2/core/security.py,sha256=HO6hWggMWg_JbndIALzm9C8wGgrmrS_a74peCLkzLZw,910
|
|
8
|
+
microservice_chassis_grupo2/sql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
microservice_chassis_grupo2/sql/database.py,sha256=bF9thqg2dcx_iJtUXPdvaIkc8AkSQqRwawfsGzJ41ok,530
|
|
10
|
+
microservice_chassis_grupo2/sql/models.py,sha256=ODheJMFCAGpd-SRqD2R1qiEBFadeirsjzcecOKT3xVo,1258
|
|
11
|
+
microservice_chassis_grupo2-0.1.2.dist-info/METADATA,sha256=DeaSF_jllaoUOYv6XW17iwFt5NvD6IvpZsXzSuPGlbU,249
|
|
12
|
+
microservice_chassis_grupo2-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
microservice_chassis_grupo2-0.1.2.dist-info/top_level.txt,sha256=gAbQlQALJPI7wCWahNa12XvGlherC3Jf9C2X4Y80DXU,28
|
|
14
|
+
microservice_chassis_grupo2-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
microservice_chassis_grupo2
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
microservice_chassis_grupo2-0.1.1.dist-info/METADATA,sha256=sT9FefPRru5WbMSOG9U_BE7mdTyXCjK7HLUuqNH73Dw,249
|
|
2
|
-
microservice_chassis_grupo2-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
3
|
-
microservice_chassis_grupo2-0.1.1.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
-
microservice_chassis_grupo2-0.1.1.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
{microservice_chassis_grupo2-0.1.1.dist-info → microservice_chassis_grupo2-0.1.2.dist-info}/WHEEL
RENAMED
|
File without changes
|