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
+5 -4
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."`
@@ -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
}
@@ -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)
}