Merge pull request #5607 from owncloud/configurable-bundles

load bundles from JSON
This commit is contained in:
Michael Barz
2023-02-21 21:58:14 +01:00
committed by GitHub
4 changed files with 31 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
Enhancement: Make the settings bundles part of the service config
We added the settings bundles to the config. The default roles are still unchanged. You can now override the defaults by replacing the whole bundles list via the yaml config files. An example can be found in the Service Configuration documentation.
We added the settings bundles to the config. The default roles are still unchanged. You can now override the defaults by replacing the whole bundles list via json config files. The config file is loaded from a specified path which can be configured with `SETTINGS_BUNDLES_PATH`.
https://github.com/owncloud/ocis/pull/5589
https://github.com/owncloud/ocis/pull/5607

View File

@@ -22,10 +22,11 @@ type Config struct {
GRPCClientTLS *shared.GRPCClientTLS `yaml:"grpc_client_tls"`
StoreType string `yaml:"store_type" env:"SETTINGS_STORE_TYPE" desc:"Store type configures the persistency driver. Supported values are \"metadata\" and \"filesystem\"."`
DataPath string `yaml:"data_path" env:"SETTINGS_DATA_PATH" desc:"The directory where the filesystem storage will store ocis settings. If not definied, the root directory derives from $OCIS_BASE_DATA_PATH:/settings."`
Metadata Metadata `yaml:"metadata_config"`
Bundles []*settingsmsg.Bundle `yaml:"bundles"`
StoreType string `yaml:"store_type" env:"SETTINGS_STORE_TYPE" desc:"Store type configures the persistency driver. Supported values are \"metadata\" and \"filesystem\"."`
DataPath string `yaml:"data_path" env:"SETTINGS_DATA_PATH" desc:"The directory where the filesystem storage will store ocis settings. If not definied, the root directory derives from $OCIS_BASE_DATA_PATH:/settings."`
Metadata Metadata `yaml:"metadata_config"`
BundlesPath string `yaml:"bundles_path" env:"SETTINGS_BUNDLES_PATH" desc:"The path to a JSON file with a list of bundles. If not definied, the default bundles will be loaded."`
Bundles []*settingsmsg.Bundle `yaml:"-"`
AdminUserID string `yaml:"admin_user_id" env:"OCIS_ADMIN_USER_ID;SETTINGS_ADMIN_USER_ID" desc:"ID of the user that should receive admin privileges. Consider that the UUID can be encoded in some LDAP deployment configurations like in .ldif files. These need to be decoded beforehand."`

View File

@@ -1,14 +1,16 @@
package defaults
import (
"encoding/json"
"os"
"path"
"strings"
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
"github.com/owncloud/ocis/v2/services/settings/pkg/config"
rdefaults "github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults"
"github.com/pkg/errors"
)
func FullDefaultConfig() *config.Config {
@@ -53,7 +55,8 @@ func DefaultConfig() *config.Config {
StorageAddress: "127.0.0.1:9215",
SystemUserIDP: "internal",
},
Bundles: []*v0.Bundle{},
BundlesPath: "",
Bundles: nil,
}
}
@@ -123,12 +126,23 @@ func EnsureDefaults(cfg *config.Config) {
}
func Sanitize(cfg *config.Config) {
if len(cfg.Bundles) == 0 {
cfg.Bundles = rdefaults.GenerateBundlesDefaultRoles()
}
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
}
// LoadBundles loads setting bundles from a file or from defaults
func LoadBundles(cfg *config.Config) error {
if cfg.BundlesPath != "" {
data, _ := os.ReadFile(cfg.BundlesPath)
err := json.Unmarshal(data, &cfg.Bundles)
if err != nil {
return errors.Wrapf(err, "Could not load bundles from path %s", cfg.BundlesPath)
}
}
if len(cfg.Bundles) == 0 {
cfg.Bundles = rdefaults.GenerateBundlesDefaultRoles()
}
return nil
}

View File

@@ -29,6 +29,10 @@ func ParseConfig(cfg *config.Config) error {
defaults.Sanitize(cfg)
if err := defaults.LoadBundles(cfg); err != nil {
return err
}
return Validate(cfg)
}