Add support for multiple (glob) provision cfg paths
This commit is contained in:
@@ -258,7 +258,7 @@ func (app *CortezaApp) Provision(ctx context.Context) (err error) {
|
||||
ctx = actionlog.RequestOriginToContext(ctx, actionlog.RequestOrigin_APP_Provision)
|
||||
ctx = auth.SetSuperUserContext(ctx)
|
||||
|
||||
if err = provision.Run(ctx, app.Log, app.Store); err != nil {
|
||||
if err = provision.Run(ctx, app.Log, app.Store, app.Opt.Provision.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ package options
|
||||
|
||||
type (
|
||||
ProvisionOpt struct {
|
||||
Always bool `env:"PROVISION_ALWAYS"`
|
||||
Always bool `env:"PROVISION_ALWAYS"`
|
||||
Path string `env:"PROVISION_PATH"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -18,6 +19,7 @@ type (
|
||||
func Provision() (o *ProvisionOpt) {
|
||||
o = &ProvisionOpt{
|
||||
Always: true,
|
||||
Path: "provision/*",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
@@ -4,4 +4,6 @@ name: provision
|
||||
props:
|
||||
- name: always
|
||||
type: bool
|
||||
default: true
|
||||
default: true
|
||||
- name: path
|
||||
default: "provision/*"
|
||||
|
||||
@@ -10,23 +10,34 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"go.uber.org/zap"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func importConfig(ctx context.Context, log *zap.Logger, s store.Storer) error {
|
||||
// imports configuration files from path(s)
|
||||
//
|
||||
// paths can be colon delimited list of absolute or relative paths and/or with glob pattern
|
||||
func importConfig(ctx context.Context, log *zap.Logger, s store.Storer, paths string) error {
|
||||
var (
|
||||
yd = yaml.Decoder()
|
||||
nn = make([]resource.Interface, 0, 200)
|
||||
se = es.NewStoreEncoder(s, &es.EncoderConfig{OnExisting: es.Skip})
|
||||
bld = envoy.NewBuilder(se)
|
||||
|
||||
pp, err = filepath.Glob("provision/*")
|
||||
sources = make([]string, 0, 16)
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
log.Info("importing config", zap.String("paths", paths))
|
||||
|
||||
// verify all paths before doing the actual import
|
||||
for _, path := range strings.Split(paths, ":") {
|
||||
if aux, err := filepath.Glob(path); err != nil {
|
||||
return err
|
||||
} else {
|
||||
sources = append(sources, aux...)
|
||||
}
|
||||
}
|
||||
|
||||
for _, path := range pp {
|
||||
for _, path := range sources {
|
||||
log.Info("provisioning from path", zap.String("path", path))
|
||||
if mm, err := directory.Decode(ctx, path, yd); err != nil {
|
||||
return err
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context, log *zap.Logger, s store.Storer) error {
|
||||
func Run(ctx context.Context, log *zap.Logger, s store.Storer, path string) error {
|
||||
ffn := []func() error{
|
||||
func() error { return roles(ctx, s) },
|
||||
func() error { return importConfig(ctx, log, s) },
|
||||
func() error { return importConfig(ctx, log, s, path) },
|
||||
func() error { return authSettingsAutoDiscovery(ctx, log, service.DefaultSettings) },
|
||||
func() error { return authAddExternals(ctx, log) },
|
||||
func() error { return service.DefaultSettings.UpdateCurrent(ctx) },
|
||||
|
||||
Reference in New Issue
Block a user