#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)
|
||||
try:
|
||||
values = parameter["value_replace"]
|
||||
added = 0
|
||||
for val in values:
|
||||
newparams.append({
|
||||
"name": val["key"],
|
||||
"value": val["value"],
|
||||
"variant": "STATIC_VALUE",
|
||||
"id": "body_replacement",
|
||||
})
|
||||
if values != None:
|
||||
added = 0
|
||||
for val in values:
|
||||
newparams.append({
|
||||
"name": val["key"],
|
||||
"value": val["value"],
|
||||
"variant": "STATIC_VALUE",
|
||||
"id": "body_replacement",
|
||||
})
|
||||
|
||||
print("Added param %s for body" % val["key"])
|
||||
added += 1
|
||||
print("Added param %s for body" % val["key"])
|
||||
added += 1
|
||||
|
||||
print("ADDED %d parameters for body" % added)
|
||||
print("ADDED %d parameters for body" % added)
|
||||
except KeyError as e:
|
||||
print("KeyError body OpenAPI: %s" % e)
|
||||
pass
|
||||
@@ -1427,7 +1428,10 @@ class AppBase:
|
||||
print("Running with params (1): %s" % baseparams)
|
||||
ret = await func(**baseparams)
|
||||
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)
|
||||
json_object = True
|
||||
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.")
|
||||
}
|
||||
|
||||
type ExecutionStruct struct {
|
||||
Start string `json:"start"`
|
||||
ExecutionSource string `json:"execution_source"`
|
||||
ExecutionArgument string `json:"execution_argument"`
|
||||
}
|
||||
|
||||
for _, item := range hook.Workflows {
|
||||
log.Printf("Running webhook for workflow %s with startnode %s", item, hook.Start)
|
||||
workflow := Workflow{
|
||||
@@ -3430,22 +3436,36 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
parsedBody := string(body)
|
||||
parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
||||
//parsedBody = strings.Replace(parsedBody, "\"", "\\\"", -1)
|
||||
if len(parsedBody) > 0 {
|
||||
if string(parsedBody[0]) == `"` && string(parsedBody[len(parsedBody)-1]) == "\"" {
|
||||
parsedBody = parsedBody[1 : len(parsedBody)-1]
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
newBody := ExecutionStruct{
|
||||
Start: hook.Start,
|
||||
ExecutionSource: "webhook",
|
||||
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{
|
||||
Method: "POST",
|
||||
Body: ioutil.NopCloser(strings.NewReader(bodyWrapper)),
|
||||
Body: ioutil.NopCloser(bytes.NewReader(b)),
|
||||
}
|
||||
|
||||
// OrgId: activeOrgs[0].Id,
|
||||
|
||||
@@ -4023,15 +4023,18 @@ func deleteWorkflowApp(resp http.ResponseWriter, request *http.Request) {
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
} else {
|
||||
log.Printf("App to be deleted is private")
|
||||
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
|
||||
_, err = dbclient.GetAll(ctx, q, &workflows)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting related workflows for the app: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "}`))
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -5963,11 +5966,20 @@ func getAllSchedules(ctx context.Context, orgId string) ([]ScheduleOld, error) {
|
||||
|
||||
func getAllWorkflowApps(ctx context.Context) ([]WorkflowApp, error) {
|
||||
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)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user