From 52708c5ba0c11d1427e7cb0adf93dfe483143365 Mon Sep 17 00:00:00 2001 From: acazares Date: Fri, 23 Jan 2026 13:42:58 -0600 Subject: [PATCH] feat(api): integrate Sitar API configuration and authentication --- .env.example | 7 +++++-- .../general_catalogs/exchange_rate/services.py | 15 ++++++++------- backend/core/config.py | 11 +++++++---- docker-compose.yml | 6 +++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index c66ef877..8e04d045 100644 --- a/.env.example +++ b/.env.example @@ -21,14 +21,12 @@ KEYCLOAK_FRONTEND_CLIENT_ID=anexo76-frontend # ----- Backend ----- DEBUG=True ENVIRONMENT=development - CORE_DB_HOST=postgres-a76 CORE_DB_PORT=5432 CORE_DB_NAME=anexo76_core CORE_DB_USER=postgres CORE_DB_PASSWORD=postgres - # ----- Frontend ----- NODE_ENV=development VITE_API_URL=http://localhost:8000/api @@ -36,3 +34,8 @@ INTERNAL_API_URL=http://backend:8000/api VITE_KEYCLOAK_REALM=master VITE_KEYCLOAK_URL=http://localhost:8080 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 diff --git a/backend/api/v1/modules/a76/general_catalogs/exchange_rate/services.py b/backend/api/v1/modules/a76/general_catalogs/exchange_rate/services.py index 94f6e1f4..ee33f82a 100644 --- a/backend/api/v1/modules/a76/general_catalogs/exchange_rate/services.py +++ b/backend/api/v1/modules/a76/general_catalogs/exchange_rate/services.py @@ -145,10 +145,11 @@ class ExchangeRateService: return True @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""" 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} headers = {"Content-Type": "application/json"} @@ -176,9 +177,9 @@ class ExchangeRateService: Optional[float]: The exchange rate value if found, None otherwise. """ # API Credentials - API_BASE_URL = settings.EXTERNAL_API_URL - API_USER = settings.EXTERNAL_API_USER - API_PASS = settings.EXTERNAL_API_PASSWORD + API_BASE_URL = settings.SITAR_API_URL + API_USER = settings.SITAR_API_USER + API_PASS = settings.SITAR_API_PASSWORD if not API_USER or not API_PASS: 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}") # 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: print("Failed to obtain external API token") return None # 2. Fetch Exchange Rate # 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 # based on user feedback/code: 'Authorization:' . $token diff --git a/backend/core/config.py b/backend/core/config.py index 54301641..37c5d52f 100644 --- a/backend/core/config.py +++ b/backend/core/config.py @@ -43,12 +43,15 @@ class Settings(BaseSettings): LICENSE_CHECK_ENABLED: bool = True # External APIs - EXTERNAL_API_URL: str = "http://74.208.80.245:3000" - EXTERNAL_API_USER: str = "" - EXTERNAL_API_PASSWORD: str = "" + SITAR_API_URL: str = "api.sitar.aduanasoft.com:880" + SITAR_API_USER: str = "" + SITAR_API_PASSWORD: str = "" 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 diff --git a/docker-compose.yml b/docker-compose.yml index a9bcb766..498a6782 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -175,9 +175,9 @@ services: - KEYCLOAK_CLIENT_ID=${KEYCLOAK_CLIENT_ID:-anexo76-backend} - KEYCLOAK_CLIENT_SECRET=${KEYCLOAK_CLIENT_SECRET:-dev-secret} - CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:5173,http://localhost:3000} - - EXTERNAL_API_URL=${EXTERNAL_API_URL} - - EXTERNAL_API_USER=${EXTERNAL_API_USER} - - EXTERNAL_API_PASSWORD=${EXTERNAL_API_PASSWORD} + - SITAR_API_URL=${SITAR_API_URL} + - SITAR_API_USER=${SITAR_API_USER} + - SITAR_API_PASSWORD=${SITAR_API_PASSWORD} ports: - "8000:8000" depends_on: