[add]: bank call auth endpoint
This commit is contained in:
@@ -8,6 +8,45 @@ import logging
|
|||||||
class SimbrellaIntegration:
|
class SimbrellaIntegration:
|
||||||
BASE_URL = settings.SIMBRELLA_BASE_URL
|
BASE_URL = settings.SIMBRELLA_BASE_URL
|
||||||
ENDPOINT_RAC_CHECKS = settings.SIMBRELLA_ENDPOINT_RAC_CHECKS
|
ENDPOINT_RAC_CHECKS = settings.SIMBRELLA_ENDPOINT_RAC_CHECKS
|
||||||
|
HEALTH_ENDPOINT = settings.SIMBRELLA_HEALTH
|
||||||
|
AUTH_ENDPOINT = settings.BANK_CALL_AUTH_ENDPOINT
|
||||||
|
|
||||||
|
_access_token = None # cache token in memory
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_token():
|
||||||
|
"""
|
||||||
|
Generate a new access token using the username and password from settings.
|
||||||
|
"""
|
||||||
|
url = f"{SimbrellaIntegration.BASE_URL}{SimbrellaIntegration.AUTH_ENDPOINT}"
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"username": settings.BANK_CALL_USERNAME,
|
||||||
|
"password": settings.BANK_CALL_PASSWORD,
|
||||||
|
"grant_type": "password"
|
||||||
|
}
|
||||||
|
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
try:
|
||||||
|
logger.info(f"Requesting token from {url}")
|
||||||
|
|
||||||
|
response = httpx.post(url, json=payload, headers=headers, timeout=10.0)
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
SimbrellaIntegration._access_token = data.get("access_token")
|
||||||
|
|
||||||
|
if not SimbrellaIntegration._access_token:
|
||||||
|
raise Exception("Access token not found in response")
|
||||||
|
|
||||||
|
logger.info("Successfully retrieved access token")
|
||||||
|
return SimbrellaIntegration._access_token
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Token generation failed: {str(e)}", exc_info=True)
|
||||||
|
raise Exception(f"Token generation failed: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def rac_check(customer_id, account_id, transaction_id):
|
def rac_check(customer_id, account_id, transaction_id):
|
||||||
@@ -28,8 +67,7 @@ class SimbrellaIntegration:
|
|||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"x-api-key": f"{settings.VALID_API_KEY}",
|
"Authorization": f"Bearer {SimbrellaIntegration._access_token}"
|
||||||
"App-Id": f"{settings.VALID_APP_ID}",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -43,3 +81,25 @@ class SimbrellaIntegration:
|
|||||||
logger.error(f"RACCheck API call failed: {str(e)}", exc_info=True)
|
logger.error(f"RACCheck API call failed: {str(e)}", exc_info=True)
|
||||||
raise Exception(f"RACCheck API call failed: {str(e)}")
|
raise Exception(f"RACCheck API call failed: {str(e)}")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def health_check():
|
||||||
|
"""
|
||||||
|
Health check for Simbrella Service
|
||||||
|
"""
|
||||||
|
|
||||||
|
url = f"{SimbrellaIntegration.BASE_URL}/{SimbrellaIntegration.HEALTH_ENDPOINT}"
|
||||||
|
logger.info(f"Simbrella Health Check URL: {url}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": f"Bearer {SimbrellaIntegration._access_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
response = httpx.get(url, headers=headers, timeout=10.0)
|
||||||
|
logger.info(f"Simbrella Health Check Response: {response.text}")
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Simbrella Health Check API call failed: {str(e)}", exc_info=True)
|
||||||
|
raise Exception(f"Simbrella Health Check API call failed: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from sqlite3 import DatabaseError
|
|
||||||
from app.api.integrations.events_service import EventServiceIntegration
|
from app.api.integrations.events_service import EventServiceIntegration
|
||||||
|
from app.api.integrations.simbrella import SimbrellaIntegration
|
||||||
from flask import Blueprint, request, jsonify, send_from_directory
|
from flask import Blueprint, request, jsonify, send_from_directory
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
EligibilityCheckService,
|
EligibilityCheckService,
|
||||||
@@ -125,6 +125,7 @@ def health_check():
|
|||||||
response = {}
|
response = {}
|
||||||
db_status = "Connection Successful"
|
db_status = "Connection Successful"
|
||||||
events_service_status = "Connection Successful"
|
events_service_status = "Connection Successful"
|
||||||
|
bank_status = "Connection Successful"
|
||||||
errors = []
|
errors = []
|
||||||
status = "ok"
|
status = "ok"
|
||||||
|
|
||||||
@@ -162,11 +163,26 @@ def health_check():
|
|||||||
status = "failed"
|
status = "failed"
|
||||||
errors.append(f"Events Service connection failed: {str(e)}")
|
errors.append(f"Events Service connection failed: {str(e)}")
|
||||||
|
|
||||||
|
# Check Emulator health
|
||||||
|
try:
|
||||||
|
emulator_response = SimbrellaIntegration.health_check()
|
||||||
|
|
||||||
|
if emulator_response.status_code != 200:
|
||||||
|
bank_status = "Connection Failed"
|
||||||
|
status = "failed"
|
||||||
|
errors.append(f"Emulator response: {emulator_response.text}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
bank_status = "Connection Failed"
|
||||||
|
status = "failed"
|
||||||
|
errors.append(f"Emulator connection failed: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"status": status,
|
"status": status,
|
||||||
"db_status": db_status,
|
"db_status": db_status,
|
||||||
"events_service_status": events_service_status,
|
"events_service_status": events_service_status,
|
||||||
|
"bank_status": bank_status,
|
||||||
"db_uri": db_uri,
|
"db_uri": db_uri,
|
||||||
"errors": errors or None
|
"errors": errors or None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user