Fixed issues with string and json parsing in SDK

This commit is contained in:
frikky
2021-04-02 21:57:02 +02:00
parent ab5c0d82b9
commit 63db013438
10 changed files with 177 additions and 58 deletions
+34 -13
View File
@@ -859,7 +859,6 @@ class AppBase:
return parse_nested_param(string + ')', level) return parse_nested_param(string + ')', level)
elif len(re.findall("\(", string)) < len(re.findall("\)", string)): elif len(re.findall("\(", string)) < len(re.findall("\)", string)):
return parse_nested_param('(' + string, level) return parse_nested_param('(' + string, level)
else: else:
return 'Failed to parse params' return 'Failed to parse params'
@@ -950,17 +949,30 @@ class AppBase:
print(f"JSON ERROR in join(): {e}") print(f"JSON ERROR in join(): {e}")
if "len" in thistype or "length" in thistype or "lenght" in thistype: if "len" in thistype or "length" in thistype or "lenght" in thistype:
print(f"Trying to length-parse: {data}")
tmp = "" tmp = ""
try: try:
tmp = json.loads(tmpdata) tmp = json.loads(data)
except: except (NameError, KeyError, TypeError, json.decoder.JSONDecodeError) as e:
try: try:
tmpdata = data.replace("\'", "\"") print(f"[WARNING] INITIAL Parsing bug for length in app sdk: {e}")
tmp = json.loads(tmpdata) #data = data.replace("\'", "\"")
except: data = data.replace("True", "true")
print("[ERROR] Parsing bug for length in app sdk") data = data.replace("False", "false")
data = data.replace("None", "null")
data = data.replace("\"", "\\\"")
data = data.replace("'", "\"")
tmp = json.loads(data)
except (NameError, KeyError, TypeError, json.decoder.JSONDecodeError) as e:
print(f"[ERROR] Parsing bug for length in app sdk: {e}")
pass pass
if tmp == "":
print("[WARNING] Length parsing: item wasn't parsed")
tmp = data
if isinstance(tmp, list): if isinstance(tmp, list):
return str(len(tmp)) return str(len(tmp))
elif isinstance(tmp, object): elif isinstance(tmp, object):
@@ -1028,13 +1040,22 @@ class AppBase:
print("INNER: ", innervalue) print("INNER: ", innervalue)
print("OUTER: ", outervalue) print("OUTER: ", outervalue)
# FIXME: There is a known bug here with nested paranthesis
#if outervalue != innervalue:
# # FIXME: This line right here WILL break things when we
# # Do recursive paranthesis in the future
# innervalue = outervalue
# #print("Outer: ", outervalue, " inner: ", innervalue)
# for key in range(len(innervalue)):
# # Replace OUTERVALUE[key] with INNERVALUE[key] in data.
# print("\nReplace %s\nwith\n%s\nin\n%s" % (outervalue[key], innervalue[key], data))
# data = data.replace(outervalue[key], innervalue[key])
#else:
if outervalue != innervalue: if outervalue != innervalue:
#print("Outer: ", outervalue, " inner: ", innervalue) print("Setting inner to outer")
for key in range(len(innervalue)): innervalue = outervalue
# Replace OUTERVALUE[key] with INNERVALUE[key] in data.
print("Replace %s with %s in %s" % (outervalue[key], innervalue[key], data))
data = data.replace(outervalue[key], innervalue[key])
else:
for thistype in wrappers: for thistype in wrappers:
if thistype.lower() not in data.lower(): if thistype.lower() not in data.lower():
continue continue
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
NAME=shuffle-app_sdk NAME=shuffle-app_sdk
VERSION=0.8.64 VERSION=0.8.71
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION
+2 -2
View File
@@ -1,2 +1,2 @@
urllib3=1.25.9 urllib3==1.25.9
requests=2.25.1 requests==2.25.1
+1 -1
View File
@@ -2,7 +2,7 @@ module shuffle
go 1.13 go 1.13
//replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared
//replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi
require ( require (
+3 -1
View File
@@ -5140,12 +5140,13 @@ func runInit(ctx context.Context) {
// Gets environments and inits if it doesn't exist // Gets environments and inits if it doesn't exist
count, err := getEnvironmentCount() count, err := getEnvironmentCount()
if count == 0 && err == nil && len(activeOrgs) == 1 { if count == 0 && err == nil && len(activeOrgs) == 1 {
log.Printf("Setting up environment with org %s", activeOrgs[0].Id) log.Printf("[INFO] Setting up environment with org %s", activeOrgs[0].Id)
item := shuffle.Environment{ item := shuffle.Environment{
Name: "Shuffle", Name: "Shuffle",
Type: "onprem", Type: "onprem",
OrgId: activeOrgs[0].Id, OrgId: activeOrgs[0].Id,
Default: true, Default: true,
Id: uuid.NewV4().String(),
} }
err = setEnvironment(ctx, &item) err = setEnvironment(ctx, &item)
@@ -5889,6 +5890,7 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
Registered: true, Registered: true,
Default: false, Default: false,
OrgId: org.Id, OrgId: org.Id,
Id: uuid.NewV4().String(),
} }
err = setEnvironment(ctx, &newEnv) err = setEnvironment(ctx, &newEnv)
+1 -1
View File
@@ -1058,7 +1058,7 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
} }
if workflowExecution.Status == "FINISHED" { if workflowExecution.Status == "FINISHED" {
log.Printf("Workflowexecution is already FINISHED. No further action can be taken") log.Printf("[INFO] Workflowexecution is already FINISHED. No further action can be taken.")
resp.WriteHeader(401) resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Workflowexecution is already finished because of %s with status %s"}`, workflowExecution.LastNode, workflowExecution.Status))) resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Workflowexecution is already finished because of %s with status %s"}`, workflowExecution.LastNode, workflowExecution.Status)))
return return
+50 -6
View File
@@ -474,6 +474,39 @@ const Admin = (props) => {
}); });
} }
const inviteUser = (data) => {
console.log("INPUT: ", data)
setLoginInfo("")
// Just use this one?
var data = { "username": data.Username, "type": "invite", "org_id": selectedOrganization.id}
var baseurl = globalUrl
const url = baseurl + '/api/v1/users/register_org';
fetch(url, {
method: 'POST',
credentials: "include",
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
},
})
.then(response =>
response.json().then(responseJson => {
if (responseJson["success"] === false) {
setLoginInfo("Error: " + responseJson.reason)
} else {
setLoginInfo("")
setModalOpen(false)
getUsers()
}
}),
)
.catch(error => {
console.log("Error in userdata: ", error)
});
}
const submitUser = (data) => { const submitUser = (data) => {
console.log("INPUT: ", data) console.log("INPUT: ", data)
setLoginInfo("") setLoginInfo("")
@@ -1689,6 +1722,11 @@ const Admin = (props) => {
{curTab === 1 ? "Add user" : "Add environment"} {curTab === 1 ? "Add user" : "Add environment"}
</span></DialogTitle> </span></DialogTitle>
<DialogContent> <DialogContent>
{curTab === 1 && isCloud ?
<Typography variant="body1" style={{marginBottom: 10}}>
We'll send an email to invite them to your organization.
</Typography>
: null}
{curTab === 1 ? {curTab === 1 ?
<div> <div>
Username Username
@@ -1712,6 +1750,8 @@ const Admin = (props) => {
variant="outlined" variant="outlined"
onChange={(event) => changeModalData("Username", event.target.value)} onChange={(event) => changeModalData("Username", event.target.value)}
/> />
{isCloud ? null :
<span>
Password Password
<TextField <TextField
color="primary" color="primary"
@@ -1733,8 +1773,10 @@ const Admin = (props) => {
variant="outlined" variant="outlined"
onChange={(event) => changeModalData("Password", event.target.value)} onChange={(event) => changeModalData("Password", event.target.value)}
/> />
</span>
}
</div> </div>
: curTab === 3 ? : curTab === 5 ?
<div> <div>
Environment Name Environment Name
<TextField <TextField
@@ -1766,8 +1808,12 @@ const Admin = (props) => {
</Button> </Button>
<Button variant="contained" style={{ borderRadius: "0px" }} onClick={() => { <Button variant="contained" style={{ borderRadius: "0px" }} onClick={() => {
if (curTab === 1) { if (curTab === 1) {
if (isCloud) {
inviteUser(modalUser)
} else {
submitUser(modalUser) submitUser(modalUser)
} else if (curTab === 3) { }
} else if (curTab === 5) {
submitEnvironment(modalUser) submitEnvironment(modalUser)
} }
}} color="primary"> }} color="primary">
@@ -2353,9 +2399,7 @@ const Admin = (props) => {
style={{minWidth: 110, maxWidth: 110, overflow: "hidden"}} style={{minWidth: 110, maxWidth: 110, overflow: "hidden"}}
/> />
<ListItemText <ListItemText
primary={data.fields.map(data => { primary={data.fields === null || data.fields === undefined ? "" : data.fields.map(data => {return data.key}).join(", ")}
return data.key
}).join(", ")}
style={{minWidth: 200, maxWidth: 200, overflow: "hidden"}} style={{minWidth: 200, maxWidth: 200, overflow: "hidden"}}
/> />
<ListItemText> <ListItemText>
@@ -2651,7 +2695,7 @@ const Admin = (props) => {
<Tab label=<span><LockIcon style={iconStyle} />App Authentication</span>/> <Tab label=<span><LockIcon style={iconStyle} />App Authentication</span>/>
<Tab label=<span><DescriptionIcon style={iconStyle} />Files</span> /> <Tab label=<span><DescriptionIcon style={iconStyle} />Files</span> />
<Tab label=<span><ScheduleIcon style={iconStyle} />Schedules</span> /> <Tab label=<span><ScheduleIcon style={iconStyle} />Schedules</span> />
{isCloud ? null : <Tab label=<span><EcoIcon style={iconStyle} />Environments</span>/>} {/*isCloud ? null : <Tab label=<span><EcoIcon style={iconStyle} />Environments</span>/>*/}
{window.location.protocol == "http:" && window.location.port === "3000" ? <Tab label=<span><CloudIcon style={iconStyle} /> Hybrid</span>/> : null} {window.location.protocol == "http:" && window.location.port === "3000" ? <Tab label=<span><CloudIcon style={iconStyle} /> Hybrid</span>/> : null}
{window.location.protocol == "http:" && window.location.port === "3000" ? <Tab label=<span><BusinessIcon style={iconStyle} /> Organizations</span>/> : null} {window.location.protocol == "http:" && window.location.port === "3000" ? <Tab label=<span><BusinessIcon style={iconStyle} /> Organizations</span>/> : null}
{window.location.protocol === "http:" && window.location.port === "3000" ? <Tab label=<span><LockIcon style={iconStyle} />Categories</span>/> : null} {window.location.protocol === "http:" && window.location.port === "3000" ? <Tab label=<span><LockIcon style={iconStyle} />Categories</span>/> : null}
+2 -1
View File
@@ -501,7 +501,8 @@ const AppCreator = (props) => {
} }
if (!allowedfunctions.includes(method.toUpperCase())) { if (!allowedfunctions.includes(method.toUpperCase())) {
alert.info("Skipped method (not allowed) "+method) console.log("Invalid method: ", method, "data: ", methodvalue)
alert.info("Skipped method (not allowed): "+method)
continue continue
} }
+48 -2
View File
@@ -166,6 +166,7 @@ const Workflows = (props) => {
const [newWorkflowTags, setNewWorkflowTags] = React.useState([]); const [newWorkflowTags, setNewWorkflowTags] = React.useState([]);
const [update, setUpdate] = React.useState("test"); const [update, setUpdate] = React.useState("test");
const [deleteModalOpen, setDeleteModalOpen] = React.useState(false); const [deleteModalOpen, setDeleteModalOpen] = React.useState(false);
const [publishModalOpen, setPublishModalOpen] = React.useState(false);
const [editingWorkflow, setEditingWorkflow] = React.useState({}) const [editingWorkflow, setEditingWorkflow] = React.useState({})
const [executionLoading, setExecutionLoading] = React.useState(false) const [executionLoading, setExecutionLoading] = React.useState(false)
const [importLoading, setImportLoading] = React.useState(false) const [importLoading, setImportLoading] = React.useState(false)
@@ -246,6 +247,49 @@ const Workflows = (props) => {
findWorkflow(newfilters) findWorkflow(newfilters)
} }
const publishModal = publishModalOpen ?
<Dialog
open={publishModalOpen}
onClose={() => {
setPublishModalOpen(false)
setSelectedWorkflow({})
}}
PaperProps={{
style: {
backgroundColor: surfaceColor,
color: "white",
minWidth: 500,
padding: 50,
},
}}
>
<DialogTitle style={{marginBottom: 0, }}>
<div style={{textAlign: "center", color: "rgba(255,255,255,0.9)"}}>
Are you sure you want to PUBLISH this workflow?
</div>
</DialogTitle>
<DialogContent style={{color: "rgba(255,255,255,0.65)", textAlign: "center"}}>
<div>
<Typography variant="body1" style={{marginBottom: 20,}}>
Before publishing, we will sanitize all inputs, remove references to you, randomize ID's and remove your authentication.
</Typography>
</div>
<Button variant="contained" style={{}} onClick={() => {
publishWorkflow(selectedWorkflow)
setPublishModalOpen(false)
}} color="primary">
Yes
</Button>
<Button style={{}} onClick={() => {
setPublishModalOpen(false)
}} color="primary">
No
</Button>
</DialogContent>
</Dialog>
: null
const deleteModal = deleteModalOpen ? const deleteModal = deleteModalOpen ?
<Dialog <Dialog
open={deleteModalOpen} open={deleteModalOpen}
@@ -263,7 +307,7 @@ const Workflows = (props) => {
> >
<DialogTitle> <DialogTitle>
<div style={{textAlign: "center", color: "rgba(255,255,255,0.9)"}}> <div style={{textAlign: "center", color: "rgba(255,255,255,0.9)"}}>
Are you sure? <div/>Other workflows relying on this one may stop working Are you sure you want to delete this workflow? <div/>Other workflows relying on this one may stop working
</div> </div>
</DialogTitle> </DialogTitle>
<DialogContent style={{color: "rgba(255,255,255,0.65)", textAlign: "center"}}> <DialogContent style={{color: "rgba(255,255,255,0.65)", textAlign: "center"}}>
@@ -888,7 +932,8 @@ const Workflows = (props) => {
{"Change details"} {"Change details"}
</MenuItem> </MenuItem>
<MenuItem style={{backgroundColor: inputColor, color: "white"}} onClick={() => { <MenuItem style={{backgroundColor: inputColor, color: "white"}} onClick={() => {
publishWorkflow(data) setSelectedWorkflow(data)
setPublishModalOpen(true)
}} key={"publish"}> }} key={"publish"}>
<CloudUploadIcon style={{marginLeft: 0, marginRight: 8}}/> <CloudUploadIcon style={{marginLeft: 0, marginRight: 8}}/>
{"Publish Workflow"} {"Publish Workflow"}
@@ -1830,6 +1875,7 @@ const Workflows = (props) => {
</Dropzone> </Dropzone>
{modalView} {modalView}
{deleteModal} {deleteModal}
{publishModal}
{workflowDownloadModalOpen} {workflowDownloadModalOpen}
</div> </div>
: :
+5
View File
@@ -71,6 +71,8 @@ github.com/frikky/kin-openapi v0.38.0 h1:V7ttwIJS8Vks4KL+mZVj1ZSqhIcQtgaG8akeqXE
github.com/frikky/kin-openapi v0.38.0/go.mod h1:Fr28TtCHL4K0kIqtqui8HWxN1LG5uAh3z/tDfFyiA1s= github.com/frikky/kin-openapi v0.38.0/go.mod h1:Fr28TtCHL4K0kIqtqui8HWxN1LG5uAh3z/tDfFyiA1s=
github.com/frikky/shuffle-shared v0.0.12 h1:+0EIfThmK47Po+LogPYZR4XjbS4Ds19WNMFu2YUSjhw= github.com/frikky/shuffle-shared v0.0.12 h1:+0EIfThmK47Po+LogPYZR4XjbS4Ds19WNMFu2YUSjhw=
github.com/frikky/shuffle-shared v0.0.12/go.mod h1:SEY432/xs4oBkOUnGwxiYKCZWZLRaheGInhAoW7N8ww= github.com/frikky/shuffle-shared v0.0.12/go.mod h1:SEY432/xs4oBkOUnGwxiYKCZWZLRaheGInhAoW7N8ww=
github.com/frikky/shuffle-shared v0.0.23 h1:Pnlc2M6fHnFRLFd5K1iLTVv4/t4P04Ri1GJ5CMxzq0U=
github.com/frikky/shuffle-shared v0.0.23/go.mod h1:H7SqOta/EAYnfYuWzwzYSh/oWfF0kgnuaJTQNKQBvoQ=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -162,6 +164,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -194,6 +198,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=