Fixed App overwrites and bad app function names
This commit is contained in:
+30
-36
@@ -510,39 +510,38 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (*openapi3.Swagger,
|
||||
for actualPath, path := range swagger.Paths {
|
||||
// FIXME: Add everything from here:
|
||||
// https://godoc.org/github.com/getkin/kin-openapi/openapi3#PathItem
|
||||
firstQuery := true
|
||||
if path.Get != nil {
|
||||
action, curCode := handleGet(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handleGet(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Connect != nil {
|
||||
action, curCode := handleConnect(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handleConnect(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Head != nil {
|
||||
action, curCode := handleHead(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handleHead(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Delete != nil {
|
||||
action, curCode := handleDelete(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handleDelete(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Post != nil {
|
||||
action, curCode := handlePost(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handlePost(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Patch != nil {
|
||||
action, curCode := handlePatch(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handlePatch(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
if path.Put != nil {
|
||||
action, curCode := handlePut(swagger, api, extraParameters, path, actualPath, firstQuery)
|
||||
action, curCode := handlePut(swagger, api, extraParameters, path, actualPath)
|
||||
api.Actions = append(api.Actions, action)
|
||||
pythonFunctions = append(pythonFunctions, curCode)
|
||||
}
|
||||
@@ -736,7 +735,7 @@ func fixFunctionName(functionName, actualPath string) string {
|
||||
return functionName
|
||||
}
|
||||
|
||||
func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Connect.Summary, actualPath)
|
||||
|
||||
@@ -756,7 +755,7 @@ func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters [
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -818,11 +817,10 @@ func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters [
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -843,7 +841,7 @@ func handleConnect(swagger *openapi3.Swagger, api WorkflowApp, extraParameters [
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Get.Summary, actualPath)
|
||||
|
||||
@@ -863,7 +861,7 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
|
||||
// FIXME - remove this when authentication is properly introduced
|
||||
@@ -930,11 +928,12 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
log.Printf("NOT FIRST QUERY!: %s", baseUrl)
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
log.Printf("AFTER: %s", baseUrl)
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -955,7 +954,7 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Head.Summary, actualPath)
|
||||
|
||||
@@ -975,7 +974,7 @@ func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -1037,11 +1036,10 @@ func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1062,7 +1060,7 @@ func handleHead(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Delete.Summary, actualPath)
|
||||
|
||||
@@ -1082,7 +1080,7 @@ func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -1144,11 +1142,10 @@ func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1169,7 +1166,7 @@ func handleDelete(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
//log.Printf("PATH: %s", actualPath)
|
||||
functionName := fixFunctionName(path.Post.Summary, actualPath)
|
||||
@@ -1192,7 +1189,7 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -1256,11 +1253,10 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1281,7 +1277,7 @@ func handlePost(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wo
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Patch.Summary, actualPath)
|
||||
|
||||
@@ -1301,7 +1297,7 @@ func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []W
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -1363,11 +1359,10 @@ func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []W
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1388,7 +1383,7 @@ func handlePatch(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []W
|
||||
return action, curCode
|
||||
}
|
||||
|
||||
func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string, firstQuery bool) (WorkflowAppAction, string) {
|
||||
func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []WorkflowAppActionParameter, path *openapi3.PathItem, actualPath string) (WorkflowAppAction, string) {
|
||||
// What to do with this, hmm
|
||||
functionName := fixFunctionName(path.Put.Summary, actualPath)
|
||||
|
||||
@@ -1408,7 +1403,7 @@ func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
||||
|
||||
// Parameters: []WorkflowAppActionParameter{},
|
||||
// FIXME - add data for POST stuff
|
||||
firstQuery = true
|
||||
firstQuery := true
|
||||
optionalQueries := []string{}
|
||||
parameters := []string{}
|
||||
optionalParameters := []WorkflowAppActionParameter{}
|
||||
@@ -1471,11 +1466,10 @@ func handlePut(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
|
||||
|
||||
if firstQuery {
|
||||
baseUrl = fmt.Sprintf("%s?%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("%s&%s={%s}", baseUrl, param.Value.Name, param.Value.Name)
|
||||
firstQuery = false
|
||||
}
|
||||
firstQuery = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-3
@@ -1906,6 +1906,7 @@ func checkAdminLogin(resp http.ResponseWriter, request *http.Request) {
|
||||
if err != nil {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
|
||||
return
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
@@ -5536,8 +5537,26 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Functions: %d", swagger.Paths)
|
||||
log.Printf("Actions: %d", len(api.Actions))
|
||||
// FIXME: CHECK IF SAME NAME AS NORMAL APP
|
||||
// Can't overwrite existing normal app
|
||||
workflowApps, err := getAllWorkflowApps(ctx)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting all workflow apps from database to verify: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "Failed to verify existence"}`))
|
||||
return
|
||||
}
|
||||
|
||||
// Same name only?
|
||||
lowerName := strings.ToLower(swagger.Info.Title)
|
||||
for _, app := range workflowApps {
|
||||
if app.Downloaded && !app.Generated && strings.ToLower(app.Name) == lowerName {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Normal app with name %s already exists. Delete it first."}`, swagger.Info.Title)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
api.Owner = user.Id
|
||||
|
||||
err = dumpApi(basePath, api)
|
||||
@@ -5843,7 +5862,7 @@ func init() {
|
||||
log.Printf("Running INIT process")
|
||||
dbclient, err = datastore.NewClient(ctx, gceProject)
|
||||
if err != nil {
|
||||
log.Printf("DBclient error during init: %s", err)
|
||||
panic(fmt.Sprintf("DBclient error during init: %s", err))
|
||||
}
|
||||
|
||||
go runInit(ctx)
|
||||
|
||||
@@ -1355,12 +1355,12 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
curapp := WorkflowApp{}
|
||||
// FIXME - can this work with ONLY AppID?
|
||||
for _, app := range workflowApps {
|
||||
log.Printf("Name Version: %s_%s, other: %s_%s", app.Name, app.AppVersion, action.AppName, action.AppVersion)
|
||||
if app.ID == action.AppID {
|
||||
curapp = app
|
||||
break
|
||||
}
|
||||
|
||||
// Has to NOT be generated
|
||||
//if app.Name == action.AppName && app.AppVersion == action.AppVersion {
|
||||
// curapp = app
|
||||
// break
|
||||
|
||||
Reference in New Issue
Block a user