Moved documentation to shared

This commit is contained in:
frikky
2021-06-04 08:45:59 +02:00
parent 90469f9d0f
commit d8d64b858f
4 changed files with 9 additions and 201 deletions
+1 -1
View File
@@ -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=
+1 -1
View File
@@ -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
+3 -195
View File
@@ -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
+4 -4
View File
@@ -2058,7 +2058,7 @@ const AppCreator = (props) => {
<FormControl style={{backgroundColor: surfaceColor, color: "white",}}>
<DialogTitle><div style={{color: "white"}}>New action</div></DialogTitle>
<DialogContent>
<a target="_blank" href="https://shuffler.io/docs/apps#create_openapi_app" style={{textDecoration: "none", color: "#f85a3e"}}>Learn more about actions</a>
<a target="_blank" href="https://shuffler.io/docs/app_creation#actions" style={{textDecoration: "none", color: "#f85a3e"}}>Learn more about actions</a>
<div style={{marginTop: "15px"}}/>
Name
<TextField
@@ -2748,7 +2748,7 @@ const AppCreator = (props) => {
return (
<div>
<DialogContent>
<a target="_blank" rel="norefferer" href="https://shuffler.io/docs/apps#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is this?</a><div/>
<a target="_blank" rel="norefferer" href="https://shuffler.io/docs/app_creation#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is this?</a><div/>
These are required fields for authenticating with {selectedApp.name}
<div style={{marginTop: 15}}/>
<b>Name - what is this used for?</b>
@@ -2871,7 +2871,7 @@ const AppCreator = (props) => {
<div style={{color: "white"}}>
<h2>Test</h2>
Test an action to see whether it performs in an expected way.
<a target="_blank" href="https://shuffler.io/docs/apps#testing" style={{textDecoration: "none", color: "#f85a3e"}}>&nbsp;TBD: Click here to learn more about testing</a>.
<a target="_blank" href="https://shuffler.io/docs/app_creation#testing" style={{textDecoration: "none", color: "#f85a3e"}}>&nbsp;TBD: Click here to learn more about testing</a>.
<div>
Test :)
</div>
@@ -3055,7 +3055,7 @@ const AppCreator = (props) => {
<input hidden type="file" ref={(ref) => upload = ref} onChange={editHeaderImage} />
<Paper style={boxStyle}>
<h2 style={{marginBottom: "10px", color: "white"}}>General information</h2>
<a target="_blank" href="https://shuffler.io/docs/apps#create_openapi_app" style={{textDecoration: "none", color: "#f85a3e"}}>Click here to learn more about app creation</a>
<a target="_blank" href="https://shuffler.io/docs/app_creation#app-creator-instructions" style={{textDecoration: "none", color: "#f85a3e"}}>Click here to learn more about app creation</a>
<div style={{color: "white", flex: "1", display: "flex", flexDirection: "row"}}>
<Tooltip title="Click to edit the app's image" placement="bottom">
<div style={{flex: "1", margin: 10, border: "1px solid #f85a3e", cursor: "pointer", backgroundColor: inputColor, maxWidth: 174, maxHeight: 174}} onClick={() => {