Made Liquid formatting work with loops and added extra auto-fixes

This commit is contained in:
frikky
2022-01-15 03:18:08 +01:00
parent c406b4453e
commit e9c84bb858
5 changed files with 56 additions and 10 deletions
+42 -1
View File
@@ -13,6 +13,7 @@ import asyncio
import requests import requests
import http.client import http.client
import urllib.parse import urllib.parse
import jinja2
from io import BytesIO from io import BytesIO
from liquid import Liquid from liquid import Liquid
@@ -1764,6 +1765,7 @@ class AppBase:
#self.logger.info(globals()) #self.logger.info(globals())
self.logger.info("[DEBUG] Running liquid with data of length %d" % len(template)) 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) run = Liquid(template, mode="wild", from_file=False)
# Can't handle self yet (?) # Can't handle self yet (?)
@@ -1777,6 +1779,36 @@ class AppBase:
self.logger.info(f"[ERROR] Liquid Syntax error: {e}") self.logger.info(f"[ERROR] Liquid Syntax error: {e}")
error = True error = True
error_msg = e 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: except Exception as e:
self.logger.info(f"[ERROR] General exception for liquid: {e}") self.logger.info(f"[ERROR] General exception for liquid: {e}")
error = True error = True
@@ -2467,6 +2499,11 @@ class AppBase:
else: else:
newvalue = tmpitem.replace(str(actualitem[index][0]), str(json_replacement[i]), 1) 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: try:
newvalue = json.loads(newvalue) newvalue = json.loads(newvalue)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
@@ -2477,7 +2514,7 @@ class AppBase:
self.logger.info("New replacement: %s" % new_replacement) self.logger.info("New replacement: %s" % new_replacement)
# New # FIXME: Should this use new_replacement?
tmpitem = tmpitem.replace(actualitem[index][0], replacement, 1) tmpitem = tmpitem.replace(actualitem[index][0], replacement, 1)
# This code handles files. # This code handles files.
@@ -2579,6 +2616,10 @@ class AppBase:
#self.logger.info("REPLACING %s with %s" % (key, replacement)) #self.logger.info("REPLACING %s with %s" % (key, replacement))
#replacement = parse_wrapper_start(replacement) #replacement = parse_wrapper_start(replacement)
tmpitem = tmpitem.replace(key, replacement, -1) 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. # This code handles files.
+1 -1
View File
@@ -3,7 +3,7 @@
### DEFAULT ### DEFAULT
NAME=shuffle-app_sdk NAME=shuffle-app_sdk
VERSION=0.9.44 VERSION=0.9.49
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
+2 -2
View File
@@ -2,7 +2,7 @@ module main
go 1.15 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/kin-openapi => ../../../../git/kin-openapi
//replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch //replace github.com/frikky/go-elasticsearch => ../../../../git/go-elasticsearch
@@ -14,7 +14,7 @@ require (
github.com/basgys/goxml2json v1.1.0 github.com/basgys/goxml2json v1.1.0
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82
github.com/docker/docker v20.10.9+incompatible 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/fsouza/go-dockerclient v1.7.4
github.com/ghodss/yaml v1.0.0 github.com/ghodss/yaml v1.0.0
github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-billy/v5 v5.3.1
+3 -2
View File
@@ -61,7 +61,7 @@ services:
- SHUFFLE_PASS_APP_PROXY=${SHUFFLE_PASS_APP_PROXY} - SHUFFLE_PASS_APP_PROXY=${SHUFFLE_PASS_APP_PROXY}
- SHUFFLE_SWARM_NETWORK_NAME=shuffle_swarm_executions - SHUFFLE_SWARM_NETWORK_NAME=shuffle_swarm_executions
- SHUFFLE_SCALE_REPLICAS=1 - SHUFFLE_SCALE_REPLICAS=1
- SHUFFLE_SWARM_CONFIG=run - SHUFFLE_SWARM_CONFIG=runn
restart: unless-stopped restart: unless-stopped
opensearch: opensearch:
image: opensearchproject/opensearch:1.2.3 image: opensearchproject/opensearch:1.2.3
@@ -93,6 +93,7 @@ services:
restart: unless-stopped restart: unless-stopped
networks: networks:
shuffle: shuffle:
driver: overlay driver: bridge
#driver: overlay
#driver: bridge #driver: bridge
+8 -4
View File
@@ -10,7 +10,9 @@ import {
Paper, Paper,
Typography, Typography,
} from "@material-ui/core"; } from "@material-ui/core";
import { useTheme } from "@material-ui/core/styles"; import { useTheme } from "@material-ui/core/styles";
import { useNavigate } from "react-router-dom";
const hrefStyle = { const hrefStyle = {
color: "white", color: "white",
@@ -31,6 +33,7 @@ const useStyles = makeStyles({
const LoginDialog = (props) => { const LoginDialog = (props) => {
const theme = useTheme(); const theme = useTheme();
let navigate = useNavigate();
const { const {
globalUrl, globalUrl,
@@ -62,7 +65,8 @@ const LoginDialog = (props) => {
}; };
if (isLoggedIn === true) { if (isLoggedIn === true) {
window.location.pathname = "/workflows"; //window.location.pathname = "/workflows";
navigate("/workflows")
} }
const checkAdmin = () => { const checkAdmin = () => {
@@ -99,7 +103,7 @@ const LoginDialog = (props) => {
} }
if (responseJson.reason === "stay") { if (responseJson.reason === "stay") {
window.location.pathname = "/adminsetup"; navigate("/adminsetup")
} }
} }
}) })
@@ -176,7 +180,7 @@ const LoginDialog = (props) => {
setIsLoggedIn(true); setIsLoggedIn(true);
window.location.pathname = "/workflows"; navigate("/workflows")
} }
}) })
) )
@@ -468,7 +472,7 @@ const LoginDialog = (props) => {
style={{ flex: "1", marginTop: 5 }} style={{ flex: "1", marginTop: 5 }}
onClick={() => { onClick={() => {
console.log("CLICK"); console.log("CLICK");
window.location = ssoUrl; navigate(ssoUrl)
}} }}
> >
Use SSO Use SSO