Spaces:
Running
Running
fix errors from duplicated info and update scheme sql
Browse files- api_validator.py +15 -2
- schema.sql +45 -2
- schemaTest.sql +0 -71
- testdb.sql +0 -72
api_validator.py
CHANGED
|
@@ -6,6 +6,11 @@ import hashlib
|
|
| 6 |
import apiCall
|
| 7 |
import hashlib
|
| 8 |
import psycopg2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def validate_api_call(
|
|
@@ -238,11 +243,19 @@ def validate_api_call(
|
|
| 238 |
# Store configuration
|
| 239 |
# TODO: Implement database
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
conn = psycopg2.connect(
|
| 242 |
database="testdb",
|
| 243 |
user="postgres",
|
| 244 |
host="localhost",
|
| 245 |
-
password=
|
| 246 |
port=5432,
|
| 247 |
)
|
| 248 |
|
|
@@ -275,7 +288,7 @@ def validate_api_call(
|
|
| 275 |
False,
|
| 276 |
False,
|
| 277 |
schedule_interval_minutes,
|
| 278 |
-
|
| 279 |
created_at,
|
| 280 |
None,
|
| 281 |
),
|
|
|
|
| 6 |
import apiCall
|
| 7 |
import hashlib
|
| 8 |
import psycopg2
|
| 9 |
+
import os
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
# Load environment variables from .env file
|
| 13 |
+
load_dotenv()
|
| 14 |
|
| 15 |
|
| 16 |
def validate_api_call(
|
|
|
|
| 243 |
# Store configuration
|
| 244 |
# TODO: Implement database
|
| 245 |
|
| 246 |
+
db_password = os.getenv("DB_PASSWORD")
|
| 247 |
+
if not db_password:
|
| 248 |
+
return {
|
| 249 |
+
"success": False,
|
| 250 |
+
"message": "Database password not found in environment variables. Please set DB_PASSWORD.",
|
| 251 |
+
"config_id": None,
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
conn = psycopg2.connect(
|
| 255 |
database="testdb",
|
| 256 |
user="postgres",
|
| 257 |
host="localhost",
|
| 258 |
+
password=db_password,
|
| 259 |
port=5432,
|
| 260 |
)
|
| 261 |
|
|
|
|
| 288 |
False,
|
| 289 |
False,
|
| 290 |
schedule_interval_minutes,
|
| 291 |
+
start_datetime,
|
| 292 |
created_at,
|
| 293 |
None,
|
| 294 |
),
|
schema.sql
CHANGED
|
@@ -3,6 +3,7 @@ DROP TABLE IF EXISTS api_configurations;
|
|
| 3 |
|
| 4 |
CREATE TABLE api_configurations (
|
| 5 |
id SERIAL PRIMARY KEY,
|
|
|
|
| 6 |
mcp_api_key VARCHAR(255) NOT NULL,
|
| 7 |
name VARCHAR(255) NOT NULL,
|
| 8 |
description TEXT,
|
|
@@ -23,9 +24,51 @@ CREATE TABLE api_configurations (
|
|
| 23 |
|
| 24 |
CREATE TABLE api_call_results (
|
| 25 |
id SERIAL PRIMARY KEY,
|
| 26 |
-
config_id INTEGER REFERENCES api_configurations(
|
| 27 |
response_data JSONB,
|
| 28 |
is_successful BOOLEAN,
|
| 29 |
error_message TEXT,
|
| 30 |
called_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 31 |
-
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
CREATE TABLE api_configurations (
|
| 5 |
id SERIAL PRIMARY KEY,
|
| 6 |
+
config_id INTEGER NOT NULL UNIQUE,
|
| 7 |
mcp_api_key VARCHAR(255) NOT NULL,
|
| 8 |
name VARCHAR(255) NOT NULL,
|
| 9 |
description TEXT,
|
|
|
|
| 24 |
|
| 25 |
CREATE TABLE api_call_results (
|
| 26 |
id SERIAL PRIMARY KEY,
|
| 27 |
+
config_id INTEGER REFERENCES api_configurations(config_id) ON DELETE CASCADE,
|
| 28 |
response_data JSONB,
|
| 29 |
is_successful BOOLEAN,
|
| 30 |
error_message TEXT,
|
| 31 |
called_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
INSERT INTO api_configurations (
|
| 35 |
+
config_id, mcp_api_key, name, description, method, base_url, endpoint,
|
| 36 |
+
params, headers, additional_params,
|
| 37 |
+
is_validated, is_active, stop, schedule_interval_minutes
|
| 38 |
+
) VALUES (
|
| 39 |
+
10101,
|
| 40 |
+
'abc123xyz',
|
| 41 |
+
'Track NVDA Price',
|
| 42 |
+
'Tracking NVIDIA stock price every 20 minutes',
|
| 43 |
+
'GET',
|
| 44 |
+
'https://api.example.com',
|
| 45 |
+
'/stocks/nvda',
|
| 46 |
+
'{"interval":"1d","range":"5d"}',
|
| 47 |
+
'{"Authorization":"Bearer token"}',
|
| 48 |
+
'{}',
|
| 49 |
+
TRUE,
|
| 50 |
+
TRUE,
|
| 51 |
+
FALSE,
|
| 52 |
+
20
|
| 53 |
+
);
|
| 54 |
+
|
| 55 |
+
INSERT INTO api_call_results (
|
| 56 |
+
config_id, response_data, is_successful, error_message
|
| 57 |
+
) VALUES (
|
| 58 |
+
10101,
|
| 59 |
+
'{"symbol":"NVDA", "price":1142.50, "timestamp":"2025-06-03T14:20:00Z"}',
|
| 60 |
+
TRUE,
|
| 61 |
+
NULL
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
INSERT INTO api_call_results (
|
| 65 |
+
config_id, response_data, is_successful, error_message
|
| 66 |
+
) VALUES (
|
| 67 |
+
10101,
|
| 68 |
+
NULL,
|
| 69 |
+
FALSE,
|
| 70 |
+
'Timeout while contacting the API'
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
select * from api_configurations;
|
| 74 |
+
select * from api_call_results;
|
schemaTest.sql
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
DROP TABLE IF EXISTS api_call_results;
|
| 2 |
-
DROP TABLE IF EXISTS api_configurations;
|
| 3 |
-
|
| 4 |
-
CREATE TABLE api_configurations (
|
| 5 |
-
id SERIAL PRIMARY KEY,
|
| 6 |
-
mcp_api_key VARCHAR(255) NOT NULL,
|
| 7 |
-
name VARCHAR(255) NOT NULL,
|
| 8 |
-
description TEXT,
|
| 9 |
-
method VARCHAR(10) NOT NULL DEFAULT 'GET',
|
| 10 |
-
base_url VARCHAR(500) NOT NULL,
|
| 11 |
-
endpoint VARCHAR(500),
|
| 12 |
-
params JSONB,
|
| 13 |
-
headers JSONB,
|
| 14 |
-
additional_params JSONB,
|
| 15 |
-
is_validated BOOLEAN DEFAULT FALSE,
|
| 16 |
-
is_active BOOLEAN DEFAULT FALSE,
|
| 17 |
-
stop BOOLEAN DEFAULT FALSE,
|
| 18 |
-
schedule_interval_minutes INTEGER,
|
| 19 |
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 20 |
-
validated_at TIMESTAMP
|
| 21 |
-
);
|
| 22 |
-
|
| 23 |
-
CREATE TABLE api_call_results (
|
| 24 |
-
id SERIAL PRIMARY KEY,
|
| 25 |
-
config_id INTEGER REFERENCES api_configurations(id) ON DELETE CASCADE,
|
| 26 |
-
response_data JSONB,
|
| 27 |
-
is_successful BOOLEAN,
|
| 28 |
-
error_message TEXT,
|
| 29 |
-
called_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 30 |
-
);
|
| 31 |
-
|
| 32 |
-
INSERT INTO api_configurations (
|
| 33 |
-
mcp_api_key, name, description, method, base_url, endpoint,
|
| 34 |
-
params, headers, additional_params,
|
| 35 |
-
is_validated, is_active, stop, schedule_interval_minutes
|
| 36 |
-
) VALUES (
|
| 37 |
-
'abc123xyz',
|
| 38 |
-
'Track NVDA Price',
|
| 39 |
-
'Tracking NVIDIA stock price every 20 minutes',
|
| 40 |
-
'GET',
|
| 41 |
-
'https://api.example.com',
|
| 42 |
-
'/stocks/nvda',
|
| 43 |
-
'{"interval":"1d","range":"5d"}',
|
| 44 |
-
'{"Authorization":"Bearer token"}',
|
| 45 |
-
'{}',
|
| 46 |
-
TRUE,
|
| 47 |
-
TRUE,
|
| 48 |
-
FALSE,
|
| 49 |
-
20
|
| 50 |
-
);
|
| 51 |
-
|
| 52 |
-
INSERT INTO api_call_results (
|
| 53 |
-
config_id, response_data, is_successful, error_message
|
| 54 |
-
) VALUES (
|
| 55 |
-
1,
|
| 56 |
-
'{"symbol":"NVDA", "price":1142.50, "timestamp":"2025-06-03T14:20:00Z"}',
|
| 57 |
-
TRUE,
|
| 58 |
-
NULL
|
| 59 |
-
);
|
| 60 |
-
|
| 61 |
-
INSERT INTO api_call_results (
|
| 62 |
-
config_id, response_data, is_successful, error_message
|
| 63 |
-
) VALUES (
|
| 64 |
-
1,
|
| 65 |
-
NULL,
|
| 66 |
-
FALSE,
|
| 67 |
-
'Timeout while contacting the API'
|
| 68 |
-
);
|
| 69 |
-
|
| 70 |
-
select * from api_configurations;
|
| 71 |
-
select * from api_call_results;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testdb.sql
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
DROP TABLE IF EXISTS api_call_results;
|
| 2 |
-
DROP TABLE IF EXISTS api_configurations;
|
| 3 |
-
|
| 4 |
-
CREATE TABLE api_configurations (
|
| 5 |
-
id SERIAL PRIMARY KEY,
|
| 6 |
-
mcp_api_key VARCHAR(255) NOT NULL,
|
| 7 |
-
name VARCHAR(255) NOT NULL,
|
| 8 |
-
description TEXT,
|
| 9 |
-
method VARCHAR(10) NOT NULL DEFAULT 'GET',
|
| 10 |
-
base_url VARCHAR(500) NOT NULL,
|
| 11 |
-
endpoint VARCHAR(500),
|
| 12 |
-
params JSONB,
|
| 13 |
-
headers JSONB,
|
| 14 |
-
additional_params JSONB,
|
| 15 |
-
is_validated BOOLEAN DEFAULT FALSE,
|
| 16 |
-
is_active BOOLEAN DEFAULT FALSE,
|
| 17 |
-
stop BOOLEAN DEFAULT FALSE,
|
| 18 |
-
schedule_interval_minutes INTEGER,
|
| 19 |
-
time_to_start TIMESTAMP,
|
| 20 |
-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
| 21 |
-
validated_at TIMESTAMP
|
| 22 |
-
);
|
| 23 |
-
|
| 24 |
-
CREATE TABLE api_call_results (
|
| 25 |
-
id SERIAL PRIMARY KEY,
|
| 26 |
-
config_id INTEGER REFERENCES api_configurations(id) ON DELETE CASCADE,
|
| 27 |
-
response_data JSONB,
|
| 28 |
-
is_successful BOOLEAN,
|
| 29 |
-
error_message TEXT,
|
| 30 |
-
called_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
| 31 |
-
);
|
| 32 |
-
|
| 33 |
-
INSERT INTO api_configurations (
|
| 34 |
-
mcp_api_key, name, description, method, base_url, endpoint,
|
| 35 |
-
params, headers, additional_params,
|
| 36 |
-
is_validated, is_active, stop, schedule_interval_minutes
|
| 37 |
-
) VALUES (
|
| 38 |
-
'abc123xyz',
|
| 39 |
-
'Track NVDA Price',
|
| 40 |
-
'Tracking NVIDIA stock price every 20 minutes',
|
| 41 |
-
'GET',
|
| 42 |
-
'https://api.example.com',
|
| 43 |
-
'/stocks/nvda',
|
| 44 |
-
'{"interval":"1d","range":"5d"}',
|
| 45 |
-
'{"Authorization":"Bearer token"}',
|
| 46 |
-
'{}',
|
| 47 |
-
TRUE,
|
| 48 |
-
TRUE,
|
| 49 |
-
FALSE,
|
| 50 |
-
20
|
| 51 |
-
);
|
| 52 |
-
|
| 53 |
-
INSERT INTO api_call_results (
|
| 54 |
-
config_id, response_data, is_successful, error_message
|
| 55 |
-
) VALUES (
|
| 56 |
-
1,
|
| 57 |
-
'{"symbol":"NVDA", "price":1142.50, "timestamp":"2025-06-03T14:20:00Z"}',
|
| 58 |
-
TRUE,
|
| 59 |
-
NULL
|
| 60 |
-
);
|
| 61 |
-
|
| 62 |
-
INSERT INTO api_call_results (
|
| 63 |
-
config_id, response_data, is_successful, error_message
|
| 64 |
-
) VALUES (
|
| 65 |
-
1,
|
| 66 |
-
NULL,
|
| 67 |
-
FALSE,
|
| 68 |
-
'Timeout while contacting the API'
|
| 69 |
-
);
|
| 70 |
-
|
| 71 |
-
select * from api_configurations;
|
| 72 |
-
select * from api_call_results;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|