From e9c84bb858e87bdb633255196e093dbdd5160c5e Mon Sep 17 00:00:00 2001 From: frikky Date: Sat, 15 Jan 2022 03:18:08 +0100 Subject: [PATCH] Made Liquid formatting work with loops and added extra auto-fixes --- backend/app_sdk/app_base.py | 43 +++++++++++++++++++++++++++++++- backend/app_sdk/build.sh | 2 +- backend/go-app/go.mod | 4 +-- docker-compose.yml | 5 ++-- frontend/src/views/LoginPage.jsx | 12 ++++++--- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/backend/app_sdk/app_base.py b/backend/app_sdk/app_base.py index ecc61235..c2a3f72e 100644 --- a/backend/app_sdk/app_base.py +++ b/backend/app_sdk/app_base.py @@ -13,6 +13,7 @@ import asyncio import requests import http.client import urllib.parse +import jinja2 from io import BytesIO from liquid import Liquid @@ -1764,6 +1765,7 @@ class AppBase: #self.logger.info(globals()) self.logger.info("[DEBUG] Running liquid with data of length %d" % len(template)) + #self.logger.info(f"[DEBUG] Data: {template}") run = Liquid(template, mode="wild", from_file=False) # Can't handle self yet (?) @@ -1777,6 +1779,36 @@ class AppBase: self.logger.info(f"[ERROR] Liquid Syntax error: {e}") error = True error_msg = e + except TypeError as e: + try: + if "string as left operand" in f"{e}": + #print(f"HANDLE REPLACE: {template}") + split_left = template.split("|") + if len(split_left) < 2: + return template + + splititem = split_left[0] + additem = "{{" + if "{{" in splititem: + splititem = splititem.replace("{{", "", -1) + + if "{%" in splititem: + splititem = splititem.replace("{%", "", -1) + additem = "{%" + + splititem = "%s \"%s\"" % (additem, splititem.strip()) + parsed_template = template.replace(split_left[0], splititem) + run = Liquid(parsed_template, mode="wild", from_file=False) + return run.render(**globals()) + + except Exception as e: + print(f"SubError in Liquid: {e}") + #return template + + self.logger.info(f"[ERROR] Liquid TypeError error: {e}") + error = True + error_msg = e + except Exception as e: self.logger.info(f"[ERROR] General exception for liquid: {e}") error = True @@ -2467,6 +2499,11 @@ class AppBase: else: newvalue = tmpitem.replace(str(actualitem[index][0]), str(json_replacement[i]), 1) + try: + newvalue = parse_liquid(newvalue, self) + except Exception as e: + self.logger.info(f"[WARNING] Failed liquid parsing in loop (2): {e}") + try: newvalue = json.loads(newvalue) except json.decoder.JSONDecodeError as e: @@ -2477,7 +2514,7 @@ class AppBase: self.logger.info("New replacement: %s" % new_replacement) - # New + # FIXME: Should this use new_replacement? tmpitem = tmpitem.replace(actualitem[index][0], replacement, 1) # This code handles files. @@ -2579,6 +2616,10 @@ class AppBase: #self.logger.info("REPLACING %s with %s" % (key, replacement)) #replacement = parse_wrapper_start(replacement) tmpitem = tmpitem.replace(key, replacement, -1) + try: + tmpitem = parse_liquid(tmpitem, self) + except Exception as e: + self.logger.info(f"[WARNING] Failed liquid parsing in loop (2): {e}") # This code handles files. diff --git a/backend/app_sdk/build.sh b/backend/app_sdk/build.sh index 2c04a57f..0eeeb7c7 100644 --- a/backend/app_sdk/build.sh +++ b/backend/app_sdk/build.sh @@ -3,7 +3,7 @@ ### DEFAULT NAME=shuffle-app_sdk -VERSION=0.9.44 +VERSION=0.9.49 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 diff --git a/backend/go-app/go.mod b/backend/go-app/go.mod index d43f805c..111c8026 100644 --- a/backend/go-app/go.mod +++ b/backend/go-app/go.mod @@ -2,7 +2,7 @@ module main go 1.15 -//replace github.com/shuffle/shuffle-shared => ../../../../git/shuffle-shared +replace github.com/shuffle/shuffle-shared => ../../../../git/shuffle-shared //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi //replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch @@ -14,7 +14,7 @@ require ( github.com/basgys/goxml2json v1.1.0 github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 github.com/docker/docker v20.10.9+incompatible - github.com/frikky/kin-openapi v0.40.0 + github.com/frikky/kin-openapi v0.41.0 github.com/fsouza/go-dockerclient v1.7.4 github.com/ghodss/yaml v1.0.0 github.com/go-git/go-billy/v5 v5.3.1 diff --git a/docker-compose.yml b/docker-compose.yml index f1c7ff7c..d5c27571 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -61,7 +61,7 @@ services: - SHUFFLE_PASS_APP_PROXY=${SHUFFLE_PASS_APP_PROXY} - SHUFFLE_SWARM_NETWORK_NAME=shuffle_swarm_executions - SHUFFLE_SCALE_REPLICAS=1 - - SHUFFLE_SWARM_CONFIG=run + - SHUFFLE_SWARM_CONFIG=runn restart: unless-stopped opensearch: image: opensearchproject/opensearch:1.2.3 @@ -93,6 +93,7 @@ services: restart: unless-stopped networks: shuffle: - driver: overlay + driver: bridge +#driver: overlay #driver: bridge diff --git a/frontend/src/views/LoginPage.jsx b/frontend/src/views/LoginPage.jsx index 2c1bd14f..8928f166 100644 --- a/frontend/src/views/LoginPage.jsx +++ b/frontend/src/views/LoginPage.jsx @@ -10,7 +10,9 @@ import { Paper, Typography, } from "@material-ui/core"; + import { useTheme } from "@material-ui/core/styles"; +import { useNavigate } from "react-router-dom"; const hrefStyle = { color: "white", @@ -31,6 +33,7 @@ const useStyles = makeStyles({ const LoginDialog = (props) => { const theme = useTheme(); + let navigate = useNavigate(); const { globalUrl, @@ -62,7 +65,8 @@ const LoginDialog = (props) => { }; if (isLoggedIn === true) { - window.location.pathname = "/workflows"; + //window.location.pathname = "/workflows"; + navigate("/workflows") } const checkAdmin = () => { @@ -99,7 +103,7 @@ const LoginDialog = (props) => { } if (responseJson.reason === "stay") { - window.location.pathname = "/adminsetup"; + navigate("/adminsetup") } } }) @@ -176,7 +180,7 @@ const LoginDialog = (props) => { setIsLoggedIn(true); - window.location.pathname = "/workflows"; + navigate("/workflows") } }) ) @@ -468,7 +472,7 @@ const LoginDialog = (props) => { style={{ flex: "1", marginTop: 5 }} onClick={() => { console.log("CLICK"); - window.location = ssoUrl; + navigate(ssoUrl) }} > Use SSO