2023-03-03 14:43:11 +01:00
|
|
|
// @APIVersion 1.0.0
|
|
|
|
// @Title oc-catalog API
|
|
|
|
// @Description Backend of the oc-search project
|
|
|
|
// @Contact opencloud@irt-saintexupery.com
|
|
|
|
//// @SecurityDefinition jwtAPIToken apiKey Authorization header "API authentication with JWT tokens"
|
|
|
|
|
|
|
|
package routers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2024-07-29 18:02:29 +02:00
|
|
|
"cloud.o-forge.io/core/deprecated-oc-catalog/controllers"
|
|
|
|
"cloud.o-forge.io/core/deprecated-oc-catalog/services"
|
2023-03-03 14:43:11 +01:00
|
|
|
|
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
|
|
|
|
|
"github.com/beego/beego/v2/adapter/swagger"
|
|
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
|
|
"github.com/beego/beego/v2/server/web/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootapi swagger.Swagger
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
// Remove old swagger comments
|
|
|
|
err := os.Remove("routers/commentsRouter_controllers.go")
|
|
|
|
if err != nil {
|
|
|
|
logs.Warning("Couldn't remove comments file: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
ns := beego.NewNamespace("/v1",
|
|
|
|
beego.NSNamespace("/user",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.UserController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/data",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.DataController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/computing",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.ComputingController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/datacenter",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.DatacenterController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/storage",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.StorageController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/search",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.SearchController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/workspace",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.WorkspaceController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/workflow",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.WorkflowController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
beego.NSNamespace("/schedule",
|
|
|
|
beego.NSInclude(
|
|
|
|
&controllers.ScheduleController{},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
beego.AddNamespace(ns)
|
|
|
|
|
|
|
|
beego.Get("/", func(ctx *context.Context) {
|
|
|
|
ctx.Output.Body([]byte(services.DC_NAME))
|
|
|
|
})
|
|
|
|
|
2024-02-15 10:52:29 +01:00
|
|
|
// Force regenerate swagger before consuming the data
|
2023-11-02 15:49:33 +01:00
|
|
|
// bee.GenerateDocs(".")
|
2023-03-03 14:43:11 +01:00
|
|
|
|
|
|
|
// Open our jsonFile
|
|
|
|
swaggerSchemaPath := "swagger/swagger.json"
|
|
|
|
swaggerFile, err := os.Open(swaggerSchemaPath)
|
|
|
|
// if we os.Open returns an error then handle it
|
|
|
|
if err != nil {
|
|
|
|
logs.Critical("Error opening %v: %v", swaggerSchemaPath, err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// defer the closing of our jsonFile so that we can parse it later on
|
|
|
|
defer swaggerFile.Close()
|
|
|
|
|
|
|
|
byteValue, err := ioutil.ReadAll(swaggerFile)
|
|
|
|
if err != nil {
|
|
|
|
logs.Critical("Error reading %v: %v", swaggerSchemaPath, err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
json.Unmarshal(byteValue, &rootapi)
|
|
|
|
|
|
|
|
// To simplify match of Paths, we must adapt swagger path representation to beego router
|
|
|
|
// For example: /path/{myID} will be /path/:myID
|
|
|
|
for k, v := range rootapi.Paths {
|
|
|
|
if strings.ContainsAny(k, "{}") {
|
|
|
|
newKey := strings.Replace(k, "{", ":", -1)
|
|
|
|
newKey = strings.Replace(newKey, "}", "", -1)
|
|
|
|
|
|
|
|
rootapi.Paths[newKey] = v
|
|
|
|
delete(rootapi.Paths, k)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init some extra stuff
|
|
|
|
initAuthMiddleware()
|
|
|
|
initUglyFixes()
|
|
|
|
}
|
2024-02-19 17:24:14 +01:00
|
|
|
|