2023-04-24 20:52:12 +02:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/admin"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/command/common"
|
2023-07-05 20:05:30 +02:00
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/setup"
|
2023-04-24 20:52:12 +02:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
2024-02-21 11:09:34 +01:00
|
|
|
const (
|
|
|
|
flagPrintDefaultToken = "print-default-token"
|
|
|
|
)
|
|
|
|
|
2023-04-24 20:52:12 +02:00
|
|
|
func RunCommand() *cli.Command {
|
2024-11-18 11:05:17 +01:00
|
|
|
flags := common.Flags()
|
2023-04-24 20:52:12 +02:00
|
|
|
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "run",
|
|
|
|
Usage: "Run the admin server",
|
|
|
|
Flags: flags,
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
conf, err := common.LoadConfig(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not load configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.SetFormat(logger.Format(conf.Logger.Format))
|
|
|
|
logger.SetLevel(logger.Level(conf.Logger.Level))
|
|
|
|
|
2023-07-05 20:05:30 +02:00
|
|
|
projectVersion := ctx.String("projectVersion")
|
|
|
|
|
2024-09-23 10:13:04 +02:00
|
|
|
if conf.Proxy.Sentry.DSN != "" {
|
|
|
|
flushSentry, err := setup.SetupSentry(ctx.Context, conf.Proxy.Sentry, projectVersion)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not initialize sentry client")
|
|
|
|
}
|
|
|
|
|
|
|
|
defer flushSentry()
|
|
|
|
}
|
2023-07-05 20:05:30 +02:00
|
|
|
|
2024-03-27 17:47:39 +01:00
|
|
|
integrations, err := setup.SetupIntegrations(ctx.Context, conf)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not setup integrations")
|
|
|
|
}
|
|
|
|
|
2023-04-24 20:52:12 +02:00
|
|
|
srv := admin.NewServer(
|
|
|
|
admin.WithServerConfig(conf.Admin),
|
|
|
|
admin.WithRedisConfig(conf.Redis),
|
2024-03-26 17:28:38 +01:00
|
|
|
admin.WithBootstrapConfig(conf.Bootstrap),
|
2024-03-27 17:47:39 +01:00
|
|
|
admin.WithIntegrations(integrations...),
|
2023-04-24 20:52:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
addrs, srvErrs := srv.Start(ctx.Context)
|
|
|
|
|
|
|
|
select {
|
|
|
|
case addr := <-addrs:
|
|
|
|
url := fmt.Sprintf("http://%s", addr.String())
|
|
|
|
url = strings.Replace(url, "0.0.0.0", "127.0.0.1", 1)
|
|
|
|
|
|
|
|
logger.Info(ctx.Context, "listening", logger.F("url", url))
|
|
|
|
case err = <-srvErrs:
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = <-srvErrs; err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|