Record request, response, status, & logs for http function invocations
This commit is contained in:
14
app.py
14
app.py
@@ -183,7 +183,7 @@ def execute_http_function(function):
|
|||||||
code = http_function['script_content']
|
code = http_function['script_content']
|
||||||
environment = http_function['environment_info']
|
environment = http_function['environment_info']
|
||||||
|
|
||||||
request_obj = {
|
request_data = {
|
||||||
'method': request.method,
|
'method': request.method,
|
||||||
'headers': dict(request.headers),
|
'headers': dict(request.headers),
|
||||||
'url': request.url,
|
'url': request.url,
|
||||||
@@ -192,26 +192,28 @@ def execute_http_function(function):
|
|||||||
|
|
||||||
# Add JSON data if it exists
|
# Add JSON data if it exists
|
||||||
if request.is_json:
|
if request.is_json:
|
||||||
request_obj['json'] = request.get_json()
|
request_data['json'] = request.get_json()
|
||||||
|
|
||||||
# Add form data if it exists
|
# Add form data if it exists
|
||||||
if request.form:
|
if request.form:
|
||||||
request_obj['form'] = request.form.to_dict()
|
request_data['form'] = request.form.to_dict()
|
||||||
|
|
||||||
# Add query parameters if they exist
|
# Add query parameters if they exist
|
||||||
if request.args:
|
if request.args:
|
||||||
request_obj['query'] = request.args.to_dict()
|
request_data['query'] = request.args.to_dict()
|
||||||
|
|
||||||
# Add plain text data if it exists
|
# Add plain text data if it exists
|
||||||
if request.data and not request.is_json:
|
if request.data and not request.is_json:
|
||||||
request_obj['text'] = request.data.decode('utf-8')
|
request_data['text'] = request.data.decode('utf-8')
|
||||||
|
|
||||||
# Call the Node.js API
|
# Call the Node.js API
|
||||||
response = requests.post(API_URL, json={'code': code, 'request': request_obj, 'environment': environment})
|
response = requests.post(API_URL, json={'code': code, 'request': request_data, 'environment': environment})
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|
||||||
db.update_http_function_environment_info_and_invoked_count(function, json.dumps(response_data['environment']))
|
db.update_http_function_environment_info_and_invoked_count(function, json.dumps(response_data['environment']))
|
||||||
|
|
||||||
|
db.add_http_function_invocation(http_function['id'], response_data['status'], request_data, response_data['result'], response_data['logs'])
|
||||||
|
|
||||||
# Map the Node.js response to Flask response
|
# Map the Node.js response to Flask response
|
||||||
flask_response = map_isolator_response_to_flask_response(response_data)
|
flask_response = map_isolator_response_to_flask_response(response_data)
|
||||||
return flask_response
|
return flask_response
|
||||||
|
|||||||
5
db.py
5
db.py
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2.extras import RealDictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
@@ -71,3 +72,7 @@ class DataBase():
|
|||||||
def delete_http_function(self, name):
|
def delete_http_function(self, name):
|
||||||
self.execute(
|
self.execute(
|
||||||
'DELETE FROM http_functions WHERE NAME=%s', [name], commit=True)
|
'DELETE FROM http_functions WHERE NAME=%s', [name], commit=True)
|
||||||
|
|
||||||
|
def add_http_function_invocation(self, http_function_id, status, request_data, response_data, logs):
|
||||||
|
self.execute(
|
||||||
|
'INSERT INTO http_function_invocations (http_function_id, status, request_data, response_data, logs) VALUES (%s, %s, %s, %s)', [http_function_id, status, json.dumps(request_data), json.dumps(response_data), json.dumps(logs)], commit=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user