From 3628812ff659a48190b4bc694f0d1ec441b39396 Mon Sep 17 00:00:00 2001 From: Frikky Date: Thu, 1 Feb 2024 14:32:31 +0100 Subject: [PATCH] Fixed api calls not following PROXY guidelines: https://github.com/Shuffle/Shuffle/issues/1318 --- backend/go-app/docker.go | 4 ++-- backend/go-app/main.go | 18 ++++++++---------- backend/go-app/walkoff.go | 37 +------------------------------------ 3 files changed, 11 insertions(+), 48 deletions(-) diff --git a/backend/go-app/docker.go b/backend/go-app/docker.go index a4565523..b7db534a 100755 --- a/backend/go-app/docker.go +++ b/backend/go-app/docker.go @@ -798,7 +798,7 @@ func getDockerImage(resp http.ResponseWriter, request *http.Request) { // Downloads and activates an app from shuffler.io if possible func handleRemoteDownloadApp(resp http.ResponseWriter, ctx context.Context, user shuffle.User, appId string) { url := fmt.Sprintf("https://shuffler.io/api/v1/apps/%s/config", appId) - log.Printf("Downloading API from %s", url) + log.Printf("[DEBUG] Downloading API from URL %s", url) req, err := http.NewRequest( "GET", url, @@ -812,7 +812,7 @@ func handleRemoteDownloadApp(resp http.ResponseWriter, ctx context.Context, user return } - httpClient := &http.Client{} + httpClient := shuffle.GetExternalClient(url) newresp, err := httpClient.Do(req) if err != nil { log.Printf("[ERROR] Failed running auto-download request for %s: %s", appId, err) diff --git a/backend/go-app/main.go b/backend/go-app/main.go index b702f16d..e291c9ae 100755 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -1972,13 +1972,8 @@ func executeCloudAction(action shuffle.CloudSyncJob, apikey string) error { return err } - //transport := http.DefaultTransport.(*http.Transport).Clone() - //client := &http.Client{ - // Transport: transport, - //} - client := &http.Client{} - syncUrl := fmt.Sprintf("%s/api/v1/cloud/sync/handle_action", syncUrl) + client := shuffle.GetExternalClient(syncUrl) req, err := http.NewRequest( "POST", syncUrl, @@ -3483,8 +3478,8 @@ func remoteOrgJobHandler(org shuffle.Org, interval int) error { } - client := &http.Client{} syncUrl := fmt.Sprintf("%s/api/v1/cloud/sync", syncUrl) + client := shuffle.GetExternalClient(syncUrl) req, err := http.NewRequest( "POST", syncUrl, @@ -3867,6 +3862,9 @@ func runInitEs(ctx context.Context) { log.Printf("[INFO] Running schedule for cleaning up or re-running unfinished workflows in %d environments.", len(environments)) for _, environment := range environments { + // Allowed without PROXY management as it's localhost + // client := shuffle.GetExternalClient(syncUrl) + httpClient := &http.Client{} url := fmt.Sprintf("http://localhost:5001/api/v1/environments/%s/stop", environment) req, err := http.NewRequest( @@ -4077,7 +4075,7 @@ func handleVerifyCloudsync(orgId string) (shuffle.SyncFeatures, error) { //r.HandleFunc("/api/v1/getorgs", handleGetOrgs).Methods("GET", "OPTIONS") syncURL := fmt.Sprintf("%s/api/v1/cloud/sync/get_access", syncUrl) - client := &http.Client{} + client := shuffle.GetExternalClient(syncURL) req, err := http.NewRequest( "GET", syncURL, @@ -4121,7 +4119,7 @@ func handleStopCloudSync(syncUrl string, org shuffle.Org) (*shuffle.Org, error) log.Printf("[INFO] Should run cloud sync disable for org %s with URL %s and sync key %s", org.Id, syncUrl, org.SyncConfig.Apikey) - client := &http.Client{} + client := shuffle.GetExternalClient(syncUrl) req, err := http.NewRequest( "DELETE", syncUrl, @@ -4292,7 +4290,6 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) { //log.Printf("Apidata: %s", tmpData.Apikey) // FIXME: Path - client := &http.Client{} apiPath := "/api/v1/cloud/sync/setup" if tmpData.Disable { if !org.CloudSync { @@ -4362,6 +4359,7 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) { bytes.NewBuffer(b), ) + client := shuffle.GetExternalClient(syncPath) newresp, err := client.Do(req) if err != nil { resp.WriteHeader(400) diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 659c52b3..c1e71f2f 100755 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -952,42 +952,7 @@ func deleteWorkflow(resp http.ResponseWriter, request *http.Request) { resp.Write([]byte(`{"success": true}`)) } -// Identifies what a category defined really is -func getWorkflowLocal(fileId string, request *http.Request) ([]byte, error) { - fullUrl := fmt.Sprintf("%s/api/v1/workflows/%s", localBase, fileId) - client := &http.Client{} - req, err := http.NewRequest( - "GET", - fullUrl, - nil, - ) - - if err != nil { - return []byte{}, err - } - - for key, value := range request.Header { - req.Header.Add(key, strings.Join(value, ";")) - } - - newresp, err := client.Do(req) - if err != nil { - return []byte{}, err - } - - body, err := ioutil.ReadAll(newresp.Body) - if err != nil { - return []byte{}, err - } - - // Temporary solution - if strings.Contains(string(body), "reason") && strings.Contains(string(body), "false") { - return []byte{}, errors.New(fmt.Sprintf("Failed getting workflow %s with message %s", fileId, string(body))) - } - - return body, nil -} func handleExecution(id string, workflow shuffle.Workflow, request *http.Request, orgId string) (shuffle.WorkflowExecution, string, error) { //go func() { @@ -1777,7 +1742,7 @@ func cloudExecuteAction(execution shuffle.WorkflowExecution) error { } syncURL := fmt.Sprintf("%s/api/v1/cloud/sync/execute_node", syncUrl) - client := &http.Client{} + client := shuffle.GetExternalClient(syncURL) req, err := http.NewRequest( "POST", syncURL,