2024-09-08 15:28:22: merge [master:33b4e2d9651dc592eae18e258984b11b35cc0a5e];

This commit is contained in:
txix committed 2024-09-08 15:28:22 +03:00
1 parent 6f45b1861f
commit 02df1a6546
36 files changed
+653 -3262

No files matched your search

+20 -21
View File
@@ -2,17 +2,17 @@ package assembly
import (
"context"
"github.com/txix-open/isp-kit/rc"
"github.com/integration-system/isp-kit/app"
"github.com/integration-system/isp-kit/bootstrap"
"github.com/integration-system/isp-kit/cluster"
"github.com/integration-system/isp-kit/dbrx"
"github.com/integration-system/isp-kit/dbx"
"github.com/integration-system/isp-kit/grpc"
"github.com/integration-system/isp-kit/log"
"github.com/pkg/errors"
"github.com/txix-open/isp-kit/app"
"github.com/txix-open/isp-kit/bootstrap"
"github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/dbrx"
"github.com/txix-open/isp-kit/dbx"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/log"
"isp-system-service/conf"
"isp-system-service/migrations"
)
type Assembly struct {
@@ -23,9 +23,8 @@ type Assembly struct {
}
func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
dbCli := dbrx.New(dbx.WithMigration(boot.MigrationsDir))
dbCli := dbrx.New(dbx.WithMigrationRunner(boot.MigrationsDir, boot.App.Logger()))
server := grpc.NewServer()
return &Assembly{
boot: boot,
db: dbCli,
@@ -35,27 +34,27 @@ func New(boot *bootstrap.Bootstrap) (*Assembly, error) {
}
func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error {
var (
newCfg conf.Remote
prevCfg conf.Remote
)
err := a.boot.RemoteConfig.Upgrade(remoteConfig, &newCfg, &prevCfg)
newCfg, _, err := rc.Upgrade[conf.Remote](a.boot.RemoteConfig, remoteConfig)
if err != nil {
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade remote config"))
a.boot.Fatal(errors.WithMessage(err, "upgrade remote config"))
}
migrations.Initialize.SetParams(a.boot.MigrationsDir, newCfg.Database.Schema)
a.logger.SetLevel(newCfg.LogLevel)
err = a.db.Upgrade(ctx, newCfg.Database)
if err != nil {
a.logger.Fatal(ctx, errors.WithMessage(err, "upgrade db client"), log.Any("config", newCfg.Database))
a.boot.Fatal(errors.WithMessage(err, "upgrade db client"))
}
locator := NewLocator(a.db, a.logger)
handler := locator.Handler(newCfg)
a.server.Upgrade(handler)
config := locator.Config(newCfg)
err = config.Baseline.Do(a.boot.App.Context())
if err != nil {
a.boot.Fatal(errors.WithMessage(err, "run baseline"))
}
a.server.Upgrade(config.Handler)
return nil
}
+17 -6
View File
@@ -1,15 +1,16 @@
package assembly
import (
"github.com/integration-system/isp-kit/db"
"github.com/integration-system/isp-kit/grpc/endpoint"
"github.com/integration-system/isp-kit/grpc/isp"
"github.com/integration-system/isp-kit/log"
"github.com/txix-open/isp-kit/db"
"github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/endpoint"
"github.com/txix-open/isp-kit/log"
"isp-system-service/conf"
"isp-system-service/controller"
"isp-system-service/repository"
"isp-system-service/routes"
"isp-system-service/service"
"isp-system-service/service/baseline"
"isp-system-service/service/secure"
"isp-system-service/transaction"
)
@@ -31,7 +32,12 @@ func NewLocator(db DB, logger log.Logger) Locator {
}
}
func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
type Config struct {
Handler *grpc.Mux
Baseline baseline.Service
}
func (l Locator) Config(cfg conf.Remote) Config {
txManager := transaction.NewManager(l.db)
accessListRep := repository.NewAccessList(l.db)
applicationRep := repository.NewApplication(l.db)
@@ -67,5 +73,10 @@ func (l Locator) Handler(cfg conf.Remote) isp.BackendServiceServer {
}
mapper := endpoint.DefaultWrapper(l.logger, endpoint.BodyLogger(l.logger))
server := routes.Handler(mapper, c)
return server
baselineService := baseline.NewService(cfg.Baseline, txManager, l.logger)
return Config{
Handler: server,
Baseline: baselineService,
}
}