Skip to content

Commit

Permalink
Fixed shared folder
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Jan 26, 2021
1 parent f06030e commit a3b8d56
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ func SetNewWorkflow(resp http.ResponseWriter, request *http.Request) {
return
}

//memcacheName := fmt.Sprintf("%s_workflows", user.Username)
//memcache.Delete(ctx, memcacheName)
memcacheName := fmt.Sprintf("%s_workflows", user.Username)
memcache.Delete(ctx, memcacheName)

resp.WriteHeader(200)
//log.Println(string(workflowjson))
Expand Down Expand Up @@ -1147,7 +1147,7 @@ func ValidateSwagger(resp http.ResponseWriter, request *http.Request) {
}

// Just here to verify that the user is logged in
_, err := HandleApiAuthentication(resp, request)
user, err := HandleApiAuthentication(resp, request)
if err != nil {
log.Printf("Api authentication failed in validate swagger: %s", err)
resp.WriteHeader(401)
Expand Down Expand Up @@ -1208,6 +1208,7 @@ func ValidateSwagger(resp http.ResponseWriter, request *http.Request) {
log.Printf("[INFO] Version: %#v", version)
log.Printf("[INFO] OpenAPI: %s", version.OpenAPI)

ctx := context.Background()
if strings.HasPrefix(version.Swagger, "3.") || strings.HasPrefix(version.OpenAPI, "3.") {
log.Println("[INFO] Handling v3 API")
swaggerLoader := openapi3.NewSwaggerLoader()
Expand Down Expand Up @@ -1254,6 +1255,9 @@ func ValidateSwagger(resp http.ResponseWriter, request *http.Request) {
log.Printf("[INFO] Successfully set OpenAPI with ID %s", idstring)
resp.WriteHeader(200)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "id": "%s"}`, idstring)))

memcache.Delete(ctx, "all_apps")
memcache.Delete(ctx, fmt.Sprintf("apps_%s", user.Id))
return
} else { //strings.HasPrefix(version.Swagger, "2.") || strings.HasPrefix(version.OpenAPI, "2.") {
// Convert
Expand Down Expand Up @@ -1305,7 +1309,6 @@ func ValidateSwagger(resp http.ResponseWriter, request *http.Request) {
Body: string(swaggerdata),
}

ctx := context.Background()
err = SetOpenApiDatastore(ctx, idstring, parsed)
if err != nil {
log.Printf("Failed uploading openapi2 to datastore: %s", err)
Expand All @@ -1316,6 +1319,9 @@ func ValidateSwagger(resp http.ResponseWriter, request *http.Request) {

resp.WriteHeader(200)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "id": "%s"}`, idstring)))

memcache.Delete(ctx, "all_apps")
memcache.Delete(ctx, fmt.Sprintf("apps_%s", user.Id))
return
}
/*
Expand Down Expand Up @@ -1390,3 +1396,64 @@ func HandleGetUsers(resp http.ResponseWriter, request *http.Request) {
resp.WriteHeader(200)
resp.Write(newjson)
}

func GetOpenapi(resp http.ResponseWriter, request *http.Request) {
cors := HandleCors(resp, request)
if cors {
return
}

// Just here to verify that the user is logged in
_, err := HandleApiAuthentication(resp, request)
if err != nil {
log.Printf("Api authentication failed in validate swagger: %s", err)
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

location := strings.Split(request.URL.String(), "/")
var id string
if location[1] == "api" {
if len(location) <= 4 {
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

id = location[4]
}

if len(id) != 32 {
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

// FIXME - FIX AUTH WITH APP
ctx := context.Background()
//_, err = GetApp(ctx, id)
//if err == nil {
// log.Println("You're supposed to be able to continue now.")
//}

parsedApi, err := GetOpenApiDatastore(ctx, id)
if err != nil {
resp.WriteHeader(401)
resp.Write([]byte(`{"success": false}`))
return
}

log.Printf("[INFO] API LENGTH GET: %d, ID: %s", len(parsedApi.Body), id)

parsedApi.Success = true
data, err := json.Marshal(parsedApi)
if err != nil {
resp.WriteHeader(422)
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Failed marshalling parsed swagger: %s"}`, err)))
return
}

resp.WriteHeader(200)
resp.Write(data)
}

0 comments on commit a3b8d56

Please sign in to comment.