#168: Got successful Oauth2 implementation with Gmail OpenAPIls
This commit is contained in:
@@ -1378,7 +1378,7 @@ class AppBase:
|
||||
except IndexError:
|
||||
print("[DEBUG] INDEXERROR: ", parsersplit[outercnt])
|
||||
#ret = innervalue
|
||||
ret, tmp_loop = recurse_json(innervalue, parsersplit[outercnt:])
|
||||
ret, tmp_loop = recurse_json(basejson[i], parsersplit[outercnt:])
|
||||
|
||||
newvalue.append(ret)
|
||||
|
||||
@@ -1738,7 +1738,7 @@ class AppBase:
|
||||
#self.logger.debug(f"\n\nHandle static data with JSON: {data}\n\n")
|
||||
#self.logger.info("STATIC PARSED: %s" % actualitem)
|
||||
if len(actualitem) > 0:
|
||||
self.logger.info("ACTUAL: ", actualitem)
|
||||
#self.logger.info("[DEACTUAL: ", actualitem)
|
||||
for replace in actualitem:
|
||||
try:
|
||||
to_be_replaced = replace[0]
|
||||
@@ -1774,7 +1774,7 @@ class AppBase:
|
||||
#self.logger.info("VALUE: %s" % parameter["value"])
|
||||
|
||||
if parameter["variant"] == "WORKFLOW_VARIABLE":
|
||||
self.logger.info("Handling workflow variable")
|
||||
self.logger.info("[DEBUG] Handling workflow variable")
|
||||
found = False
|
||||
try:
|
||||
for item in fullexecution["workflow"]["workflow_variables"]:
|
||||
@@ -2533,7 +2533,8 @@ class AppBase:
|
||||
break
|
||||
except TypeError as e:
|
||||
newres = ""
|
||||
errorstring = "%s" % e
|
||||
self.logger.info(f"[DEBUG] Got exec error: {errorstring}")
|
||||
errorstring = f"{e}"
|
||||
if "got an unexpected keyword argument" in errorstring:
|
||||
fieldsplit = errorstring.split("'")
|
||||
if len(fieldsplit) > 1:
|
||||
@@ -2541,7 +2542,7 @@ class AppBase:
|
||||
|
||||
try:
|
||||
del params[field]
|
||||
self.logger.info("Removed field invalid field %s" % field)
|
||||
self.logger.info("[WARNING] Removed field invalid field %s" % field)
|
||||
except KeyError:
|
||||
break
|
||||
else:
|
||||
@@ -2774,7 +2775,8 @@ class AppBase:
|
||||
try:
|
||||
self.action_result["result"] = json.dumps({
|
||||
"success": False,
|
||||
"reason": f"Request error - failing silently. Details: {e}"
|
||||
"reason": f"Request error - failing silently. Details in detail section",
|
||||
"details": f"{e}",
|
||||
})
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
self.action_result["result"] = f"Request error: {e}"
|
||||
|
||||
@@ -23,7 +23,7 @@ require (
|
||||
github.com/docker/go-units v0.4.0 // indirect
|
||||
github.com/elastic/go-elasticsearch/v7 v7.13.1 // indirect
|
||||
github.com/frikky/kin-openapi v0.39.0
|
||||
github.com/frikky/shuffle-shared v0.1.13
|
||||
github.com/frikky/shuffle-shared v0.1.14
|
||||
github.com/fsouza/go-dockerclient v1.7.2
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/go-git/go-billy/v5 v5.0.0
|
||||
|
||||
+21
-6
@@ -1985,8 +1985,10 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
||||
location := strings.Split(request.URL.String(), "/")
|
||||
|
||||
var hookId string
|
||||
var queries string
|
||||
if location[1] == "api" {
|
||||
if len(location) <= 4 {
|
||||
log.Printf("[INFO] Couldn't handle location. Too short in webhook: %d", len(location))
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
@@ -1995,10 +1997,20 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
||||
hookId = location[4]
|
||||
}
|
||||
|
||||
if strings.Contains(hookId, "?") {
|
||||
splitter := strings.Split(hookId, "?")
|
||||
hookId = splitter[0]
|
||||
|
||||
if len(splitter) > 1 {
|
||||
queries = splitter[1]
|
||||
}
|
||||
}
|
||||
|
||||
// ID: webhook_<UID>
|
||||
if len(hookId) != 44 {
|
||||
log.Printf("[INFO] Couldn't handle hookId. Too short in webhook: %d", len(hookId))
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "message": "ID not valid"}`))
|
||||
resp.Write([]byte(`{"success": false, "reason": "Hook ID not valid"}`))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2022,19 +2034,19 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
||||
if hook.Status == "stopped" {
|
||||
log.Printf("[WARNING] Not running %s because hook status is stopped", hook.Id)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "The webhook isn't running. Click start to start it"}`)))
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "The webhook isn't running. Is it running?"}`)))
|
||||
return
|
||||
}
|
||||
|
||||
if len(hook.Workflows) == 0 {
|
||||
log.Printf("Not running because hook isn't connected to any workflows")
|
||||
log.Printf("[DEBUG] Not running because hook isn't connected to any workflows")
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "No workflows are defined"}`)))
|
||||
return
|
||||
}
|
||||
|
||||
if hook.Environment == "cloud" {
|
||||
log.Printf("This should trigger in the cloud. Duplicate action allowed onprem.")
|
||||
log.Printf("[DEBUG] This should trigger in the cloud. Duplicate action allowed onprem.")
|
||||
}
|
||||
|
||||
// Check auth
|
||||
@@ -2050,12 +2062,16 @@ func handleWebhookCallback(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
body, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
log.Printf("Body data error: %s", err)
|
||||
log.Printf("[DEBUG] Body data error: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
if len(queries) > 0 && len(body) == 0 {
|
||||
body = []byte(queries)
|
||||
}
|
||||
|
||||
//log.Printf("BODY: %s", parsedBody)
|
||||
|
||||
// This is a specific fix for MSteams and may fix other things as well
|
||||
@@ -5862,7 +5878,6 @@ func initHandlers() {
|
||||
r.HandleFunc("/api/v1/triggers/gmail/register", shuffle.HandleNewGmailRegister).Methods("GET", "OPTIONS")
|
||||
r.HandleFunc("/api/v1/triggers/gmail/getFolders", shuffle.HandleGetGmailFolders).Methods("GET", "OPTIONS")
|
||||
|
||||
// FIXME: This should only be cloud. Done locally with ngrok to test
|
||||
//r.HandleFunc("/api/v1/triggers/gmail/routing", handleGmailRouting).Methods("POST", "OPTIONS")
|
||||
|
||||
r.HandleFunc("/api/v1/triggers/gmail/{key}", shuffle.HandleGetSpecificTrigger).Methods("GET", "OPTIONS")
|
||||
|
||||
Reference in New Issue
Block a user