Spaces:
Running
Running
switch select to insert query to insert values to db and line changed
Browse files- api_validator.py +46 -9
api_validator.py
CHANGED
@@ -4,6 +4,7 @@ from datetime import datetime, timedelta
|
|
4 |
import hashlib
|
5 |
import psycopg2
|
6 |
|
|
|
7 |
def validate_api_call(
|
8 |
mcp_api_key,
|
9 |
name,
|
@@ -235,21 +236,56 @@ def validate_api_call(
|
|
235 |
# TODO: Implement database
|
236 |
|
237 |
conn = psycopg2.connect(
|
238 |
-
database
|
239 |
-
user
|
240 |
-
host=
|
241 |
-
password
|
242 |
-
port
|
243 |
)
|
|
|
244 |
cur = conn.cursor()
|
245 |
-
cur.execute('select * from api_configurations')
|
246 |
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
conn.commit()
|
249 |
-
|
|
|
250 |
for row in rows:
|
251 |
print(row)
|
252 |
-
|
|
|
|
|
253 |
|
254 |
# Return success response
|
255 |
return {
|
@@ -331,6 +367,7 @@ def setup_scheduler(config_id, mcp_api_key):
|
|
331 |
"config_id": config_id,
|
332 |
}
|
333 |
|
|
|
334 |
## testing
|
335 |
if __name__ == "__main__":
|
336 |
# Example usage
|
|
|
4 |
import hashlib
|
5 |
import psycopg2
|
6 |
|
7 |
+
|
8 |
def validate_api_call(
|
9 |
mcp_api_key,
|
10 |
name,
|
|
|
236 |
# TODO: Implement database
|
237 |
|
238 |
conn = psycopg2.connect(
|
239 |
+
database="testdb",
|
240 |
+
user="postgres",
|
241 |
+
host="localhost",
|
242 |
+
password="12345",
|
243 |
+
port=5432,
|
244 |
)
|
245 |
+
|
246 |
cur = conn.cursor()
|
|
|
247 |
|
248 |
+
cur.execute(
|
249 |
+
"""
|
250 |
+
INSERT INTO api_configurations (
|
251 |
+
id, mcp_api_key, name, description, method,
|
252 |
+
base_url, endpoint, params, headers, additional_params,
|
253 |
+
is_validated, is_active, stop, schedule_interval_minutes,
|
254 |
+
time_to_start, created_at, validated_at
|
255 |
+
) VALUES (
|
256 |
+
%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
|
257 |
+
%s, %s, %s, %s, %s, %s, %s
|
258 |
+
)
|
259 |
+
""",
|
260 |
+
(
|
261 |
+
config_id,
|
262 |
+
mcp_api_key,
|
263 |
+
name,
|
264 |
+
description,
|
265 |
+
method,
|
266 |
+
base_url,
|
267 |
+
endpoint,
|
268 |
+
json.dumps(apiCall.parse_key_value_string(param_keys_values)),
|
269 |
+
json.dumps(apiCall.parse_key_value_string(header_keys_values)),
|
270 |
+
additional_params,
|
271 |
+
False,
|
272 |
+
False,
|
273 |
+
False,
|
274 |
+
schedule_interval_minutes,
|
275 |
+
start_datetime,
|
276 |
+
created_at,
|
277 |
+
None,
|
278 |
+
),
|
279 |
+
)
|
280 |
+
|
281 |
conn.commit()
|
282 |
+
cur.execute("SELECT * FROM api_configurations WHERE id = %s", (config_id,))
|
283 |
+
rows = cur.fetchall()
|
284 |
for row in rows:
|
285 |
print(row)
|
286 |
+
|
287 |
+
conn.close()
|
288 |
+
cur.close()
|
289 |
|
290 |
# Return success response
|
291 |
return {
|
|
|
367 |
"config_id": config_id,
|
368 |
}
|
369 |
|
370 |
+
|
371 |
## testing
|
372 |
if __name__ == "__main__":
|
373 |
# Example usage
|