fix: audit platform contracts and relation identities
This commit is contained in:
44
backend/api/cmd/resource-contract/main.go
Normal file
44
backend/api/cmd/resource-contract/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/routers"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type route struct {
|
||||
Method string `json:"method"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
type contract struct {
|
||||
Domain string `json:"domain"`
|
||||
Name string `json:"name"`
|
||||
PageKind string `json:"pageKind"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
type manifest struct {
|
||||
Resources []contract `json:"resources"`
|
||||
Routes []route `json:"routes"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
engine := gin.New()
|
||||
routers.RegisterPlatform("heqi", engine)
|
||||
routes := make([]route, 0, len(engine.Routes()))
|
||||
for _, item := range engine.Routes() {
|
||||
routes = append(routes, route{Method: item.Method, Path: strings.TrimPrefix(item.Path, "/heqi/platform/v1")})
|
||||
}
|
||||
expected := platform.ExpectedResources()
|
||||
contracts := make([]contract, 0, len(expected))
|
||||
for _, item := range expected {
|
||||
contracts = append(contracts, contract{Domain: item.Domain, Name: item.Name, PageKind: item.PageKind, Mode: string(item.Mode)})
|
||||
}
|
||||
if err := json.NewEncoder(os.Stdout).Encode(manifest{Resources: contracts, Routes: routes}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user