Started adding web3 functionality + some bug fixes

This commit is contained in:
frikky
2021-11-05 04:12:10 +01:00
parent 15479ea0f7
commit a82716f0ee
13 changed files with 512 additions and 72 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/h2non/filetype v1.1.1
github.com/satori/go.uuid v1.2.0
github.com/shuffle/shuffle-shared v0.1.28
github.com/shuffle/shuffle-shared v0.1.30
go4.org v0.0.0-20201209231011-d4a079459e60 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
google.golang.org/api v0.58.0
+20
View File
@@ -1003,6 +1003,24 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
}
}
// FIXME: This is bad, but we've had a lot of bugs with edit users, and this is the quick fix.
if userInfo.Role == "" && userInfo.ActiveOrg.Role == "" && parsedAdmin == "false" {
userInfo.Role = "admin"
userInfo.ActiveOrg.Role = "admin"
parsedAdmin = "true"
err = shuffle.SetUser(ctx, &userInfo, true)
if err != nil {
log.Printf("[WARNING] Automatically asigning user as admin to their org because they don't have a role at all failed: %s", err)
resp.WriteHeader(500)
resp.Write([]byte(`{"success": false}`))
return
} else {
log.Printf("[DEBUG] Made user %s org-admin as they didn't have any role specified", err)
}
}
returnValue := shuffle.HandleInfo{
Success: true,
Username: userInfo.Username,
@@ -1017,6 +1035,7 @@ func handleInfo(resp http.ResponseWriter, request *http.Request) {
Expiration: expiration.Unix(),
},
},
EthInfo: userInfo.EthInfo,
}
returnData, err := json.Marshal(returnValue)
@@ -5785,6 +5804,7 @@ func initHandlers() {
// This is a new API that validates if a key has been seen before.
// Not sure what the best course of action is for it.
r.HandleFunc("/api/v1/environments/{key}/stop", shuffle.HandleStopExecutions).Methods("GET", "POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/validate_app_values", shuffle.HandleKeyValueCheck).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/get_cache", shuffle.HandleGetCacheKey).Methods("POST", "OPTIONS")
r.HandleFunc("/api/v1/orgs/{orgId}/set_cache", shuffle.HandleSetCacheKey).Methods("POST", "OPTIONS")
+12 -6
View File
@@ -577,7 +577,7 @@ func handleGetWorkflowqueueConfirm(resp http.ResponseWriter, request *http.Reque
//setWorkflowqueuetest(id)
ctx := context.Background()
executionRequests, err := shuffle.GetWorkflowQueue(ctx, id)
executionRequests, err := shuffle.GetWorkflowQueue(ctx, id, 100)
if err != nil {
log.Printf("[WARNING] (1) Failed reading body for workflowqueue: %s", err)
resp.WriteHeader(401)
@@ -689,7 +689,7 @@ func handleGetWorkflowqueue(resp http.ResponseWriter, request *http.Request) {
}
}
executionRequests, err := shuffle.GetWorkflowQueue(ctx, id)
executionRequests, err := shuffle.GetWorkflowQueue(ctx, id, 100)
if err != nil {
// Skipping as this comes up over and over
//log.Printf("(2) Failed reading body for workflowqueue: %s", err)
@@ -838,7 +838,7 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "success"}`)))
return
} else {
//log.Printf("[WARNING] Handling other execution variant: %s", err)
log.Printf("[DEBUG] Handling other execution variant: %s", err)
}
var actionResult shuffle.ActionResult
@@ -962,9 +962,15 @@ func runWorkflowExecutionTransaction(ctx context.Context, attempts int64, workfl
//log.Printf("BASE LENGTH: %d", len(workflowExecution.Results))
workflowExecution, dbSave, err := shuffle.ParsedExecutionResult(ctx, *workflowExecution, actionResult, false)
if err != nil {
log.Printf("[ERROR] Failed running of parsedexecution: %s", err)
b, suberr := json.Marshal(actionResult)
if suberr != nil {
log.Printf("[ERROR] Failed running of parsedexecution: %s", err)
} else {
log.Printf("[ERROR] Failed running of parsedexecution: %s. Data: %s", err, string(b))
}
resp.WriteHeader(401)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed getting execution"}`)))
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed updating execution"}`)))
return
}
@@ -1284,7 +1290,7 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
workflowExecution, execInfo, _, err := shuffle.PrepareWorkflowExecution(ctx, workflow, request)
if err != nil {
log.Printf("[WARNING] Failed in prepareExecution: %s", err)
return shuffle.WorkflowExecution{}, "", err
return shuffle.WorkflowExecution{}, fmt.Sprintf("Failed preparration: %s", err), err
}
err = imageCheckBuilder(execInfo.ImageNames)
+1
View File
@@ -0,0 +1 @@
#