Change code generator (#4)

* Change code generator
* Remove gin
This commit is contained in:
Jonas Plum
2022-01-08 00:48:44 +01:00
committed by GitHub
parent b5dd0cfacd
commit 8333ea88a8
148 changed files with 3077 additions and 23976 deletions

View File

@@ -3,18 +3,16 @@ package main
import (
"context"
"log"
"net/http"
"net/http/httputil"
"net/url"
"github.com/arangodb/go-driver"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/SecurityBrewery/catalyst"
"github.com/SecurityBrewery/catalyst/cmd"
"github.com/SecurityBrewery/catalyst/database/busdb"
"github.com/SecurityBrewery/catalyst/generated/models"
"github.com/SecurityBrewery/catalyst/generated/model"
"github.com/SecurityBrewery/catalyst/hooks"
"github.com/SecurityBrewery/catalyst/role"
"github.com/SecurityBrewery/catalyst/test"
@@ -36,30 +34,25 @@ func main() {
log.Fatal(err)
}
demoUser := &models.UserResponse{ID: "demo", Roles: []string{role.Admin}}
demoUser := &model.UserResponse{ID: "demo", Roles: []string{role.Admin}}
ctx := busdb.UserContext(context.Background(), demoUser)
if err := test.SetupTestData(ctx, theCatalyst.DB); err != nil {
log.Fatal(err)
}
// proxy static requests
theCatalyst.Server.NoRoute(
sessions.Sessions(catalyst.SessionName, cookie.NewStore(config.Secret)),
catalyst.Authenticate(theCatalyst.DB, config.Auth),
catalyst.AuthorizeBlockedUser,
proxy,
)
theCatalyst.Server.With(catalyst.Authenticate(theCatalyst.DB, config.Auth), catalyst.AuthorizeBlockedUser()).NotFound(proxy)
if err = theCatalyst.Server.RunWithSigHandler(); err != nil {
if err := http.ListenAndServe(":8000", theCatalyst.Server); err != nil {
log.Fatal(err)
}
}
func proxy(ctx *gin.Context) {
func proxy(w http.ResponseWriter, r *http.Request) {
u, _ := url.Parse("http://localhost:8080")
proxy := httputil.NewSingleHostReverseProxy(u)
ctx.Request.Host = ctx.Request.URL.Host
r.Host = r.URL.Host
proxy.ServeHTTP(ctx.Writer, ctx.Request)
proxy.ServeHTTP(w, r)
}

View File

@@ -2,6 +2,7 @@ package main
import (
"log"
"net/http"
"github.com/SecurityBrewery/catalyst"
"github.com/SecurityBrewery/catalyst/cmd"
@@ -21,7 +22,7 @@ func main() {
log.Fatal(err)
}
if err = theCatalyst.Server.RunWithSigHandler(); err != nil {
if err := http.ListenAndServe(":8000", theCatalyst.Server); err != nil {
log.Fatal(err)
}
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/SecurityBrewery/catalyst"
"github.com/SecurityBrewery/catalyst/bus"
"github.com/SecurityBrewery/catalyst/database"
"github.com/SecurityBrewery/catalyst/generated/models"
"github.com/SecurityBrewery/catalyst/generated/model"
"github.com/SecurityBrewery/catalyst/pointer"
"github.com/SecurityBrewery/catalyst/role"
"github.com/SecurityBrewery/catalyst/storage"
@@ -72,10 +72,10 @@ func MapConfig(cli CLI) (*catalyst.Config, error) {
}
if len(artifactStates) == 0 {
artifactStates = []*models.Type{
{Icon: "mdi-help-circle-outline", ID: "unknown", Name: "Unknown", Color: pointer.String(models.TypeColorInfo)},
{Icon: "mdi-skull", ID: "malicious", Name: "Malicious", Color: pointer.String(models.TypeColorError)},
{Icon: "mdi-check", ID: "clean", Name: "Clean", Color: pointer.String(models.TypeColorSuccess)},
artifactStates = []*model.Type{
{Icon: "mdi-help-circle-outline", ID: "unknown", Name: "Unknown", Color: pointer.String(model.TypeColorInfo)},
{Icon: "mdi-skull", ID: "malicious", Name: "Malicious", Color: pointer.String(model.TypeColorError)},
{Icon: "mdi-check", ID: "clean", Name: "Clean", Color: pointer.String(model.TypeColorSuccess)},
}
}
@@ -96,21 +96,21 @@ func MapConfig(cli CLI) (*catalyst.Config, error) {
AuthDefaultRoles: roles,
},
Bus: &bus.Config{Host: cli.EmitterIOHost, Key: cli.EmitterIORKey, APIUrl: cli.CatalystAddress + "/api"},
UISettings: &models.Settings{
UISettings: &model.Settings{
ArtifactStates: artifactStates,
Timeformat: cli.Timeformat,
Version: catalyst.GetVersion(),
Tier: models.SettingsTierCommunity,
Tier: model.SettingsTierCommunity,
},
InitialAPIKey: cli.InitialAPIKey,
}
return config, nil
}
func toTypes(params []map[string]string) ([]*models.Type, error) {
var types []*models.Type
func toTypes(params []map[string]string) ([]*model.Type, error) {
var types []*model.Type
for _, param := range params {
t := &models.Type{}
t := &model.Type{}
icon, iconOK := param["icon"]
if iconOK {