#400: Fixed additional issues with JSON keys. NOT in public testing yet, as this may be breaking changes for JSON

This commit is contained in:
frikky
2022-03-15 23:05:25 +01:00
parent 80239913d8
commit 7140ce9a1c
7 changed files with 82 additions and 55 deletions
+51 -26
View File
@@ -15,6 +15,7 @@ import requests
import http.client import http.client
import urllib.parse import urllib.parse
import jinja2 import jinja2
import datetime
from io import StringIO as StringBuffer from io import StringIO as StringBuffer
from io import BytesIO from io import BytesIO
from liquid import Liquid, defaults from liquid import Liquid, defaults
@@ -125,11 +126,12 @@ class AppBase:
def __init__(self, redis=None, logger=None, console_logger=None):#, docker_client=None): def __init__(self, redis=None, logger=None, console_logger=None):#, docker_client=None):
self.logger = logger if logger is not None else logging.getLogger("AppBaseLogger") self.logger = logger if logger is not None else logging.getLogger("AppBaseLogger")
self.log_capture_string = StringBuffer()
ch = logging.StreamHandler(self.log_capture_string) #self.log_capture_string = StringBuffer()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') #ch = logging.StreamHandler(self.log_capture_string)
ch.setFormatter(formatter) #formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger.addHandler(ch) #ch.setFormatter(formatter)
#logger.addHandler(ch)
self.redis=redis self.redis=redis
self.console_logger = logger if logger is not None else logging.getLogger("AppBaseLogger") self.console_logger = logger if logger is not None else logging.getLogger("AppBaseLogger")
@@ -294,12 +296,14 @@ class AppBase:
# I wonder if this actually works # I wonder if this actually works
self.logger.info(f"[DEBUG] Before last stream result") self.logger.info(f"[DEBUG] Before last stream result")
url = "%s%s" % (self.base_url, stream_path) url = "%s%s" % (self.base_url, stream_path)
self.logger.info("[INFO] URL FOR RESULT (URL): %s" % url) self.logger.info(f"[INFO] URL FOR RESULT (URL): {url}")
try: try:
log_contents = self.log_capture_string.getvalue() #log_contents = self.log_capture_string.getvalue()
log_contents = "disabled"
#print("RESULTS: %s" % log_contents) #print("RESULTS: %s" % log_contents)
self.logger.info("[WARNING] Got logs of length {len(log_contents)}") self.logger.info(f"[WARNING] Got logs of length {len(log_contents)}")
if len(action_result["action"]["parameters"]) == 0: if len(action_result["action"]["parameters"]) == 0:
action_result["action"]["parameters"] = [] action_result["action"]["parameters"] = []
@@ -373,11 +377,12 @@ class AppBase:
except urllib3.exceptions.ProtocolError as e: except urllib3.exceptions.ProtocolError as e:
self.logger.info(f"[DEBUG] Expected ProtocolError happened: {e}") self.logger.info(f"[DEBUG] Expected ProtocolError happened: {e}")
try: #try:
self.log_capture_string.flush() # self.log_capture_string.flush()
except Exception as e: # self.log_capture_string.close()
print(f"[WARNING] Failed to flush logs: {e}") #except Exception as e:
pass # print(f"[WARNING] Failed to flush logs: {e}")
# pass
#async def cartesian_product(self, L): #async def cartesian_product(self, L):
def cartesian_product(self, L): def cartesian_product(self, L):
@@ -3022,6 +3027,17 @@ class AppBase:
self.logger.info("[INFO] Running normal execution (not loop)\n") self.logger.info("[INFO] Running normal execution (not loop)\n")
try:
for key, value in params.items():
try:
if isinstance(value, str):
params[key] = ast.literal_eval(value)
except Exception as e:
self.logger.info("[DEBUG] Failed parsing value with ast: {e}")
continue
except Exception as e:
self.logger.info("[DEBUG] Failed looping objects. Non critical: {e}")
#newres = await func(**params) #newres = await func(**params)
#self.logger.info("PARAMS: %s" % params) #self.logger.info("PARAMS: %s" % params)
#newres = "" #newres = ""
@@ -3211,10 +3227,17 @@ class AppBase:
# Send the result :) # Send the result :)
self.send_result(self.action_result, headers, stream_path) self.send_result(self.action_result, headers, stream_path)
try:
self.log_capture_string.close() #try:
except: # try:
pass # self.log_capture_string.flush()
# except Exception as e:
# print(f"[WARNING] Failed to flush logs (2): {e}")
# pass
# self.log_capture_string.close()
#except:
# print(f"[WARNING] Failed to close logs (2): {e}")
return return
@@ -3238,6 +3261,7 @@ class AppBase:
#from waitress import serve #from waitress import serve
flask_app = Flask(__name__) flask_app = Flask(__name__)
#flask_app.config['PERMANENT_SESSION_LIFETIME'] = datetime.timedelta(minutes=5)
#async def execute(): #async def execute():
@flask_app.route("/api/v1/health", methods=["GET", "POST"]) @flask_app.route("/api/v1/health", methods=["GET", "POST"])
@@ -3270,31 +3294,31 @@ class AppBase:
try: try:
app.full_execution = json.dumps(requestdata["workflow_execution"]) app.full_execution = json.dumps(requestdata["workflow_execution"])
except Exception as e: except Exception as e:
logger.info(f"Failed parsing full execution from workflow_execution: {e}") logger.info(f"[ERROR] Failed parsing full execution from workflow_execution: {e}")
try: try:
app.action = requestdata["action"] app.action = requestdata["action"]
except: except Exception as e:
logger.info("Failed parsing action") logger.info(f"[ERROR] Failed parsing action: {e}")
try: try:
app.authorization = requestdata["authorization"] app.authorization = requestdata["authorization"]
app.current_execution_id = requestdata["execution_id"] app.current_execution_id = requestdata["execution_id"]
except: except Exception as e:
logger.info("Failed parsing auth and exec id") logger.info(f"[ERROR] Failed parsing auth and exec id: {e}")
# BASE URL (backend) # BASE URL (backend)
try: try:
app.url = requestdata["url"] app.url = requestdata["url"]
logger.info(f"BACKEND URL: {app.url}") logger.info(f"BACKEND URL: {app.url}")
except: except Exception as e:
logger.info("Failed parsing url (backend)") logger.info(f"[ERROR] Failed parsing url (backend): {e}")
# URL (worker) # URL (worker)
try: try:
app.base_url = requestdata["base_url"] app.base_url = requestdata["base_url"]
logger.info(f"WORKER URL: {app.base_url}") logger.info(f"WORKER URL: {app.base_url}")
except: except Exception as e:
logger.info("Failed parsing base url (worker)") logger.info(f"[ERROR] Failed parsing base url (worker): {e}")
#await #await
app.execute_action(app.action) app.execute_action(app.action)
@@ -3316,6 +3340,7 @@ class AppBase:
} }
logger.info(f"[DEBUG] Serving on port {port}") logger.info(f"[DEBUG] Serving on port {port}")
flask_app.run( flask_app.run(
host="0.0.0.0", host="0.0.0.0",
port=port, port=port,
+1 -1
View File
@@ -3,7 +3,7 @@
### DEFAULT ### DEFAULT
NAME=shuffle-app_sdk NAME=shuffle-app_sdk
VERSION=0.9.62 VERSION=0.9.63
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
docker build . -f Dockerfile -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION -t ghcr.io/frikky/$NAME:nightly docker build . -f Dockerfile -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION -t ghcr.io/frikky/$NAME:nightly
+1 -1
View File
@@ -3,5 +3,5 @@ requests==2.25.1
MarkupSafe==2.0.1 MarkupSafe==2.0.1
liquidpy==0.7.3 liquidpy==0.7.3
flask[async]==2.0.2 flask[async]==2.0.2
#waitress==2.0.0 waitress==2.1.0
#flask==1.1.2 #flask==1.1.2
+1 -1
View File
@@ -2,7 +2,7 @@ module main
go 1.16 go 1.16
//replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared replace github.com/shuffle/shuffle-shared => ../../../shuffle-shared
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
//replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch //replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch
+3 -2
View File
@@ -1052,14 +1052,15 @@ const Admin = (props) => {
}) })
.then((responseJson) => { .then((responseJson) => {
//console.log("RESP: ", responseJson) //console.log("RESP: ", responseJson)
if (responseJson.success) { if (responseJson.success === true) {
handleFileUpload(responseJson.id, file); handleFileUpload(responseJson.id, file);
} else { } else {
alert.error("Failed to upload file ", filename); alert.error("Failed to upload file ", filename);
} }
}) })
.catch((error) => { .catch((error) => {
alert.error(error.toString()); alert.error("Failed to upload file ", filename)
console.log(error.toString());
}); });
}; };
+1 -1
View File
@@ -3168,7 +3168,7 @@ const AppCreator = (defaultprops) => {
style={{ flex: "1", marginRight: "15px", backgroundColor: inputColor }} style={{ flex: "1", marginRight: "15px", backgroundColor: inputColor }}
fullWidth={true} fullWidth={true}
placeholder={ placeholder={
'{\n\t"username": "${username}",\n\t"apikey": "${apikey}",\n\t"search": "1.2.3.5"}' '{\n\t"example": "${example}",\n\t"apikey": "${apikey}",\n\t"search": "1.2.3.5"\n}'
} }
margin="normal" margin="normal"
variant="outlined" variant="outlined"
+24 -23
View File
@@ -1299,31 +1299,32 @@ const Workflows = (props) => {
body: JSON.stringify(data), body: JSON.stringify(data),
credentials: "include", credentials: "include",
}) })
.then((response) => { .then((response) => {
if (response.status !== 200) { if (response.status !== 200) {
console.log("Status not 200 for workflow publish :O!"); console.log("Status not 200 for workflow publish :O!");
} else { } else {
if (isCloud) { if (isCloud) {
alert.success("Successfully published workflow"); alert.success("Successfully published workflow");
} else { } else {
alert.success( alert.success(
"Successfully published workflow to https://shuffler.io" "Successfully published workflow to https://shuffler.io"
); );
} }
} }
return response.json(); return response.json();
}) })
.then((responseJson) => { .then((responseJson) => {
if (responseJson.reason !== undefined) { if (responseJson.reason !== undefined) {
alert.error("Failed publishing: ", responseJson.reason); alert.error("Failed publishing: ", responseJson.reason);
} }
getAvailableWorkflows(); getAvailableWorkflows();
}) })
.catch((error) => { .catch((error) => {
alert.error(error.toString()); alert.error("Failed publishing: is the workflow valid? Remember to save the workflow first.")
}); console.log(error.toString());
});
}; };
const copyWorkflow = (data) => { const copyWorkflow = (data) => {