From d8d64b858f7f3e8f08a47de73985340ae94c3519 Mon Sep 17 00:00:00 2001 From: frikky Date: Fri, 4 Jun 2021 08:45:59 +0200 Subject: [PATCH] Moved documentation to shared --- .env | 2 +- backend/go-app/go.mod | 2 +- backend/go-app/main.go | 198 +----------------------------- frontend/src/views/AppCreator.jsx | 8 +- 4 files changed, 9 insertions(+), 201 deletions(-) diff --git a/.env b/.env index 27cf372b..9fadb1fd 100644 --- a/.env +++ b/.env @@ -50,7 +50,7 @@ SHUFFLE_CONTAINER_AUTO_CLEANUP=false SHUFFLE_ELASTIC=true # DATABASE CONFIGURATIONS -DATASTORE_EMULATOR_HOST=shuffl-database:8000 +DATASTORE_EMULATOR_HOST=shuffle-database:8000 SHUFFLE_OPENSEARCH_URL=http://shuffle-opensearch:9200 SHUFFLE_OPENSEARCH_USERNAME= SHUFFLE_OPENSEARCH_PASSWORD= diff --git a/backend/go-app/go.mod b/backend/go-app/go.mod index 5f4de234..1dd998ab 100644 --- a/backend/go-app/go.mod +++ b/backend/go-app/go.mod @@ -2,7 +2,7 @@ module shuffle go 1.13 -//replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared +replace github.com/frikky/shuffle-shared => ../../../../git/shuffle-shared //replace github.com/frikky/kin-openapi => ../../../../git/kin-openapi diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 438ebc88..fee98601 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -44,8 +44,6 @@ import ( "github.com/frikky/kin-openapi/openapi3" */ - "github.com/google/go-github/v28/github" - "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-git/v5" @@ -2824,197 +2822,7 @@ type Result struct { List []string `json:"list"` } -var docs_list = Result{List: []string{}} - -func getDocList(resp http.ResponseWriter, request *http.Request) { - cors := handleCors(resp, request) - if cors { - return - } - - ctx := context.Background() - //if item, err := memcache.Get(ctx, "docs_list"); err == memcache.ErrCacheMiss { - // // Not in cache - //} else if err != nil { - // // Error with cache - // log.Printf("Error getting item: %v", err) - //} else { - // resp.WriteHeader(200) - // resp.Write([]byte(item.Value)) - // return - //} - - if len(docs_list.List) > 0 { - b, err := json.Marshal(docs_list) - if err != nil { - log.Printf("Failed marshaling result: %s", err) - //http.Error(resp, err.Error(), 500) - } else { - resp.WriteHeader(200) - resp.Write(b) - return - } - } - - client := github.NewClient(nil) - _, item1, _, err := client.Repositories.GetContents(ctx, "frikky", "shuffle-docs", "docs", nil) - if err != nil { - log.Printf("Github error: %s", err) - resp.WriteHeader(500) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Error listing directory: %s"`, err))) - return - } - - if len(item1) == 0 { - resp.WriteHeader(500) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "No docs available."}`))) - return - } - - names := []string{} - for _, item := range item1 { - if !strings.HasSuffix(*item.Name, "md") { - continue - } - - names = append(names, (*item.Name)[0:len(*item.Name)-3]) - } - - log.Println(names) - - var result Result - result.Success = true - result.Reason = "Success" - result.List = names - docs_list = result - - b, err := json.Marshal(result) - if err != nil { - http.Error(resp, err.Error(), 500) - return - } - - //item := &memcache.Item{ - // Key: "docs_list", - // Value: b, - // Expiration: time.Minute * 60, - //} - - //if err := memcache.Add(ctx, item); err == memcache.ErrNotStored { - // if err := memcache.Set(ctx, item); err != nil { - // log.Printf("Error setting item: %v", err) - // } - //} else if err != nil { - // log.Printf("error adding item: %v", err) - //} else { - // log.Printf("Set cache for %s", item.Key) - //} - - resp.WriteHeader(200) - resp.Write(b) -} - // r.HandleFunc("/api/v1/docs/{key}", getDocs).Methods("GET", "OPTIONS") -var alldocs = map[string][]byte{} - -func getDocs(resp http.ResponseWriter, request *http.Request) { - cors := handleCors(resp, request) - if cors { - return - } - - location := strings.Split(request.URL.String(), "/") - if len(location) != 5 { - resp.WriteHeader(404) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Bad path. Use e.g. /api/v1/docs/workflows.md"}`))) - return - } - - //ctx := context.Background() - docPath := fmt.Sprintf("https://raw.githubusercontent.com/shaffuru/shuffle-docs/master/docs/%s.md", location[4]) - //location[4] - //var, ok := alldocs["asd"] - key, ok := alldocs[fmt.Sprintf("%s", location[4])] - // Custom cache for github issues lol - if ok { - resp.WriteHeader(200) - resp.Write(key) - return - } - - client := &http.Client{} - req, err := http.NewRequest( - "GET", - docPath, - nil, - ) - - if err != nil { - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Bad path. Use e.g. /api/v1/docs/workflows.md"}`))) - resp.WriteHeader(404) - //setBadMemcache(ctx, docPath) - return - } - - newresp, err := client.Do(req) - if err != nil { - resp.WriteHeader(404) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Bad path. Use e.g. /api/v1/docs/workflows.md"}`))) - //setBadMemcache(ctx, docPath) - return - } - - body, err := ioutil.ReadAll(newresp.Body) - if err != nil { - resp.WriteHeader(500) - resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Can't parse data"}`))) - //setBadMemcache(ctx, docPath) - return - } - - type Result struct { - Success bool `json:"success"` - Reason string `json:"reason"` - } - - var result Result - result.Success = true - - //applog.Infof(ctx, string(body)) - //applog.Infof(ctx, "Url: %s", docPath) - //applog.Infof(ctx, "Status: %d", newresp.StatusCode) - //applog.Infof(ctx, "GOT BODY OF LENGTH %d", len(string(body))) - - result.Reason = string(body) - b, err := json.Marshal(result) - if err != nil { - http.Error(resp, err.Error(), 500) - //setBadMemcache(ctx, docPath) - return - } - - alldocs[location[4]] = b - - // Add to cache if it doesn't exist - //item := &memcache.Item{ - // Key: docPath, - // Value: b, - // Expiration: time.Minute * 60, - //} - - //if err := memcache.Add(ctx, item); err == memcache.ErrNotStored { - // if err := memcache.Set(ctx, item); err != nil { - // log.Printf("Error setting item: %v", err) - // } - //} else if err != nil { - // log.Printf("error adding item: %v", err) - //} else { - // log.Printf("Set cache for %s", item.Key) - //} - - resp.WriteHeader(200) - resp.Write(b) -} func getOpenapi(resp http.ResponseWriter, request *http.Request) { cors := handleCors(resp, request) @@ -5735,7 +5543,7 @@ func initHandlers() { } for { - _, err = shuffle.RunInit(*dbclient, *es, storage.Client{}, gceProject, "onprem", true, "elasticsearch") + _, err = shuffle.RunInit(*dbclient, *es, storage.Client{}, gceProject, "onprem", true, elasticConfig) if err != nil { log.Printf("[DEBUG] Error in initial database connection. Retrying in 5 seconds. %s", err) time.Sleep(5 * time.Second) @@ -5786,8 +5594,8 @@ func initHandlers() { r.HandleFunc("/api/v1/getenvironments", shuffle.HandleGetEnvironments).Methods("GET", "OPTIONS") r.HandleFunc("/api/v1/setenvironments", shuffle.HandleSetEnvironments).Methods("PUT", "OPTIONS") - r.HandleFunc("/api/v1/docs", getDocList).Methods("GET", "OPTIONS") - r.HandleFunc("/api/v1/docs/{key}", getDocs).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/docs", shuffle.GetDocList).Methods("GET", "OPTIONS") + r.HandleFunc("/api/v1/docs/{key}", shuffle.GetDocs).Methods("GET", "OPTIONS") // Queuebuilder and Workflow streams. First is to update a stream, second to get a stream // Changed from workflows/streams to streams, as appengine was messing up diff --git a/frontend/src/views/AppCreator.jsx b/frontend/src/views/AppCreator.jsx index 01dade27..6088f02f 100644 --- a/frontend/src/views/AppCreator.jsx +++ b/frontend/src/views/AppCreator.jsx @@ -2058,7 +2058,7 @@ const AppCreator = (props) => {
New action
- Learn more about actions + Learn more about actions
Name { return (
- What is this?
+ What is this?
These are required fields for authenticating with {selectedApp.name}
Name - what is this used for? @@ -2871,7 +2871,7 @@ const AppCreator = (props) => {

Test

Test an action to see whether it performs in an expected way. -  TBD: Click here to learn more about testing. +  TBD: Click here to learn more about testing.
Test :)
@@ -3055,7 +3055,7 @@ const AppCreator = (props) => { upload = ref} onChange={editHeaderImage} />

General information

- Click here to learn more about app creation + Click here to learn more about app creation
{