Deprecated Corteza plugin support
The current plugin support was not stable enough in go >= 1.18, so the current implementation was dropped for a future alternate solution.
This commit is contained in:
parent
d65bd241b7
commit
7f0fe201db
17
.env.example
17
.env.example
@ -996,23 +996,6 @@
|
||||
# Default: <no value>
|
||||
# MINIO_STRICT=<no value>
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# Plugins
|
||||
#
|
||||
|
||||
###############################################################################
|
||||
# Enable plugins
|
||||
# Type: bool
|
||||
# Default: <no value>
|
||||
# PLUGINS_ENABLED=<no value>
|
||||
|
||||
###############################################################################
|
||||
# List of colon seperated paths or patterns where plugins could be found
|
||||
# Type: string
|
||||
# Default: <no value>
|
||||
# PLUGINS_PATHS=<no value>
|
||||
|
||||
###############################################################################
|
||||
###############################################################################
|
||||
# Provisioning
|
||||
|
||||
@ -32,7 +32,6 @@ corteza: schema.#platform & {
|
||||
options.messagebus,
|
||||
options.monitor,
|
||||
options.objectStore,
|
||||
options.plugins,
|
||||
options.provision,
|
||||
options.seeder,
|
||||
options.sentry,
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/pkg/options"
|
||||
"github.com/cortezaproject/corteza-server/pkg/plugin"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/go-chi/chi/v5"
|
||||
@ -50,9 +49,6 @@ type (
|
||||
lvl int
|
||||
Log *zap.Logger
|
||||
|
||||
// Available plugins
|
||||
plugins plugin.Set
|
||||
|
||||
// Store interface
|
||||
//
|
||||
// Just a blank interface{} because we want to avoid generating
|
||||
|
||||
@ -174,10 +174,6 @@ func (app *CortezaApp) Setup() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err = app.plugins.Setup(app.Log.Named("plugin")); err != nil {
|
||||
return fmt.Errorf("plugins setup failed: %w", err)
|
||||
}
|
||||
|
||||
app.lvl = bootLevelSetup
|
||||
return
|
||||
}
|
||||
@ -448,14 +444,6 @@ func (app *CortezaApp) InitServices(ctx context.Context) (err error) {
|
||||
// Initializing seeder
|
||||
_ = seeder.Seeder(ctx, app.Store, dal.Service(), seeder.Faker())
|
||||
|
||||
if err = app.plugins.Initialize(ctx, app.Log); err != nil {
|
||||
return fmt.Errorf("could not initialize plugins: %w", err)
|
||||
}
|
||||
|
||||
if err = app.plugins.RegisterAutomation(autService.Registry()); err != nil {
|
||||
return fmt.Errorf("could not register automation plugins: %w", err)
|
||||
}
|
||||
|
||||
app.lvl = bootLevelServicesInitialized
|
||||
return
|
||||
}
|
||||
|
||||
22
app/cli.go
22
app/cli.go
@ -11,7 +11,6 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/api/server"
|
||||
"github.com/cortezaproject/corteza-server/pkg/cli"
|
||||
"github.com/cortezaproject/corteza-server/pkg/options"
|
||||
"github.com/cortezaproject/corteza-server/pkg/plugin"
|
||||
fakerCommands "github.com/cortezaproject/corteza-server/pkg/seeder/commands"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
systemCommands "github.com/cortezaproject/corteza-server/system/commands"
|
||||
@ -29,25 +28,8 @@ func (app *CortezaApp) InitCLI() {
|
||||
envs []string
|
||||
)
|
||||
|
||||
app.Command = cli.RootCommand(func() (err error) {
|
||||
log := app.Log.Named("plugins")
|
||||
if app.Opt.Plugins.Enabled && len(app.Opt.Plugins.Paths) > 0 {
|
||||
log.Warn("loading", zap.String("paths", app.Opt.Plugins.Paths))
|
||||
|
||||
var paths []string
|
||||
paths, err = plugin.Resolve(app.Opt.Plugins.Paths)
|
||||
log.Warn("loading", zap.Strings("resolved-paths", paths))
|
||||
|
||||
app.plugins, err = plugin.Load(paths...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Empty set of plugins
|
||||
app.plugins = plugin.Set{}
|
||||
}
|
||||
|
||||
return err
|
||||
app.Command = cli.RootCommand(func() error {
|
||||
return nil
|
||||
})
|
||||
|
||||
// Environmental variables (from the env, files, see cli.LoadEnv) MUST be
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/codegen/schema"
|
||||
)
|
||||
|
||||
plugins: schema.#optionsGroup & {
|
||||
handle: "plugins"
|
||||
options: {
|
||||
Enabled: {
|
||||
type: "bool"
|
||||
defaultGoExpr: "true"
|
||||
description: "Enable plugins"
|
||||
}
|
||||
Paths: {
|
||||
description: "List of colon seperated paths or patterns where plugins could be found"
|
||||
}
|
||||
}
|
||||
title: "Plugins"
|
||||
}
|
||||
@ -15,7 +15,7 @@ type (
|
||||
FunctionHandler func(ctx context.Context, in *expr.Vars) (*expr.Vars, error)
|
||||
IteratorHandler func(ctx context.Context, in *expr.Vars) (wfexec.IteratorHandler, error)
|
||||
|
||||
// workflow functions are defined in the core code and through plugins
|
||||
// workflow functions are defined in the core code
|
||||
Function struct {
|
||||
Ref string `json:"ref,omitempty"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
|
||||
32
pkg/options/options.gen.go
generated
32
pkg/options/options.gen.go
generated
@ -202,11 +202,6 @@ type (
|
||||
MinioStrict bool `env:"MINIO_STRICT"`
|
||||
}
|
||||
|
||||
PluginsOpt struct {
|
||||
Enabled bool `env:"PLUGINS_ENABLED"`
|
||||
Paths string `env:"PLUGINS_PATHS"`
|
||||
}
|
||||
|
||||
ProvisionOpt struct {
|
||||
Always bool `env:"PROVISION_ALWAYS"`
|
||||
Path string `env:"PROVISION_PATH"`
|
||||
@ -845,33 +840,6 @@ func ObjectStore() (o *ObjectStoreOpt) {
|
||||
return
|
||||
}
|
||||
|
||||
// Plugins initializes and returns a PluginsOpt with default values
|
||||
//
|
||||
// This function is auto-generated
|
||||
func Plugins() (o *PluginsOpt) {
|
||||
o = &PluginsOpt{
|
||||
Enabled: true,
|
||||
}
|
||||
|
||||
// Custom defaults
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
fill(o)
|
||||
|
||||
// Custom cleanup
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Cleanup() }); ok {
|
||||
def.Cleanup()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Provision initializes and returns a ProvisionOpt with default values
|
||||
//
|
||||
// This function is auto-generated
|
||||
|
||||
@ -26,7 +26,6 @@ type (
|
||||
RBAC RbacOpt
|
||||
Locale LocaleOpt
|
||||
Limit LimitOpt
|
||||
Plugins PluginsOpt
|
||||
Discovery DiscoveryOpt
|
||||
Apigw ApigwOpt
|
||||
}
|
||||
@ -58,7 +57,6 @@ func Init() *Options {
|
||||
RBAC: *Rbac(),
|
||||
Locale: *Locale(),
|
||||
Limit: *Limit(),
|
||||
Plugins: *Plugins(),
|
||||
Discovery: *Discovery(),
|
||||
Apigw: *Apigw(),
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
package plugin
|
||||
|
||||
// Collection of boot-lifecycle related functions
|
||||
// that exec plugin functions
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/automation/types"
|
||||
sdk "github.com/cortezaproject/corteza-server/sdk/plugin"
|
||||
)
|
||||
|
||||
type (
|
||||
automationRegistry interface {
|
||||
AddFunctions(ff ...*types.Function)
|
||||
// AddTypes(tt ...expr.Type)
|
||||
}
|
||||
)
|
||||
|
||||
func (pp Set) RegisterAutomation(r automationRegistry) error {
|
||||
for _, p := range pp {
|
||||
d, is := p.def.(sdk.AutomationFunctionsProvider)
|
||||
if !is {
|
||||
continue
|
||||
}
|
||||
|
||||
r.AddFunctions(d.AutomationFunctions()...)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package plugin
|
||||
|
||||
// Collection of boot-lifecycle related functions
|
||||
// that exec plugin functions
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
sdk "github.com/cortezaproject/corteza-server/sdk/plugin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (pp Set) Setup(log *zap.Logger) error {
|
||||
for _, p := range pp {
|
||||
d, is := p.def.(sdk.Setup)
|
||||
if !is {
|
||||
continue
|
||||
}
|
||||
|
||||
err := d.Setup(log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pp Set) Initialize(ctx context.Context, log *zap.Logger) error {
|
||||
for _, p := range pp {
|
||||
d, is := p.def.(sdk.Initialize)
|
||||
if !is {
|
||||
continue
|
||||
}
|
||||
|
||||
err := d.Initialize(ctx, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"plugin"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
// Set of plugins
|
||||
Set []*item
|
||||
|
||||
// item represents a plugin
|
||||
item struct {
|
||||
src string
|
||||
def interface{}
|
||||
}
|
||||
)
|
||||
|
||||
// Resolve string with colon separated paths
|
||||
func Resolve(paths string) (out []string, err error) {
|
||||
var (
|
||||
matches []string
|
||||
)
|
||||
|
||||
for _, part := range strings.Split(paths, ":") {
|
||||
matches, err = filepath.Glob(part)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
out = append(out, matches...)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Load loads plugins from all given paths
|
||||
func Load(paths ...string) (Set, error) {
|
||||
var set = Set{}
|
||||
|
||||
for _, path := range paths {
|
||||
|
||||
if info, err := os.Lstat(path); err != nil {
|
||||
return nil, err
|
||||
} else if info.IsDir() {
|
||||
return nil, fmt.Errorf("can not use directory %s as a plugin", path)
|
||||
}
|
||||
|
||||
if i, err := load(path); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
set = append(set, i)
|
||||
}
|
||||
}
|
||||
|
||||
return set, nil
|
||||
}
|
||||
|
||||
// load single plugin from the given path
|
||||
func load(path string) (i *item, err error) {
|
||||
i = &item{}
|
||||
p, err := plugin.Open(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
aux, err := p.Lookup("CortezaPlugin")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fn, is := aux.(func() interface{})
|
||||
if !is {
|
||||
return nil, fmt.Errorf("incompatible plugin definition")
|
||||
}
|
||||
|
||||
i.def = fn()
|
||||
return
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/automation/types"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type (
|
||||
Setup interface {
|
||||
Setup(log *zap.Logger) error
|
||||
}
|
||||
|
||||
Initialize interface {
|
||||
Initialize(ctx context.Context, log *zap.Logger) error
|
||||
}
|
||||
|
||||
AutomationFunctionsProvider interface {
|
||||
AutomationFunctions() []*types.Function
|
||||
}
|
||||
|
||||
//AutomationTypesProvider interface {
|
||||
// AutomationTypes() []*expr.Type
|
||||
//}
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user