Delete modules/db_connection.py
Browse files- modules/db_connection.py +0 -38
modules/db_connection.py
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
#/modules/db_connections.py
|
2 |
-
import requests
|
3 |
-
import os
|
4 |
-
import logging
|
5 |
-
|
6 |
-
def call_azure_function(operation, data):
|
7 |
-
function_url = os.getenv('AZURE_FUNCTION_URL')
|
8 |
-
api_key = os.getenv('AZURE_FUNCTION_API_KEY')
|
9 |
-
|
10 |
-
if not function_url or not api_key:
|
11 |
-
logging.error("AZURE_FUNCTION_URL or AZURE_FUNCTION_API_KEY is not set")
|
12 |
-
raise ValueError("Azure Function URL or API Key is not configured")
|
13 |
-
|
14 |
-
logging.info(f"Calling Azure Function: {function_url}")
|
15 |
-
logging.info(f"Operation: {operation}")
|
16 |
-
logging.info(f"Data: {data}")
|
17 |
-
|
18 |
-
headers = {
|
19 |
-
'Content-Type': 'application/json',
|
20 |
-
'x-functions-key': api_key
|
21 |
-
}
|
22 |
-
|
23 |
-
try:
|
24 |
-
response = requests.post(function_url, json={'operation': operation, 'data': data}, headers=headers)
|
25 |
-
logging.info(f"Response status code: {response.status_code}")
|
26 |
-
logging.info(f"Response content: {response.text}")
|
27 |
-
|
28 |
-
if response.status_code == 200:
|
29 |
-
return response.json()
|
30 |
-
elif response.status_code == 401:
|
31 |
-
logging.error("Authentication failed. Check if the API key is correct.")
|
32 |
-
raise Exception("Authentication failed. Check if the API key is correct.")
|
33 |
-
else:
|
34 |
-
logging.error(f"Error calling Azure Function: {response.text}")
|
35 |
-
raise Exception(f"Error calling Azure Function: {response.text}")
|
36 |
-
except requests.exceptions.RequestException as e:
|
37 |
-
logging.error(f"Request exception: {str(e)}")
|
38 |
-
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|