From 5cb19669bea2aa770bd1c2ed4b58c13be065697d Mon Sep 17 00:00:00 2001 From: frikky Date: Sun, 5 Jul 2020 11:25:08 +0200 Subject: [PATCH 1/5] Added proxy options --- .env | 2 +- backend/go-app/go.sum | 1 + backend/go-app/main.go | 49 ++++++++++++++++++++++++++++- backend/go-app/walkoff.go | 9 +++++- docker-compose.yml | 6 ++-- frontend/src/Docs.js | 6 ++-- frontend/src/Workflows.js | 13 ++++++++ functions/onprem/orborus/orborus.go | 2 ++ install-guide.md | 2 +- 9 files changed, 80 insertions(+), 10 deletions(-) diff --git a/.env b/.env index ee13a292..c40fc26c 100644 --- a/.env +++ b/.env @@ -13,7 +13,7 @@ SHUFFLE_DEFAULT_PASSWORD= SHUFFLE_DEFAULT_APIKEY= # Local location of your app directory. Can't use ~/ -APP_HOTLOAD_LOCATION=./shuffle-apps +SHUFFLE_APP_HOTLOAD_LOCATION=./shuffle-apps # Other configs BACKEND_HOSTNAME=shuffle-backend diff --git a/backend/go-app/go.sum b/backend/go-app/go.sum index 6bff1e65..8f640a73 100644 --- a/backend/go-app/go.sum +++ b/backend/go-app/go.sum @@ -395,6 +395,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE= diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 8ff15f1f..ce2633db 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -28,6 +28,7 @@ import ( "cloud.google.com/go/datastore" "cloud.google.com/go/pubsub" "cloud.google.com/go/storage" + "google.golang.org/api/option" "google.golang.org/appengine/mail" "github.com/getkin/kin-openapi/openapi2" @@ -50,9 +51,14 @@ import ( "golang.org/x/crypto/bcrypt" "gopkg.in/yaml.v3" + // PROXY overrides + // "gopkg.in/src-d/go-git.v4/plumbing/transport/client" + // githttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http" + // Web // "github.com/gorilla/handlers" "github.com/gorilla/mux" + "google.golang.org/grpc" http2 "gopkg.in/src-d/go-git.v4/plumbing/transport/http" // Old items (cloud) // "google.golang.org/appengine" @@ -2466,6 +2472,7 @@ func setUser(ctx context.Context, data *User) error { // Used for testing only. Shouldn't impact production. func handleCors(resp http.ResponseWriter, request *http.Request) bool { + //allowedOrigins := "*" allowedOrigins := "http://localhost:3000" resp.Header().Set("Vary", "Origin") @@ -6144,6 +6151,45 @@ func runInit(ctx context.Context) { if err != nil { log.Printf("Failed increasing local stats: %s", err) } + log.Printf("Finalized init statistics update") + + httpProxy := os.Getenv("HTTP_PROXY") + if len(httpProxy) > 0 { + log.Printf("Running with HTTP proxy %s (env: HTTP_PROXY)", httpProxy) + } + + /* + proxyUrl, err := url.Parse(httpProxy) + if err != nil { + log.Printf("Failed setting up proxy: %s", err) + } else { + // accept any certificate (might be useful for testing) + customClient := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + Proxy: http.ProxyURL(proxyUrl), + }, + + // 15 second timeout + Timeout: 15 * time.Second, + + // don't follow redirect + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } + + // Override http(s) default protocol to use our custom client + client.InstallProtocol("http", githttp.NewClient(customClient)) + client.InstallProtocol("https", githttp.NewClient(customClient)) + } + } + + httpsProxy := os.Getenv("SHUFFLE_HTTPS_PROXY") + if len(httpsProxy) > 0 { + log.Printf("Running with HTTPS proxy %s", httpsProxy) + } + */ // Fix active users etc q := datastore.NewQuery("Users").Filter("active =", true) @@ -6337,7 +6383,8 @@ func init() { log.Printf("Starting Shuffle backend - initializing database connection") // option.WithoutAuthentication - dbclient, err = datastore.NewClient(ctx, gceProject) + + dbclient, err = datastore.NewClient(ctx, gceProject, option.WithGRPCDialOption(grpc.WithNoProxy())) if err != nil { panic(fmt.Sprintf("DBclient error during init: %s", err)) } diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 36b78bd4..660db8fd 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -1375,7 +1375,7 @@ func deleteWorkflow(resp http.ResponseWriter, request *http.Request) { resp.Write([]byte(`{"success": true}`)) } -// FIXME - check whether all nodes has a branch, otherwise go back +// Saves a workflow to an ID func saveWorkflow(resp http.ResponseWriter, request *http.Request) { cors := handleCors(resp, request) if cors { @@ -1462,6 +1462,11 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) { return } + // Fixing wrong owners when importing + if workflow.Owner == "" { + workflow.Owner = user.Id + } + // FIXME - this shouldn't be necessary with proper API checks newActions := []Action{} allNodes := []string{} @@ -1491,6 +1496,8 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) { workflow.Actions = newActions for _, trigger := range workflow.Triggers { + log.Printf("Trigger %s: %s", trigger.TriggerType, trigger.Status) + //log.Println("TRIGGERS") allNodes = append(allNodes, trigger.ID) } diff --git a/docker-compose.yml b/docker-compose.yml index b74d7a3c..aeb10bf8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: depends_on: - backend backend: - #build: ./backend + build: ./backend image: frikky/shuffle:backend container_name: shuffle-backend hostname: ${BACKEND_HOSTNAME} @@ -25,10 +25,10 @@ services: - shuffle volumes: - /var/run/docker.sock:/var/run/docker.sock - - ${APP_HOTLOAD_LOCATION}:/shuffle-apps + - ${SHUFFLE_APP_HOTLOAD_LOCATION}:/shuffle-apps environment: - DATASTORE_EMULATOR_HOST=shuffle-database:8000 - - APP_HOTLOAD_FOLDER=/shuffle-apps + - SHUFFLE_APP_HOTLOAD_FOLDER=/shuffle-apps - ORG_ID=${ORG_ID} - APP_DOWNLOAD_LOCATION=${APP_DOWNLOAD_LOCATION} - SHUFFLE_DEFAULT_USERNAME=${SHUFFLE_DEFAULT_USERNAME} diff --git a/frontend/src/Docs.js b/frontend/src/Docs.js index 06917bda..badec6ee 100644 --- a/frontend/src/Docs.js +++ b/frontend/src/Docs.js @@ -62,7 +62,7 @@ const Docs = (props) => { if (parent !== null) { var elements = parent.getElementsByTagName('h2') - const name = window.location.hash.slice(1, window.location.hash.lenth).toLowerCase().split("%20").join(" ").split("_").join(" ") + const name = window.location.hash.slice(1, window.location.hash.lenth).toLowerCase().split("%20").join(" ").split("_").join(" ").split("-").join(" ") console.log(name) var found = false @@ -214,7 +214,7 @@ const Docs = (props) => {