feat(api): integrate Sitar API configuration and authentication
This commit is contained in:
@@ -21,14 +21,12 @@ KEYCLOAK_FRONTEND_CLIENT_ID=anexo76-frontend
|
|||||||
# ----- Backend -----
|
# ----- Backend -----
|
||||||
DEBUG=True
|
DEBUG=True
|
||||||
ENVIRONMENT=development
|
ENVIRONMENT=development
|
||||||
|
|
||||||
CORE_DB_HOST=postgres-a76
|
CORE_DB_HOST=postgres-a76
|
||||||
CORE_DB_PORT=5432
|
CORE_DB_PORT=5432
|
||||||
CORE_DB_NAME=anexo76_core
|
CORE_DB_NAME=anexo76_core
|
||||||
CORE_DB_USER=postgres
|
CORE_DB_USER=postgres
|
||||||
CORE_DB_PASSWORD=postgres
|
CORE_DB_PASSWORD=postgres
|
||||||
|
|
||||||
|
|
||||||
# ----- Frontend -----
|
# ----- Frontend -----
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
VITE_API_URL=http://localhost:8000/api
|
VITE_API_URL=http://localhost:8000/api
|
||||||
@@ -36,3 +34,8 @@ INTERNAL_API_URL=http://backend:8000/api
|
|||||||
VITE_KEYCLOAK_REALM=master
|
VITE_KEYCLOAK_REALM=master
|
||||||
VITE_KEYCLOAK_URL=http://localhost:8080
|
VITE_KEYCLOAK_URL=http://localhost:8080
|
||||||
VITE_KEYCLOAK_CLIENT_ID=anexo76-frontend
|
VITE_KEYCLOAK_CLIENT_ID=anexo76-frontend
|
||||||
|
|
||||||
|
# ----- Sitar API -----
|
||||||
|
SITAR_API_URL=http://api.sitar.aduanasoft.com
|
||||||
|
SITAR_API_USER=your_sitar_user
|
||||||
|
SITAR_API_PASSWORD=your_sitar_password
|
||||||
|
|||||||
@@ -145,10 +145,11 @@ class ExchangeRateService:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_external_api_token(base_url, username, password) -> Optional[str]:
|
def _get_sitar_api_token(base_url, username, password) -> Optional[str]:
|
||||||
"""Helper to get authentication token from external API"""
|
"""Helper to get authentication token from external API"""
|
||||||
try:
|
try:
|
||||||
login_url = f"{base_url}/auth/login"
|
print(base_url)
|
||||||
|
login_url = f"{base_url}/exchange-rate/auth/login"
|
||||||
payload = {"username": username, "password": password}
|
payload = {"username": username, "password": password}
|
||||||
headers = {"Content-Type": "application/json"}
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
@@ -176,9 +177,9 @@ class ExchangeRateService:
|
|||||||
Optional[float]: The exchange rate value if found, None otherwise.
|
Optional[float]: The exchange rate value if found, None otherwise.
|
||||||
"""
|
"""
|
||||||
# API Credentials
|
# API Credentials
|
||||||
API_BASE_URL = settings.EXTERNAL_API_URL
|
API_BASE_URL = settings.SITAR_API_URL
|
||||||
API_USER = settings.EXTERNAL_API_USER
|
API_USER = settings.SITAR_API_USER
|
||||||
API_PASS = settings.EXTERNAL_API_PASSWORD
|
API_PASS = settings.SITAR_API_PASSWORD
|
||||||
|
|
||||||
if not API_USER or not API_PASS:
|
if not API_USER or not API_PASS:
|
||||||
print("ERROR: External API credentials not properly configured in settings")
|
print("ERROR: External API credentials not properly configured in settings")
|
||||||
@@ -188,14 +189,14 @@ class ExchangeRateService:
|
|||||||
print(f"DEBUG: Fetching External API for date: {date_str}")
|
print(f"DEBUG: Fetching External API for date: {date_str}")
|
||||||
|
|
||||||
# 1. Get Token
|
# 1. Get Token
|
||||||
token = ExchangeRateService._get_external_api_token(API_BASE_URL, API_USER, API_PASS)
|
token = ExchangeRateService._get_sitar_api_token(API_BASE_URL, API_USER, API_PASS)
|
||||||
if not token:
|
if not token:
|
||||||
print("Failed to obtain external API token")
|
print("Failed to obtain external API token")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 2. Fetch Exchange Rate
|
# 2. Fetch Exchange Rate
|
||||||
# The API endpoint is /tipoCambio/{YYYY-MM-DD}
|
# The API endpoint is /tipoCambio/{YYYY-MM-DD}
|
||||||
tc_endpoint = f"{API_BASE_URL}/tipoCambio/{date_str}"
|
tc_endpoint = f"{API_BASE_URL}/exchange-rate/tipoCambio/{date_str}"
|
||||||
|
|
||||||
# Auth header: The API expects just the token string in common usage, but we try standard first
|
# Auth header: The API expects just the token string in common usage, but we try standard first
|
||||||
# based on user feedback/code: 'Authorization:' . $token
|
# based on user feedback/code: 'Authorization:' . $token
|
||||||
|
|||||||
@@ -43,12 +43,15 @@ class Settings(BaseSettings):
|
|||||||
LICENSE_CHECK_ENABLED: bool = True
|
LICENSE_CHECK_ENABLED: bool = True
|
||||||
|
|
||||||
# External APIs
|
# External APIs
|
||||||
EXTERNAL_API_URL: str = "http://74.208.80.245:3000"
|
SITAR_API_URL: str = "api.sitar.aduanasoft.com:880"
|
||||||
EXTERNAL_API_USER: str = ""
|
SITAR_API_USER: str = ""
|
||||||
EXTERNAL_API_PASSWORD: str = ""
|
SITAR_API_PASSWORD: str = ""
|
||||||
|
|
||||||
model_config = SettingsConfigDict(
|
model_config = SettingsConfigDict(
|
||||||
env_file=[".env", "../.env"], case_sensitive=True, extra="ignore", env_file_encoding="utf-8"
|
env_file=[".env", "../.env"],
|
||||||
|
case_sensitive=True,
|
||||||
|
extra="ignore",
|
||||||
|
env_file_encoding="utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -175,9 +175,9 @@ services:
|
|||||||
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend}
|
- KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend}
|
||||||
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret}
|
- KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret}
|
||||||
- CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:5173,http://localhost:3000}
|
- CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:5173,http://localhost:3000}
|
||||||
- EXTERNAL_API_URL=${EXTERNAL_API_URL}
|
- SITAR_API_URL=${SITAR_API_URL}
|
||||||
- EXTERNAL_API_USER=${EXTERNAL_API_USER}
|
- SITAR_API_USER=${SITAR_API_USER}
|
||||||
- EXTERNAL_API_PASSWORD=${EXTERNAL_API_PASSWORD}
|
- SITAR_API_PASSWORD=${SITAR_API_PASSWORD}
|
||||||
ports:
|
ports:
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
Reference in New Issue
Block a user