#218: Fixed webhook and app sdk execution bugs
This commit is contained in:
+16
-12
@@ -1039,19 +1039,20 @@ class AppBase:
|
|||||||
print("PARAM: %s" % parameter)
|
print("PARAM: %s" % parameter)
|
||||||
try:
|
try:
|
||||||
values = parameter["value_replace"]
|
values = parameter["value_replace"]
|
||||||
added = 0
|
if values != None:
|
||||||
for val in values:
|
added = 0
|
||||||
newparams.append({
|
for val in values:
|
||||||
"name": val["key"],
|
newparams.append({
|
||||||
"value": val["value"],
|
"name": val["key"],
|
||||||
"variant": "STATIC_VALUE",
|
"value": val["value"],
|
||||||
"id": "body_replacement",
|
"variant": "STATIC_VALUE",
|
||||||
})
|
"id": "body_replacement",
|
||||||
|
})
|
||||||
|
|
||||||
print("Added param %s for body" % val["key"])
|
print("Added param %s for body" % val["key"])
|
||||||
added += 1
|
added += 1
|
||||||
|
|
||||||
print("ADDED %d parameters for body" % added)
|
print("ADDED %d parameters for body" % added)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print("KeyError body OpenAPI: %s" % e)
|
print("KeyError body OpenAPI: %s" % e)
|
||||||
pass
|
pass
|
||||||
@@ -1427,7 +1428,10 @@ class AppBase:
|
|||||||
print("Running with params (1): %s" % baseparams)
|
print("Running with params (1): %s" % baseparams)
|
||||||
ret = await func(**baseparams)
|
ret = await func(**baseparams)
|
||||||
print("Return from execution: %s" % ret)
|
print("Return from execution: %s" % ret)
|
||||||
if isinstance(ret, dict) or isinstance(ret, list):
|
if ret == None:
|
||||||
|
results.append("")
|
||||||
|
json_object = False
|
||||||
|
elif isinstance(ret, dict) or isinstance(ret, list):
|
||||||
results.append(ret)
|
results.append(ret)
|
||||||
json_object = True
|
json_object = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
+26
-6
@@ -3415,6 +3415,12 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
log.Printf("This should trigger in the cloud. Duplicate action allowed onprem.")
|
log.Printf("This should trigger in the cloud. Duplicate action allowed onprem.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ExecutionStruct struct {
|
||||||
|
Start string `json:"start"`
|
||||||
|
ExecutionSource string `json:"execution_source"`
|
||||||
|
ExecutionArgument string `json:"execution_argument"`
|
||||||
|
}
|
||||||
|
|
||||||
for _, item := range hook.Workflows {
|
for _, item := range hook.Workflows {
|
||||||
log.Printf("Running webhook for workflow %s with startnode %s", item, hook.Start)
|
log.Printf("Running webhook for workflow %s with startnode %s", item, hook.Start)
|
||||||
workflow := Workflow{
|
workflow := Workflow{
|
||||||
@@ -3430,22 +3436,36 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parsedBody := string(body)
|
parsedBody := string(body)
|
||||||
parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
//parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
||||||
if len(parsedBody) > 0 {
|
if len(parsedBody) > 0 {
|
||||||
if string(parsedBody[0]) == `"` && string(parsedBody[len(parsedBody)-1]) == "\"" {
|
if string(parsedBody[0]) == `"` && string(parsedBody[len(parsedBody)-1]) == "\"" {
|
||||||
parsedBody = parsedBody[1 : len(parsedBody)-1]
|
parsedBody = parsedBody[1 : len(parsedBody)-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyWrapper := fmt.Sprintf(`{"start": "%s", "execution_source": "webhook", "execution_argument": "%s"}`, hook.Start, string(parsedBody))
|
newBody := ExecutionStruct{
|
||||||
if len(hook.Start) == 0 {
|
Start: hook.Start,
|
||||||
log.Printf("No start node for hook %s - running with workflow default.", hook.Id)
|
ExecutionSource: "webhook",
|
||||||
bodyWrapper = string(parsedBody)
|
ExecutionArgument: string(parsedBody),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b, err := json.Marshal(newBody)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed newBody marshaling: %s", err)
|
||||||
|
resp.WriteHeader(401)
|
||||||
|
resp.Write([]byte(`{"success": false}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//bodyWrapper := fmt.Sprintf(`{"start": "%s", "execution_source": "webhook", "execution_argument": "%s"}`, hook.Start, string(parsedBody))
|
||||||
|
//if len(hook.Start) == 0 {
|
||||||
|
// log.Printf("No start node for hook %s - running with workflow default.", hook.Id)
|
||||||
|
// bodyWrapper = string(parsedBody)
|
||||||
|
//}
|
||||||
|
|
||||||
newRequest := &http.Request{
|
newRequest := &http.Request{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Body: ioutil.NopCloser(strings.NewReader(bodyWrapper)),
|
Body: ioutil.NopCloser(bytes.NewReader(b)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrgId: activeOrgs[0].Id,
|
// OrgId: activeOrgs[0].Id,
|
||||||
|
|||||||
@@ -4023,15 +4023,18 @@ func deleteWorkflowApp(resp http.ResponseWriter, request *http.Request) {
|
|||||||
resp.Write([]byte(`{"success": false}`))
|
resp.Write([]byte(`{"success": false}`))
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
log.Printf("App to be deleted is private")
|
||||||
private = true
|
private = true
|
||||||
}
|
}
|
||||||
|
|
||||||
q := datastore.NewQuery("workflow").Filter("org_id = ", user.ActiveOrg.Id)
|
// FIXME: Make workflows track themself INSIDE apps, or with a reference
|
||||||
|
q := datastore.NewQuery("workflow").Filter("org_id = ", user.ActiveOrg.Id).Limit(30)
|
||||||
var workflows []Workflow
|
var workflows []Workflow
|
||||||
_, err = dbclient.GetAll(ctx, q, &workflows)
|
_, err = dbclient.GetAll(ctx, q, &workflows)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Failed getting related workflows for the app: %s", err)
|
||||||
resp.WriteHeader(401)
|
resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false, "reason": "}`))
|
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5963,11 +5966,20 @@ func getAllSchedules(ctx context.Context, orgId string) ([]ScheduleOld, error) {
|
|||||||
|
|
||||||
func getAllWorkflowApps(ctx context.Context) ([]WorkflowApp, error) {
|
func getAllWorkflowApps(ctx context.Context) ([]WorkflowApp, error) {
|
||||||
var allworkflowapps []WorkflowApp
|
var allworkflowapps []WorkflowApp
|
||||||
q := datastore.NewQuery("workflowapp").Limit(50).Order("-edited")
|
q := datastore.NewQuery("workflowapp").Order("-edited").Limit(50)
|
||||||
|
//Activated bool `json:"activated" yaml:"activated" required:false datastore:"activated"`
|
||||||
|
|
||||||
_, err := dbclient.GetAll(ctx, q, &allworkflowapps)
|
_, err := dbclient.GetAll(ctx, q, &allworkflowapps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []WorkflowApp{}, err
|
if strings.Contains(fmt.Sprintf("%s", err), "ResourceExhausted") {
|
||||||
|
q := datastore.NewQuery("workflowapp").Limit(30).Order("-edited")
|
||||||
|
_, err := dbclient.GetAll(ctx, q, &allworkflowapps)
|
||||||
|
if err != nil {
|
||||||
|
return []WorkflowApp{}, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return []WorkflowApp{}, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return allworkflowapps, nil
|
return allworkflowapps, nil
|
||||||
|
|||||||
@@ -405,7 +405,6 @@ const AppCreator = (props) => {
|
|||||||
newitem = newitem[tmpparam]
|
newitem = newitem[tmpparam]
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("PARAM: ", newitem)
|
|
||||||
return newitem
|
return newitem
|
||||||
|
|
||||||
//console.log("Should get ", parameter["$ref"])
|
//console.log("Should get ", parameter["$ref"])
|
||||||
@@ -422,7 +421,6 @@ const AppCreator = (props) => {
|
|||||||
setBasedata(data)
|
setBasedata(data)
|
||||||
|
|
||||||
if (data.info !== null && data.info !== undefined) {
|
if (data.info !== null && data.info !== undefined) {
|
||||||
console.log("DATA: ", data)
|
|
||||||
setName(data.info.title)
|
setName(data.info.title)
|
||||||
setDescription(data.info.description)
|
setDescription(data.info.description)
|
||||||
document.title = "Apps - "+data.info.title
|
document.title = "Apps - "+data.info.title
|
||||||
@@ -500,6 +498,55 @@ const AppCreator = (props) => {
|
|||||||
"example_response": "",
|
"example_response": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (methodvalue["requestBody"] !== undefined) {
|
||||||
|
//console.log("Handle requestbody: ", methodvalue["requestBody"])
|
||||||
|
if (methodvalue["requestBody"]["content"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["application/json"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["application/json"]["schema"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["application/json"]["schema"]["properties"] !== undefined) {
|
||||||
|
var tmpobject = {}
|
||||||
|
for (let [prop, propvalue] of Object.entries(methodvalue["requestBody"]["content"]["application/json"]["schema"]["properties"])) {
|
||||||
|
tmpobject[prop] = `\$\{${prop}\}`
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var subkey in methodvalue["requestBody"]["content"]["application/json"]["schema"]["required"]) {
|
||||||
|
const tmpitem = methodvalue["requestBody"]["content"]["application/json"]["schema"]["required"][subkey]
|
||||||
|
tmpobject[tmpitem] = `\$\{${tmpitem}\}`
|
||||||
|
}
|
||||||
|
|
||||||
|
newaction["body"] = JSON.stringify(tmpobject, null, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (methodvalue["requestBody"]["content"]["application/xml"] !== undefined) {
|
||||||
|
console.log("METHOD XML: ", methodvalue)
|
||||||
|
if (methodvalue["requestBody"]["content"]["application/xml"]["schema"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["application/xml"]["schema"]["properties"] !== undefined) {
|
||||||
|
var tmpobject = {}
|
||||||
|
for (let [prop, propvalue] of Object.entries(methodvalue["requestBody"]["content"]["application/xml"]["schema"]["properties"])) {
|
||||||
|
tmpobject[prop] = `\$\{${prop}\}`
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var subkey in methodvalue["requestBody"]["content"]["application/xml"]["schema"]["required"]) {
|
||||||
|
const tmpitem = methodvalue["requestBody"]["content"]["application/xml"]["schema"]["required"][subkey]
|
||||||
|
tmpobject[tmpitem] = `\$\{${tmpitem}\}`
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log("OBJ XML: ", tmpobject)
|
||||||
|
//newaction["body"] = XML.stringify(tmpobject, null, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (methodvalue["requestBody"]["content"]["example"] !== undefined) {
|
||||||
|
if (methodvalue["requestBody"]["content"]["example"]["example"] !== undefined) {
|
||||||
|
newaction["body"] = methodvalue["requestBody"]["content"]["example"]["example"]
|
||||||
|
//JSON.stringify(tmpobject, null, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("NOT APPLICATION/JSON: ", methodvalue["requestBody"]["content"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HAHAHA wtf is this.
|
// HAHAHA wtf is this.
|
||||||
if (methodvalue.responses !== undefined) {
|
if (methodvalue.responses !== undefined) {
|
||||||
if (methodvalue.responses.default !== undefined) {
|
if (methodvalue.responses.default !== undefined) {
|
||||||
@@ -1317,7 +1364,6 @@ const AppCreator = (props) => {
|
|||||||
const findBodyParams = (body) => {
|
const findBodyParams = (body) => {
|
||||||
const regex = /\${(\w+)}/g
|
const regex = /\${(\w+)}/g
|
||||||
const found = body.match(regex)
|
const found = body.match(regex)
|
||||||
console.log("FOUND: ", found)
|
|
||||||
if (found === null) {
|
if (found === null) {
|
||||||
setExtraBodyFields([])
|
setExtraBodyFields([])
|
||||||
} else {
|
} else {
|
||||||
@@ -1521,7 +1567,7 @@ const AppCreator = (props) => {
|
|||||||
const queries = values[1]
|
const queries = values[1]
|
||||||
|
|
||||||
if (currentAction.paths !== paths && urlPath.length > 0) {
|
if (currentAction.paths !== paths && urlPath.length > 0) {
|
||||||
console.log("IN PATHS SETTER: !", paths)
|
//console.log("IN PATHS SETTER: !", paths)
|
||||||
setActionField("paths", paths)
|
setActionField("paths", paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -907,7 +907,7 @@ const Apps = (props) => {
|
|||||||
<div style={{marginTop: 15}}>
|
<div style={{marginTop: 15}}>
|
||||||
{apps.length > 0 ?
|
{apps.length > 0 ?
|
||||||
filteredApps.length > 0 ?
|
filteredApps.length > 0 ?
|
||||||
<div style={{height: "75vh", overflowY: "scroll"}}>
|
<div style={{height: "75vh", overflowY: "auto"}}>
|
||||||
{filteredApps.map(app => {
|
{filteredApps.map(app => {
|
||||||
return (
|
return (
|
||||||
appPaper(app)
|
appPaper(app)
|
||||||
|
|||||||
@@ -1383,20 +1383,20 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
|
|||||||
// FIXME - clean up stopped (remove) containers with this execution id
|
// FIXME - clean up stopped (remove) containers with this execution id
|
||||||
newresp, err := client.Do(req)
|
newresp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed making request: %s", err)
|
log.Printf("[ERROR] Failed making request: %s", err)
|
||||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(newresp.Body)
|
body, err := ioutil.ReadAll(newresp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed reading body: %s", err)
|
log.Printf("[ERROR] Failed reading body: %s", err)
|
||||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if newresp.StatusCode != 200 {
|
if newresp.StatusCode != 200 {
|
||||||
log.Printf("Err: %s\nStatusCode: %d", string(body), newresp.StatusCode)
|
log.Printf("[ERROR] Bad statuscode: %s\nStatusCode: %d", string(body), newresp.StatusCode)
|
||||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user