snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
139
server/federation/service/service.go
Normal file
139
server/federation/service/service.go
Normal file
@@ -0,0 +1,139 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
cs "github.com/cortezaproject/corteza/server/compose/service"
|
||||
"github.com/cortezaproject/corteza/server/pkg/actionlog"
|
||||
"github.com/cortezaproject/corteza/server/pkg/auth"
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
"github.com/cortezaproject/corteza/server/pkg/label"
|
||||
"github.com/cortezaproject/corteza/server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
ss "github.com/cortezaproject/corteza/server/system/service"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
labelTypes "github.com/cortezaproject/corteza/server/pkg/label/types"
|
||||
)
|
||||
|
||||
type (
|
||||
Config struct {
|
||||
ActionLog options.ActionLogOpt
|
||||
Storage options.ObjectStoreOpt
|
||||
Federation options.FederationOpt
|
||||
Server options.HttpServerOpt
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultStore store.Storer
|
||||
|
||||
DefaultLogger *zap.Logger
|
||||
|
||||
DefaultAccessControl *accessControl
|
||||
|
||||
// CurrentSettings represents current system settings
|
||||
CurrentSettings = &types.AppSettings{}
|
||||
|
||||
DefaultOptions options.FederationOpt
|
||||
|
||||
DefaultActionlog actionlog.Recorder
|
||||
|
||||
DefaultNode *node
|
||||
DefaultNodeSync NodeSyncService
|
||||
DefaultExposedModule ExposedModuleService
|
||||
DefaultSharedModule SharedModuleService
|
||||
DefaultModuleMapping ModuleMappingService
|
||||
|
||||
// wrapper around time.Now() that will aid service testing
|
||||
now = func() *time.Time {
|
||||
c := time.Now().Round(time.Second)
|
||||
return &c
|
||||
}
|
||||
|
||||
// wrapper around id.Next() that will aid service testing
|
||||
nextID = func() uint64 {
|
||||
return id.Next()
|
||||
}
|
||||
)
|
||||
|
||||
func Initialize(_ context.Context, log *zap.Logger, s store.Storer, c Config) (err error) {
|
||||
DefaultOptions = c.Federation
|
||||
|
||||
// we're doing conversion to avoid having
|
||||
// store interface exposed or generated inside app package
|
||||
DefaultStore = s
|
||||
|
||||
DefaultLogger = log.Named("service")
|
||||
|
||||
// @todo add healthcheck(s) for federation sync services
|
||||
|
||||
{
|
||||
tee := zap.NewNop()
|
||||
policy := actionlog.MakeProductionPolicy()
|
||||
|
||||
if !c.ActionLog.Enabled {
|
||||
policy = actionlog.MakeDisabledPolicy()
|
||||
} else if c.ActionLog.Debug {
|
||||
policy = actionlog.MakeDebugPolicy()
|
||||
tee = logger.MakeDebugLogger()
|
||||
}
|
||||
|
||||
DefaultActionlog = actionlog.NewService(DefaultStore, log, tee, policy)
|
||||
}
|
||||
|
||||
DefaultAccessControl = AccessControl(s)
|
||||
|
||||
DefaultNode = Node(
|
||||
DefaultStore,
|
||||
ss.DefaultUser,
|
||||
DefaultActionlog,
|
||||
func(ctx context.Context, i auth.Identifiable) (token []byte, err error) {
|
||||
return auth.TokenIssuer.Issue(
|
||||
ctx,
|
||||
auth.WithIdentity(i),
|
||||
auth.WithScope("api"),
|
||||
auth.WithAudience("federation"),
|
||||
)
|
||||
},
|
||||
c.Federation,
|
||||
c.Server,
|
||||
DefaultAccessControl,
|
||||
)
|
||||
DefaultNodeSync = NodeSync()
|
||||
DefaultExposedModule = ExposedModule()
|
||||
DefaultSharedModule = SharedModule()
|
||||
DefaultModuleMapping = ModuleMapping()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func Watchers(ctx context.Context) {
|
||||
DefaultLogger.Info("Starting federation - warning, this is still an experimental feature")
|
||||
|
||||
syncService := NewSync(
|
||||
&Syncer{},
|
||||
&Mapper{},
|
||||
DefaultSharedModule,
|
||||
cs.DefaultRecord,
|
||||
ss.DefaultUser,
|
||||
ss.DefaultRole)
|
||||
|
||||
syncStructure := WorkerStructure(syncService, DefaultLogger)
|
||||
syncData := WorkerData(syncService, DefaultLogger)
|
||||
|
||||
go syncStructure.Watch(
|
||||
ctx,
|
||||
DefaultOptions.StructureMonitorInterval,
|
||||
DefaultOptions.StructurePageSize)
|
||||
|
||||
go syncData.Watch(
|
||||
ctx,
|
||||
DefaultOptions.DataMonitorInterval,
|
||||
DefaultOptions.DataPageSize)
|
||||
}
|
||||
|
||||
func AddFederationLabel(entity label.LabeledResource, key string, value string) {
|
||||
entity.SetLabel(key, labelTypes.LabelValue{Val: value})
|
||||
}
|
||||
Reference in New Issue
Block a user