Fixed minor issue with app sdk

This commit is contained in:
frikky
2023-01-16 00:30:46 +01:00
parent 0171d908cd
commit 78d62789cc
2 changed files with 37 additions and 29 deletions
+1
View File
@@ -63,6 +63,7 @@ SHUFFLE_ELASTIC=true
SHUFFLE_LOGS_DISABLED=false SHUFFLE_LOGS_DISABLED=false
SHUFFLE_CHAT_DISABLED=false # Controls support chat SHUFFLE_CHAT_DISABLED=false # Controls support chat
SHUFFLE_RERUN_SCHEDULE=300 SHUFFLE_RERUN_SCHEDULE=300
SHUFFLE_DISABLE_RERUN_AND_ABORT=false
# DATABASE CONFIGURATIONS # DATABASE CONFIGURATIONS
DATASTORE_EMULATOR_HOST=shuffle-database:8000 DATASTORE_EMULATOR_HOST=shuffle-database:8000
+36 -29
View File
@@ -327,7 +327,8 @@ class AppBase:
new_input = fixed_return new_input = fixed_return
except Exception as e: except Exception as e:
self.logger.info(f"[ERROR] Failed to run magic parser (2): {e}") # Not used anymore
#self.logger.info(f"[ERROR] Failed to run magic parser (2): {e}")
return input_data return input_data
try: try:
@@ -401,15 +402,6 @@ class AppBase:
# FIXME: Add cleanup of parameters to not send to frontend here # FIXME: Add cleanup of parameters to not send to frontend here
params = {} params = {}
#action = action_result["action"]
#try:
# for item in action["authentication"]:
# for action["parameters"]
# self.logger.info("AUTH: ", key, value)
# params[item["key"]] = item["value"]
#except KeyError:
# self.logger.info("No authentication specified!")
# pass
# 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")
@@ -448,7 +440,7 @@ class AppBase:
try: try:
ret = requests.post(url, headers=headers, json=action_result, timeout=10) ret = requests.post(url, headers=headers, json=action_result, timeout=10)
self.logger.info(f"[DEBUG] Result: {ret.status_code} (break on 200)") self.logger.info(f"[DEBUG] Result: {ret.status_code} (break on 200 or 201)")
if ret.status_code == 200 or ret.status_code == 201: if ret.status_code == 200 or ret.status_code == 201:
finished = True finished = True
break break
@@ -1015,6 +1007,7 @@ class AppBase:
# An attempt at decomposing coroutine results # An attempt at decomposing coroutine results
# Backwards compatibility
try: try:
if asyncio.iscoroutine(tmp): if asyncio.iscoroutine(tmp):
self.logger.info("[DEBUG] In coroutine (2)") self.logger.info("[DEBUG] In coroutine (2)")
@@ -1028,7 +1021,8 @@ class AppBase:
tmp = asyncio.run(parse_value(tmp)) tmp = asyncio.run(parse_value(tmp))
else: else:
self.logger.info("[DEBUG] Not in coroutine (2)") #self.logger.info("[DEBUG] Not in coroutine (2)")
pass
except Exception as e: except Exception as e:
self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}") self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}")
@@ -1448,7 +1442,7 @@ class AppBase:
failed = False failed = False
break break
elif ret.status_code == 500: elif ret.status_code == 500 or ret.status_code == 400:
self.logger.info("[ERROR] (fails: %d) Error in app with status code %d for results (1). RETRYING because results can't be handled" % (i+1, ret.status_code)) self.logger.info("[ERROR] (fails: %d) Error in app with status code %d for results (1). RETRYING because results can't be handled" % (i+1, ret.status_code))
rettext = ret.text rettext = ret.text
@@ -1522,7 +1516,7 @@ class AppBase:
except Exception as e: except Exception as e:
self.logger.info(f"[WARNING] Failed in replace params action parsing: {e}") self.logger.info(f"[WARNING] Failed in replace params action parsing: {e}")
self.logger.info("[DEBUG] AFTER FULLEXEC stream result (init)") self.logger.info(f"[DEBUG] AFTER FULLEXEC stream result (init): {self.current_execution_id}")
# Gets the value at the parenthesis level you want # Gets the value at the parenthesis level you want
def parse_nested_param(string, level): def parse_nested_param(string, level):
@@ -1708,7 +1702,7 @@ class AppBase:
# Because liquid can handle ALL of this now. # Because liquid can handle ALL of this now.
# Implemented for >0.9.25 # Implemented for >0.9.25
self.logger.info("[DEBUG] Skipping parser because use of its been deprecated >0.9.25 due to Liquid implementation") #self.logger.info("[DEBUG] Skipping parser because use of its been deprecated >0.9.25 due to Liquid implementation")
return data, False return data, False
wrappers = ["int", "number", "lower", "upper", "trim", "strip", "split", "parse", "len", "length", "lenght", "join", "replace"] wrappers = ["int", "number", "lower", "upper", "trim", "strip", "split", "parse", "len", "length", "lenght", "join", "replace"]
@@ -2409,9 +2403,11 @@ class AppBase:
newvalue[key] = recurse_cleanup_script(value) newvalue[key] = recurse_cleanup_script(value)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
print(f"[WARNING] Failed JSON replacement for OpenAPI keys (3) {e}") # Since here the data isn't at all JSON compatible..?
# Seems to happen with newlines in variables being parsed in as strings?
print(f"[ERROR] Failed JSON replacement for OpenAPI keys (3) {e}. Value: {data}")
except Exception as e: except Exception as e:
print(f"[WARNING] Failed as an exception (1): {e}") print(f"[ERROR] Failed as an exception (1): {e}")
try: try:
for deletekey in deletekeys: for deletekey in deletekeys:
@@ -2476,9 +2472,17 @@ class AppBase:
except: except:
self.logger.info("Error in initial replacement of escaped dollar!") self.logger.info("Error in initial replacement of escaped dollar!")
# Basic fix in case variant isn't set paramname = ""
try: try:
self.logger.info(f"[DEBUG] Parameter variant: {parameter['variant']} of length {len(parameter['value'])}") paramname = parameter["name"]
except:
pass
# Basic fix in case variant isn't set
# Variant is ALWAYS STATIC_VALUE from mid 2021~
try:
self.logger.info(f"[DEBUG] Parameter '{paramname}' of length {len(parameter['value'])}")
parameter["variant"] = parameter["variant"]
except: except:
parameter["variant"] = "STATIC_VALUE" parameter["variant"] = "STATIC_VALUE"
@@ -2904,7 +2908,8 @@ class AppBase:
if " " in actionname: if " " in actionname:
actionname.replace(" ", "_", -1) actionname.replace(" ", "_", -1)
#print(action) #print("ACTION: ", action)
#print("exec: ", self.full_execution)
#if action.generated: #if action.generated:
# actionname = actionname.lower() # actionname = actionname.lower()
@@ -2931,12 +2936,14 @@ class AppBase:
# What variables are necessary here tho hmm # What variables are necessary here tho hmm
params = {} params = {}
# This replacement should happen in backend as part of params
# error log is useless
try: try:
for item in action["authentication"]: for item in action["authentication"]:
#self.logger.info("AUTH: ", key, value) self.logger.info("AUTH PARAM: ", key, value)
params[item["key"]] = item["value"] #params[item["key"]] = item["value"]
except KeyError: except KeyError as e:
self.logger.info("[DEBUG] No authentication specified!") self.logger.info(f"[WARNING] No authentication specified! Is this correct? err: {e}")
# Fixes OpenAPI body parameters for later. # Fixes OpenAPI body parameters for later.
newparams = [] newparams = []
@@ -3007,7 +3014,7 @@ class AppBase:
pass pass
self.logger.info(f"""HANDLING {action["parameters"][counter]["value"]}""") self.logger.info(f"""HANDLING BODY: {action["parameters"][counter]["value"]}""")
action["parameters"][counter]["value"] = recurse_cleanup_script(action["parameters"][counter]["value"]) action["parameters"][counter]["value"] = recurse_cleanup_script(action["parameters"][counter]["value"])
#self.logger.info(action["parameters"]) #self.logger.info(action["parameters"])
@@ -3442,7 +3449,7 @@ class AppBase:
errorstring = f"{e}" errorstring = f"{e}"
if "the JSON object must be" in errorstring: if "the JSON object must be" in errorstring:
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly (0)?") self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly (0)? the JSON object must be in...")
try: try:
e = json.loads(f"{e}") e = json.loads(f"{e}")
except: except:
@@ -3472,7 +3479,7 @@ class AppBase:
}) })
break break
except Exception as e: except Exception as e:
self.logger.info("[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly (1)?") self.logger.info(f"[ERROR] Something is wrong with the input for this function. Are lists and JSON data handled parsed properly (1)? err: {e}")
try: try:
e = json.loads(f"{e}") e = json.loads(f"{e}")
@@ -3499,7 +3506,8 @@ class AppBase:
newres = asyncio.run(parse_value(newres)) newres = asyncio.run(parse_value(newres))
else: else:
self.logger.info("[DEBUG] Not in coroutine (1)") #self.logger.info("[DEBUG] Not in coroutine (1)")
pass
except Exception as e: except Exception as e:
self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}") self.logger.warning("[ERROR] Failed to parse coroutine value for old app: {e}")
@@ -3712,7 +3720,6 @@ class AppBase:
def execute(): def execute():
if request.method == "POST": if request.method == "POST":
#print(request.get_json(force=True)) #print(request.get_json(force=True))
#print("DATA: ", request.data)
requestdata = {} requestdata = {}
try: try:
requestdata = json.loads(request.data) requestdata = json.loads(request.data)