major claude changes
This commit is contained in:
57
app/main.py
57
app/main.py
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
@@ -11,6 +12,31 @@ elif mode == 'LOCAL':
|
|||||||
else:
|
else:
|
||||||
from settings_dev import settings
|
from settings_dev import settings
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
def setup_logging():
|
||||||
|
"""Configure structured logging for the application."""
|
||||||
|
log_level = logging.DEBUG if mode != 'PRODUCTION' else logging.INFO
|
||||||
|
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
datefmt='%Y-%m-%d %H:%M:%S'
|
||||||
|
)
|
||||||
|
|
||||||
|
root_logger = logging.getLogger()
|
||||||
|
root_logger.setLevel(log_level)
|
||||||
|
root_logger.handlers.clear()
|
||||||
|
|
||||||
|
console_handler = logging.StreamHandler(sys.stdout)
|
||||||
|
console_handler.setLevel(log_level)
|
||||||
|
console_handler.setFormatter(formatter)
|
||||||
|
root_logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
logging.getLogger('uvicorn.access').setLevel(logging.WARNING)
|
||||||
|
|
||||||
|
return logging.getLogger('eamco_voipms')
|
||||||
|
|
||||||
|
logger = setup_logging()
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from fastapi import FastAPI, HTTPException, status
|
from fastapi import FastAPI, HTTPException, status
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
@@ -19,6 +45,19 @@ from starlette.responses import JSONResponse
|
|||||||
from .voipms_client import update_did_routing, get_forwardings
|
from .voipms_client import update_did_routing, get_forwardings
|
||||||
from .database import Session
|
from .database import Session
|
||||||
from .models import Call
|
from .models import Call
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
def check_db_connection():
|
||||||
|
"""
|
||||||
|
Test database connectivity.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
db = Session()
|
||||||
|
db.execute(text("SELECT 1"))
|
||||||
|
db.close()
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
# class AuthMiddleware(BaseHTTPMiddleware):
|
# class AuthMiddleware(BaseHTTPMiddleware):
|
||||||
# async def dispatch(self, request, call_next):
|
# async def dispatch(self, request, call_next):
|
||||||
@@ -177,3 +216,21 @@ def route_to_cellphone_2():
|
|||||||
}
|
}
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def startup_event():
|
||||||
|
"""Application startup - log configuration and test DB connection."""
|
||||||
|
logger.info("🚀 eamco_voipms STARTING")
|
||||||
|
if mode in ['DEVELOPMENT', 'DEV']:
|
||||||
|
logger.info("🤖🤖🤖🤖🤖 Mode: Development 🤖🤖🤖🤖🤖")
|
||||||
|
elif mode in ['PRODUCTION', 'PROD']:
|
||||||
|
logger.info("💀💀💀💀💀💀💀💀💀💀 ⚠️ WARNING PRODUCTION 💀💀💀💀💀💀💀💀💀💀")
|
||||||
|
logger.info(f"DB: {settings.SQLALCHEMY_DATABASE_URI[:30]}...")
|
||||||
|
logger.info(f"CORS: {len(settings.origins)} origins configured")
|
||||||
|
|
||||||
|
# Test database connection
|
||||||
|
if check_db_connection():
|
||||||
|
logger.info("DB Connection: ✅ OK")
|
||||||
|
else:
|
||||||
|
logger.info("DB Connection: ❌ FAILED")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||||
@@ -9,6 +10,8 @@ if mode == 'PRODUCTION':
|
|||||||
else:
|
else:
|
||||||
from settings_dev import settings
|
from settings_dev import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from fastapi import HTTPException, status
|
from fastapi import HTTPException, status
|
||||||
|
|
||||||
@@ -80,11 +83,11 @@ def update_did_routing(did: str, routing: str):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(settings.voipms_api_url, params=params)
|
response = requests.get(settings.voipms_api_url, params=params)
|
||||||
print(f"Request URL: {response.request.url}") # Debug
|
logger.debug(f"Request URL: {response.request.url}") # Debug
|
||||||
print(f"Request Params: {params}") # Debug
|
logger.debug(f"Request Params: {params}") # Debug
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(f"VoIP.ms API Response: {data}") # Debug
|
logger.debug(f"VoIP.ms API Response: {data}") # Debug
|
||||||
|
|
||||||
if data.get("status") != "success":
|
if data.get("status") != "success":
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@@ -124,8 +127,8 @@ def get_forwardings(phone_number: str = None):
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
response = requests.get(settings.voipms_api_url, params=params)
|
response = requests.get(settings.voipms_api_url, params=params)
|
||||||
print(f"Get Forwardings Request URL: {response.request.url}")
|
logger.debug(f"Get Forwardings Request URL: {response.request.url}")
|
||||||
print(f"Get Forwardings Response: {response.json()}")
|
logger.debug(f"Get Forwardings Response: {response.json()}")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get("status") != "success":
|
if data.get("status") != "success":
|
||||||
|
|||||||
13
config.py
13
config.py
@@ -1,21 +1,20 @@
|
|||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def load_config(mode=os.environ.get('MODE')):
|
def load_config(mode=os.environ.get('MODE')):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"mode is {mode}")
|
|
||||||
if mode == 'PRODUCTION':
|
if mode == 'PRODUCTION':
|
||||||
from settings_prod import ApplicationConfig
|
from settings_prod import ApplicationConfig
|
||||||
return ApplicationConfig
|
return ApplicationConfig
|
||||||
|
|
||||||
elif mode == 'LOCAL':
|
elif mode == 'LOCAL':
|
||||||
from settings_local import ApplicationConfig
|
from settings_local import ApplicationConfig
|
||||||
return ApplicationConfig
|
return ApplicationConfig
|
||||||
|
|
||||||
elif mode == 'DEVELOPMENT':
|
elif mode == 'DEVELOPMENT':
|
||||||
print("poop")
|
|
||||||
print("poop")
|
|
||||||
print("poop")
|
|
||||||
from settings_dev import ApplicationConfig
|
from settings_dev import ApplicationConfig
|
||||||
return ApplicationConfig
|
return ApplicationConfig
|
||||||
else:
|
else:
|
||||||
@@ -23,4 +22,4 @@ def load_config(mode=os.environ.get('MODE')):
|
|||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from settings_dev import ApplicationConfig
|
from settings_dev import ApplicationConfig
|
||||||
return ApplicationConfig
|
return ApplicationConfig
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
fastapi
|
# eamco_voipms dependencies
|
||||||
uvicorn[standard]
|
# FastAPI web framework and server
|
||||||
pydantic-settings
|
fastapi==0.115.6
|
||||||
python-dotenv
|
uvicorn[standard]==0.34.0
|
||||||
requests
|
pydantic-settings==2.7.1
|
||||||
sqlalchemy
|
|
||||||
psycopg2-binary
|
# Database
|
||||||
|
SQLAlchemy==2.0.40
|
||||||
|
psycopg2-binary==2.9.10
|
||||||
|
|
||||||
|
# HTTP client
|
||||||
|
requests==2.32.3
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
python-dotenv==1.1.0
|
||||||
|
|||||||
@@ -1,43 +1,38 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
# Load environment variables from .env file
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
class ApplicationConfig:
|
class ApplicationConfig:
|
||||||
"""
|
"""
|
||||||
Basic Configuration for a generic User
|
Local Configuration (LAN deployment)
|
||||||
"""
|
"""
|
||||||
CURRENT_SETTINGS = 'LOCAL'
|
CURRENT_SETTINGS = 'LOCAL'
|
||||||
# databases info
|
|
||||||
POSTGRES_USERNAME = 'postgres'
|
# Database credentials from environment variables
|
||||||
POSTGRES_PW = 'password'
|
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||||
POSTGRES_SERVER = '192.168.1.204'
|
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||||
POSTGRES_PORT = '5432'
|
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||||
POSTGRES_DBNAME00 = 'auburnoil'
|
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||||
POSTGRES_PW,
|
|
||||||
POSTGRES_SERVER,
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||||
POSTGRES_DBNAME00
|
POSTGRES_USERNAME,
|
||||||
)
|
POSTGRES_PW,
|
||||||
|
POSTGRES_SERVER,
|
||||||
|
POSTGRES_DBNAME00
|
||||||
|
)
|
||||||
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
||||||
|
|
||||||
|
|
||||||
origins = [
|
origins = [
|
||||||
"http://192.168.1.204:9000",
|
"http://192.168.1.204:9000",
|
||||||
"http://192.168.1.204:9613",
|
"http://192.168.1.204:9613",
|
||||||
"http://192.168.1.204:9614",
|
"http://192.168.1.204:9614",
|
||||||
"http://192.168.1.204:9612",
|
"http://192.168.1.204:9612",
|
||||||
"http://192.168.1.204:9616",
|
"http://192.168.1.204:9616",
|
||||||
"http://192.168.1.204:9611",
|
"http://192.168.1.204:9611",
|
||||||
"http://192.168.1.204:9511",
|
"http://192.168.1.204:9511",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# VoIP.ms Credentials and Settings
|
||||||
# VoIP.ms Credentials and Settings
|
|
||||||
voipms_api_username = os.environ.get('VOIPMS_API_USERNAME')
|
voipms_api_username = os.environ.get('VOIPMS_API_USERNAME')
|
||||||
voipms_api_password = os.environ.get('VOIPMS_API_PASSWORD')
|
voipms_api_password = os.environ.get('VOIPMS_API_PASSWORD')
|
||||||
|
|
||||||
@@ -50,5 +45,6 @@ class ApplicationConfig:
|
|||||||
# VoIP.ms API endpoint
|
# VoIP.ms API endpoint
|
||||||
voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php")
|
voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php")
|
||||||
|
|
||||||
|
|
||||||
# Create a single instance of the settings to be used throughout the app
|
# Create a single instance of the settings to be used throughout the app
|
||||||
settings = ApplicationConfig()
|
settings = ApplicationConfig()
|
||||||
|
|||||||
@@ -1,36 +1,35 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
# Load environment variables from .env file
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
class ApplicationConfig:
|
class ApplicationConfig:
|
||||||
"""
|
"""
|
||||||
Basic Configuration for a generic User
|
Production Configuration
|
||||||
"""
|
"""
|
||||||
CURRENT_SETTINGS = 'PRODUCTION'
|
CURRENT_SETTINGS = 'PRODUCTION'
|
||||||
# databases info
|
|
||||||
POSTGRES_USERNAME = 'postgres'
|
# Database credentials from environment variables
|
||||||
POSTGRES_PW = 'password'
|
POSTGRES_USERNAME = os.environ.get('POSTGRES_USERNAME', 'postgres')
|
||||||
POSTGRES_SERVER = '192.168.1.204'
|
POSTGRES_PW = os.environ.get('POSTGRES_PW')
|
||||||
POSTGRES_PORT = '5432'
|
POSTGRES_SERVER = os.environ.get('POSTGRES_SERVER', '192.168.1.204')
|
||||||
POSTGRES_DBNAME00 = 'auburnoil'
|
POSTGRES_PORT = os.environ.get('POSTGRES_PORT', '5432')
|
||||||
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(POSTGRES_USERNAME,
|
POSTGRES_DBNAME00 = os.environ.get('POSTGRES_DBNAME', 'auburnoil')
|
||||||
POSTGRES_PW,
|
|
||||||
POSTGRES_SERVER,
|
SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||||
POSTGRES_DBNAME00
|
POSTGRES_USERNAME,
|
||||||
)
|
POSTGRES_PW,
|
||||||
|
POSTGRES_SERVER,
|
||||||
|
POSTGRES_DBNAME00
|
||||||
|
)
|
||||||
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
SQLALCHEMY_BINDS = {'auburnoil': SQLALCHEMY_DATABASE_URI}
|
||||||
|
|
||||||
origins = [
|
origins = [
|
||||||
"https://oil.edwineames.com",
|
"https://oil.edwineames.com",
|
||||||
"https://apiphone.edwineames.com",
|
"https://apiphone.edwineames.com",
|
||||||
"https://apiauto.edwineames.com",
|
"https://apiauto.edwineames.com",
|
||||||
"https://apioil.edwineames.com",
|
"https://apioil.edwineames.com",
|
||||||
|
|
||||||
]
|
]
|
||||||
# VoIP.ms Credentials and Settings
|
|
||||||
|
# VoIP.ms Credentials and Settings
|
||||||
voipms_api_username = os.environ.get('VOIPMS_API_USERNAME')
|
voipms_api_username = os.environ.get('VOIPMS_API_USERNAME')
|
||||||
voipms_api_password = os.environ.get('VOIPMS_API_PASSWORD')
|
voipms_api_password = os.environ.get('VOIPMS_API_PASSWORD')
|
||||||
|
|
||||||
@@ -43,5 +42,6 @@ class ApplicationConfig:
|
|||||||
# VoIP.ms API endpoint
|
# VoIP.ms API endpoint
|
||||||
voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php")
|
voipms_api_url = os.environ.get('VOIPMS_API_URL', "https://voip.ms/api/v1/rest.php")
|
||||||
|
|
||||||
|
|
||||||
# Create a single instance of the settings to be used throughout the app
|
# Create a single instance of the settings to be used throughout the app
|
||||||
settings = ApplicationConfig()
|
settings = ApplicationConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user