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
166 lines
4.0 KiB
Go
166 lines
4.0 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/cortezaproject/corteza/server/automation/automation"
|
|
"github.com/cortezaproject/corteza/server/pkg/actionlog"
|
|
"github.com/cortezaproject/corteza/server/pkg/corredor"
|
|
"github.com/cortezaproject/corteza/server/pkg/expr"
|
|
"github.com/cortezaproject/corteza/server/pkg/id"
|
|
"github.com/cortezaproject/corteza/server/pkg/objstore"
|
|
"github.com/cortezaproject/corteza/server/pkg/options"
|
|
"github.com/cortezaproject/corteza/server/store"
|
|
sysTypes "github.com/cortezaproject/corteza/server/system/types"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type (
|
|
websocketSender interface {
|
|
Send(kind string, payload interface{}, userIDs ...uint64) error
|
|
}
|
|
|
|
Config struct {
|
|
ActionLog options.ActionLogOpt
|
|
Workflow options.WorkflowOpt
|
|
Corredor options.CorredorOpt
|
|
}
|
|
|
|
userService interface {
|
|
FindByAny(ctx context.Context, identifier interface{}) (*sysTypes.User, error)
|
|
}
|
|
)
|
|
|
|
var (
|
|
DefaultObjectStore objstore.Store
|
|
|
|
// DefaultStore is an interface to storage backend(s)
|
|
// ng (next-gen) is a temporary prefix
|
|
// so that we can differentiate between it and the file-only store
|
|
DefaultStore store.Storer
|
|
|
|
DefaultLogger *zap.Logger
|
|
|
|
// DefaultAccessControl Access control checking
|
|
DefaultAccessControl *accessControl
|
|
|
|
DefaultActionlog actionlog.Recorder
|
|
|
|
DefaultUser userService
|
|
DefaultWorkflow *workflow
|
|
DefaultTrigger *trigger
|
|
DefaultSession *session
|
|
|
|
// wrapper around time.Now() that will aid service testing
|
|
now = func() *time.Time {
|
|
c := time.Now().Round(time.Second)
|
|
return &c
|
|
}
|
|
|
|
// wrapper around nextID that will aid service testing
|
|
nextID = func() uint64 {
|
|
return id.Next()
|
|
}
|
|
)
|
|
|
|
func Initialize(ctx context.Context, log *zap.Logger, s store.Storer, ws websocketSender, c Config) (err error) {
|
|
var (
|
|
//hcd = healthcheck.Defaults()
|
|
)
|
|
|
|
// we're doing conversion to avoid having
|
|
// store interface exposed or generated inside app package
|
|
DefaultStore = s
|
|
|
|
DefaultLogger = log.Named("workflow")
|
|
|
|
{
|
|
tee := zap.NewNop()
|
|
policy := actionlog.MakeProductionPolicy()
|
|
|
|
if !c.ActionLog.Enabled {
|
|
policy = actionlog.MakeDisabledPolicy()
|
|
} else if c.ActionLog.Debug {
|
|
policy = actionlog.MakeDebugPolicy()
|
|
tee = log
|
|
}
|
|
|
|
DefaultActionlog = actionlog.NewService(DefaultStore, log, tee, policy)
|
|
}
|
|
|
|
DefaultAccessControl = AccessControl(s)
|
|
|
|
DefaultSession = Session(DefaultLogger.Named("session"), c.Workflow, ws)
|
|
DefaultWorkflow = Workflow(DefaultLogger.Named("workflow"), c.Corredor, c.Workflow)
|
|
DefaultTrigger = Trigger(DefaultLogger.Named("trigger"), c.Workflow)
|
|
|
|
DefaultWorkflow.triggers = DefaultTrigger
|
|
|
|
Registry().AddTypes(
|
|
&expr.Any{},
|
|
&expr.Array{},
|
|
&expr.Boolean{},
|
|
&expr.ID{},
|
|
&expr.Integer{},
|
|
&expr.UnsignedInteger{},
|
|
&expr.Float{},
|
|
&expr.String{},
|
|
&expr.Handle{},
|
|
&expr.DateTime{},
|
|
&expr.Duration{},
|
|
&expr.KV{},
|
|
&expr.KVV{},
|
|
&expr.Reader{},
|
|
&expr.Vars{},
|
|
&expr.HttpRequest{},
|
|
&expr.Bytes{},
|
|
|
|
&automation.EmailMessage{},
|
|
)
|
|
|
|
automation.HttpRequestHandler(Registry())
|
|
automation.LogHandler(Registry())
|
|
automation.QueueHandler(Registry())
|
|
automation.JsenvHandler(Registry())
|
|
automation.Oauth2Handler(Registry())
|
|
automation.LoopHandler(Registry(), DefaultWorkflow.parser)
|
|
automation.CorredorHandler(Registry(), corredor.Service())
|
|
automation.EmailHandler(Registry())
|
|
automation.JwtHandler(Registry())
|
|
automation.ApigwBodyHandler(Registry())
|
|
return
|
|
}
|
|
|
|
func Activate(ctx context.Context) (err error) {
|
|
if err = DefaultWorkflow.Load(ctx); err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func Watchers(ctx context.Context) {
|
|
DefaultSession.Watch(ctx)
|
|
return
|
|
}
|
|
|
|
// Data is stale when new date does not match updatedAt or createdAt (before first update)
|
|
func isStale(new *time.Time, updatedAt *time.Time, createdAt time.Time) bool {
|
|
if new == nil {
|
|
// Change to true for stale-data-check
|
|
return false
|
|
}
|
|
|
|
if updatedAt != nil {
|
|
return !new.Equal(*updatedAt)
|
|
}
|
|
|
|
return new.Equal(createdAt)
|
|
}
|
|
|
|
// trim1st removes 1st param and returns only error
|
|
func trim1st(_ interface{}, err error) error {
|
|
return err
|
|
}
|