diff --git a/.drone.star b/.drone.star index 4e76e385e4e..61e425a43b6 100644 --- a/.drone.star +++ b/.drone.star @@ -1709,6 +1709,7 @@ def ocisServer(storage, accounts_hash_difficulty = 4, volumes = [], depends_on = "OCIS_URL": OCIS_URL, "PROXY_TLS": "true", "OCIS_BASE_DATA_PATH": "/mnt/data/ocis", + "OCIS_CONFIG_DIR": "/etc/ocis", # change default secrets "OCIS_JWT_SECRET": "Pive-Fumkiu4", "STORAGE_TRANSFER_SECRET": "replace-me-with-a-transfer-secret", diff --git a/.make/release.mk b/.make/release.mk index 30c3ac08fda..d4dd4286d0d 100644 --- a/.make/release.mk +++ b/.make/release.mk @@ -11,6 +11,7 @@ release-dirs: # docker specific packaging flags DOCKER_LDFLAGS += -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathType=path" -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseDataPathValue=/var/lib/ocis" +DOCKER_LDFLAGS += -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseConfigPathType=path" -X "$(OCIS_REPO)/ocis-pkg/config/defaults.BaseConfigPathValue=/etc/ocis" release-linux-docker-amd64: release-dirs GOOS=linux \ diff --git a/docs/helpers/configenvextractor.go b/docs/helpers/configenvextractor.go index bde518bcc23..3f08ca0cec9 100644 --- a/docs/helpers/configenvextractor.go +++ b/docs/helpers/configenvextractor.go @@ -57,6 +57,7 @@ func GenerateIntermediateCode(templatePath string, intermediateCodePath string, func RunIntermediateCode(intermediateCodePath string) { fmt.Println("Running intermediate go code for " + intermediateCodePath) os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis") + os.Setenv("OCIS_CONFIG_DIR", "~/.ocis/config") out, err := exec.Command("go", "run", intermediateCodePath).Output() if err != nil { log.Fatal(err) diff --git a/docs/ocis/config.md b/docs/ocis/config.md index f4ab30cf60b..efb81e642eb 100644 --- a/docs/ocis/config.md +++ b/docs/ocis/config.md @@ -39,15 +39,20 @@ Let's explore the various flows with examples and workflows. Let's explore with examples this approach. -#### Expected loading locations: +#### Expected loading locations -- `$HOME/.ocis/config/` -- `/etc/ocis/` -- `.config/` +- docker images: `/etc/ocis/` +- binary releases: `$HOME/.ocis/config/` -followed by the extension name. When configuring the proxy, a valid full path that will get loaded is `$HOME/.ocis/config/proxy.yaml`. +followed by the `.yaml`, eg `proxy.yaml` for the extension configuration. You also can put an `ocis.yaml` config file to the expected loading location to use a single config file. -#### Only config files +You can set another directory as config path in the environment variable `OCIS_CONFIG_DIR`. It will then pick the same file names, but from the folder you configured. + +Another option is to set the `--ocis-config-file` option for the runtime `ocis server --ocis-config-file /path/to/ocis.yaml` or for an extension without runtime `ocis proxy --ocis-config-file /path/to/ocis.yaml server`. For both cases, you can achieve the same by setting the environment variable `OCIS_CONFIG_FILE=/path/to/ocis.yaml`. + +For unsupervised extensions (without runtime), you also can specify a `--config-file` flag to use a non default config file, eg. `ocis proxy server --config-file /path/to/proxy.yaml`. An alternative is to set the extension specific configuration file path environment variable, e.g. `PROXY_CONFIG_FILE=/path/to/proxy.yaml` for the proxy extension. + +#### Only config files The following config files are present in the default loading locations: diff --git a/docs/ocis/deployment/systemd.md b/docs/ocis/deployment/systemd.md index 8ac0a1d8f27..0eac23aa652 100644 --- a/docs/ocis/deployment/systemd.md +++ b/docs/ocis/deployment/systemd.md @@ -10,17 +10,18 @@ geekdocFilePath: systemd.md {{< toc >}} ## Install the oCIS binary + Download the oCIS binary of your preferred version and for your CPU architecture and operating system from [download.owncloud.com](https://download.owncloud.com/ocis/ocis). Rename the downloaded binary to `ocis` and move it to `/usr/bin/`. As a next step, you need to mark it as executable with `chmod +x /usr/bin/ocis`. When you now run `ocis help` on your command line, you should see the available options for the oCIS command. - ## Systemd service definition Create the Systemd service definition for oCIS in the file `/etc/systemd/system/ocis.service` with following content: -``` + +```systemd [Unit] Description=OCIS server @@ -36,19 +37,23 @@ Restart=always WantedBy=multi-user.target ``` -For reasons of simplicity we are using the root user and group to run oCIS which is not recommended. Please use a non-root user in production environments and modify the oCIS service definition accordingly. - +{{< hint danger >}} +For reasons of simplicity we are using the root user and group to run oCIS, which is not recommended. Please use only privileged users in production environments and modify the oCIS service definition accordingly. +{{< /hint >}} In the service definition we referenced `/etc/ocis/ocis.env` as our file containing environment variables for the oCIS process. In order to create the file we need first to create the folder `/etc/ocis/` and than we can add the actual `/etc/ocis/ocis.env` with following content: -``` -OCIS_URL=https://some-hostname-or-ip:9200 +```bash +OCIS_URL=https://some-host-or-ip:9200 PROXY_HTTP_ADDR=0.0.0.0:9200 OCIS_INSECURE=false OCIS_LOG_LEVEL=error +OCIS_BASE_DATA_PATH=/var/lib/ocis +OCIS_CONFIG_DIR=/etc/ocis + GLAUTH_LDAPS_CERT=/etc/ocis/ldap/ldaps.crt GLAUTH_LDAPS_KEY=/etc/ocis/ldap/ldaps.key IDP_TRANSPORT_TLS_CERT=/etc/ocis/idp/server.crt @@ -59,6 +64,9 @@ PROXY_TRANSPORT_TLS_KEY=/etc/ocis/proxy/server.key Please change your `OCIS_URL` in order to reflect your actual deployment. If you are using self signed certificates you need to set `OCIS_INSECURE=true` in `/etc/ocis/ocis.env`. +In the `ocis.env` file we configured oCIS to store all data in `/var/lib/ocis`, so you need to create that folder and make it writeable for the ocis user (see user / group in the systemd file). + +If you add oCIS config files in `/etc/ocis`, you need to ensure that the directory and config file is readable by the oCIS process's user / group. ## Starting the oCIS service diff --git a/extensions/accounts/pkg/command/server.go b/extensions/accounts/pkg/command/server.go index cad2406868f..f15576d96e0 100644 --- a/extensions/accounts/pkg/command/server.go +++ b/extensions/accounts/pkg/command/server.go @@ -24,6 +24,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/accounts/pkg/config/config.go b/extensions/accounts/pkg/config/config.go index 9b46d2dbf17..d15aca3ba03 100644 --- a/extensions/accounts/pkg/config/config.go +++ b/extensions/accounts/pkg/config/config.go @@ -28,6 +28,8 @@ type Config struct { HashDifficulty int `yaml:"hash_difficulty" env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."` DemoUsersAndGroups bool `yaml:"demo_users_and_groups" env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."` + ConfigFile string `yaml:"-" env:"ACCOUNTS_CONFIG_FILE" desc:"config file to be used by the accounts extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/accounts/pkg/config/defaults/defaultconfig.go b/extensions/accounts/pkg/config/defaults/defaultconfig.go index d44ca4aafb3..b9f94e69961 100644 --- a/extensions/accounts/pkg/config/defaults/defaultconfig.go +++ b/extensions/accounts/pkg/config/defaults/defaultconfig.go @@ -19,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "accounts.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9182", Token: "", diff --git a/extensions/accounts/pkg/config/parser/parse.go b/extensions/accounts/pkg/config/parser/parse.go index 91d47c19d8a..90632414e54 100644 --- a/extensions/accounts/pkg/config/parser/parse.go +++ b/extensions/accounts/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/accounts/pkg/config" defaults "github.com/owncloud/ocis/extensions/accounts/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/accounts/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/accounts/pkg/service/v0/accounts.go b/extensions/accounts/pkg/service/v0/accounts.go index ca7a1c2659c..8c7c83c8f8b 100644 --- a/extensions/accounts/pkg/service/v0/accounts.go +++ b/extensions/accounts/pkg/service/v0/accounts.go @@ -24,12 +24,12 @@ import ( fieldmask_utils "github.com/mennanov/fieldmask-utils" "github.com/owncloud/ocis/extensions/accounts/pkg/storage" accTracing "github.com/owncloud/ocis/extensions/accounts/pkg/tracing" + settings_svc "github.com/owncloud/ocis/extensions/settings/pkg/service/v0" "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/middleware" "github.com/owncloud/ocis/ocis-pkg/roles" "github.com/owncloud/ocis/ocis-pkg/sync" settingssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/settings/v0" - settings_svc "github.com/owncloud/ocis/extensions/settings/pkg/service/v0" "github.com/rs/zerolog" merrors "go-micro.dev/v4/errors" "go-micro.dev/v4/metadata" diff --git a/extensions/audit/pkg/command/server.go b/extensions/audit/pkg/command/server.go index 25a031da0a9..6a9dc614094 100644 --- a/extensions/audit/pkg/command/server.go +++ b/extensions/audit/pkg/command/server.go @@ -21,6 +21,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/audit/pkg/config/config.go b/extensions/audit/pkg/config/config.go index b14a78a752a..3d5e313c32f 100644 --- a/extensions/audit/pkg/config/config.go +++ b/extensions/audit/pkg/config/config.go @@ -18,6 +18,8 @@ type Config struct { Events Events `yaml:"events"` Auditlog Auditlog `yaml:"auditlog"` + ConfigFile string `yaml:"-" env:"AUDIT_CONFIG_FILE" desc:"config file to be used by the audit extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/audit/pkg/config/defaults/defaultconfig.go b/extensions/audit/pkg/config/defaults/defaultconfig.go index 27b94a8147d..a59e98a350c 100644 --- a/extensions/audit/pkg/config/defaults/defaultconfig.go +++ b/extensions/audit/pkg/config/defaults/defaultconfig.go @@ -1,7 +1,10 @@ package defaults import ( + "path" + "github.com/owncloud/ocis/extensions/audit/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -15,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "audit.yaml"), + Service: config.Service{ Name: "audit", }, diff --git a/extensions/audit/pkg/config/parser/parse.go b/extensions/audit/pkg/config/parser/parse.go index 7c9179761c0..d1e84cc2497 100644 --- a/extensions/audit/pkg/config/parser/parse.go +++ b/extensions/audit/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/audit/pkg/config" "github.com/owncloud/ocis/extensions/audit/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/audit/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/glauth/pkg/command/server.go b/extensions/glauth/pkg/command/server.go index fda86d30c18..ff551ae133c 100644 --- a/extensions/glauth/pkg/command/server.go +++ b/extensions/glauth/pkg/command/server.go @@ -27,6 +27,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/glauth/pkg/config/config.go b/extensions/glauth/pkg/config/config.go index aa8479989a3..b55543744b1 100644 --- a/extensions/glauth/pkg/config/config.go +++ b/extensions/glauth/pkg/config/config.go @@ -24,6 +24,8 @@ type Config struct { RoleBundleUUID string `yaml:"role_bundle_uuid" env:"GLAUTH_ROLE_BUNDLE_ID"` + ConfigFile string `yaml:"-" env:"GLAUTH_CONFIG_FILE" desc:"config file to be used by the glauth extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/glauth/pkg/config/defaults/defaultconfig.go b/extensions/glauth/pkg/config/defaults/defaultconfig.go index 4ed303cb3da..e1537835791 100644 --- a/extensions/glauth/pkg/config/defaults/defaultconfig.go +++ b/extensions/glauth/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "glauth.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9129", }, diff --git a/extensions/glauth/pkg/config/parser/parse.go b/extensions/glauth/pkg/config/parser/parse.go index 532fb514953..fd8f98b8df1 100644 --- a/extensions/glauth/pkg/config/parser/parse.go +++ b/extensions/glauth/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/glauth/pkg/config" "github.com/owncloud/ocis/extensions/glauth/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/glauth/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,12 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) return nil } diff --git a/extensions/graph-explorer/pkg/command/server.go b/extensions/graph-explorer/pkg/command/server.go index 093cbe60b33..97552b032d0 100644 --- a/extensions/graph-explorer/pkg/command/server.go +++ b/extensions/graph-explorer/pkg/command/server.go @@ -22,7 +22,19 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", - Before: func(ctx *cli.Context) error { + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, + Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { diff --git a/extensions/graph-explorer/pkg/config/config.go b/extensions/graph-explorer/pkg/config/config.go index 2bd5bd5a62b..3ce158b5ed2 100644 --- a/extensions/graph-explorer/pkg/config/config.go +++ b/extensions/graph-explorer/pkg/config/config.go @@ -20,6 +20,8 @@ type Config struct { GraphExplorer GraphExplorer `yaml:"graph_explorer"` + ConfigFile string `yaml:"-" env:"GRAPH_EXPLORER_CONFIG_FILE" desc:"config file to be used by the graph-explorer extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go b/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go index a343da50af6..6048ebeb640 100644 --- a/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go +++ b/extensions/graph-explorer/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "graph-explorer.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9136", Token: "", diff --git a/extensions/graph-explorer/pkg/config/parser/parse.go b/extensions/graph-explorer/pkg/config/parser/parse.go index 499fbb8f369..4a6c4dad0f5 100644 --- a/extensions/graph-explorer/pkg/config/parser/parse.go +++ b/extensions/graph-explorer/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config" "github.com/owncloud/ocis/extensions/graph-explorer/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/graph-explorer/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,9 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/graph/pkg/command/server.go b/extensions/graph/pkg/command/server.go index c7e3e317a36..9be7fa218c8 100644 --- a/extensions/graph/pkg/command/server.go +++ b/extensions/graph/pkg/command/server.go @@ -22,6 +22,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/graph/pkg/config/config.go b/extensions/graph/pkg/config/config.go index 4d11d73f93e..41f4a26f040 100644 --- a/extensions/graph/pkg/config/config.go +++ b/extensions/graph/pkg/config/config.go @@ -25,6 +25,8 @@ type Config struct { Identity Identity `yaml:"identity"` Events Events `yaml:"events"` + ConfigFile string `yaml:"-" env:"GRAPH_CONFIG_FILE" desc:"config file to be used by the graph extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/graph/pkg/config/defaults/defaultconfig.go b/extensions/graph/pkg/config/defaults/defaultconfig.go index 49cd9916b57..88ab37f9c6b 100644 --- a/extensions/graph/pkg/config/defaults/defaultconfig.go +++ b/extensions/graph/pkg/config/defaults/defaultconfig.go @@ -1,13 +1,17 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/graph/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "graph.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9124", Token: "", diff --git a/extensions/graph/pkg/config/parser/parse.go b/extensions/graph/pkg/config/parser/parse.go index cf4612cc881..17041c8497c 100644 --- a/extensions/graph/pkg/config/parser/parse.go +++ b/extensions/graph/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/graph/pkg/config" "github.com/owncloud/ocis/extensions/graph/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/graph/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/idm/pkg/command/server.go b/extensions/idm/pkg/command/server.go index c63b0f2af70..f629c3dc6e8 100644 --- a/extensions/idm/pkg/command/server.go +++ b/extensions/idm/pkg/command/server.go @@ -28,6 +28,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/idm/pkg/config/config.go b/extensions/idm/pkg/config/config.go index 2706fe673fd..3e41b671151 100644 --- a/extensions/idm/pkg/config/config.go +++ b/extensions/idm/pkg/config/config.go @@ -17,10 +17,12 @@ type Config struct { Debug Debug `yaml:"debug"` IDM Settings `yaml:"idm"` - CreateDemoUsers bool `yaml:"create_demo_users" env:"IDM_CREATE_DEMO_USERS;ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"Flag to enabe/disable the creation of the demo users"` + CreateDemoUsers bool `yaml:"create_demo_users" env:"IDM_CREATE_DEMO_USERS;ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"Flag to enable/disable the creation of the demo users"` ServiceUserPasswords ServiceUserPasswords `yaml:"service_user_passwords"` + ConfigFile string `yaml:"-" env:"IDM_CONFIG_FILE" desc:"config file to be used by the IDM extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/idm/pkg/config/defaults/defaultconfig.go b/extensions/idm/pkg/config/defaults/defaultconfig.go index 983db3c0718..b3cf1179529 100644 --- a/extensions/idm/pkg/config/defaults/defaultconfig.go +++ b/extensions/idm/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "idm.yaml"), + Service: config.Service{ Name: "idm", }, diff --git a/extensions/idm/pkg/config/parser/parse.go b/extensions/idm/pkg/config/parser/parse.go index 0998543ad05..f27079b9408 100644 --- a/extensions/idm/pkg/config/parser/parse.go +++ b/extensions/idm/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/idm/pkg/config" "github.com/owncloud/ocis/extensions/idm/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/idm/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,12 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/idp/pkg/command/server.go b/extensions/idp/pkg/command/server.go index c541245d014..9ea1da17e07 100644 --- a/extensions/idp/pkg/command/server.go +++ b/extensions/idp/pkg/command/server.go @@ -22,6 +22,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/idp/pkg/config/config.go b/extensions/idp/pkg/config/config.go index 83bd84554d0..321bf2cbb4b 100644 --- a/extensions/idp/pkg/config/config.go +++ b/extensions/idp/pkg/config/config.go @@ -22,6 +22,8 @@ type Config struct { IDP Settings `yaml:"idp"` Ldap Ldap `yaml:"ldap"` + ConfigFile string `yaml:"-" env:"IDP_CONFIG_FILE" desc:"config file to be used by the IDP extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/idp/pkg/config/defaults/defaultconfig.go b/extensions/idp/pkg/config/defaults/defaultconfig.go index 2be18b92a46..490af6d86a2 100644 --- a/extensions/idp/pkg/config/defaults/defaultconfig.go +++ b/extensions/idp/pkg/config/defaults/defaultconfig.go @@ -19,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "idp1.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9134", }, diff --git a/extensions/idp/pkg/config/parser/parse.go b/extensions/idp/pkg/config/parser/parse.go index 101ea85bdcc..9d28b54a51c 100644 --- a/extensions/idp/pkg/config/parser/parse.go +++ b/extensions/idp/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/idp/pkg/config" "github.com/owncloud/ocis/extensions/idp/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/idp/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/nats/pkg/command/server.go b/extensions/nats/pkg/command/server.go index 79f3f7f4434..26474e18f11 100644 --- a/extensions/nats/pkg/command/server.go +++ b/extensions/nats/pkg/command/server.go @@ -19,6 +19,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/nats/pkg/config/config.go b/extensions/nats/pkg/config/config.go index 3d1c279443b..da5bf190afe 100644 --- a/extensions/nats/pkg/config/config.go +++ b/extensions/nats/pkg/config/config.go @@ -17,6 +17,8 @@ type Config struct { Nats Nats `ociConfig:"nats"` + ConfigFile string `yaml:"-" env:"NATS_CONFIG_FILE" desc:"config file to be used by the NATS extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/nats/pkg/config/defaults/defaultconfig.go b/extensions/nats/pkg/config/defaults/defaultconfig.go index f9435ff4df2..88cc04af545 100644 --- a/extensions/nats/pkg/config/defaults/defaultconfig.go +++ b/extensions/nats/pkg/config/defaults/defaultconfig.go @@ -21,6 +21,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "nats.yaml"), + Service: config.Service{ Name: "nats", }, diff --git a/extensions/nats/pkg/config/parser/parse.go b/extensions/nats/pkg/config/parser/parse.go index 2a427a3bd91..f1d97dfc046 100644 --- a/extensions/nats/pkg/config/parser/parse.go +++ b/extensions/nats/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/nats/pkg/config" "github.com/owncloud/ocis/extensions/nats/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/nats/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/notifications/pkg/command/server.go b/extensions/notifications/pkg/command/server.go index ad7eda613cf..cb96fb654c2 100644 --- a/extensions/notifications/pkg/command/server.go +++ b/extensions/notifications/pkg/command/server.go @@ -20,6 +20,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/notifications/pkg/config/config.go b/extensions/notifications/pkg/config/config.go index 7cc1838523a..1e56e38b3c2 100644 --- a/extensions/notifications/pkg/config/config.go +++ b/extensions/notifications/pkg/config/config.go @@ -17,6 +17,8 @@ type Config struct { Notifications Notifications `yaml:"notifications"` + ConfigFile string `yaml:"-" env:"NOTIFICATIONS_CONFIG_FILE" desc:"config file to be used by the notifications extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/notifications/pkg/config/defaults/defaultconfig.go b/extensions/notifications/pkg/config/defaults/defaultconfig.go index 19c3cc2df8e..fb82f2c8152 100644 --- a/extensions/notifications/pkg/config/defaults/defaultconfig.go +++ b/extensions/notifications/pkg/config/defaults/defaultconfig.go @@ -1,6 +1,11 @@ package defaults -import "github.com/owncloud/ocis/extensions/notifications/pkg/config" +import ( + "path" + + "github.com/owncloud/ocis/extensions/notifications/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" +) func FullDefaultConfig() *config.Config { cfg := DefaultConfig() @@ -16,6 +21,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "notifications.yaml"), + Service: config.Service{ Name: "notifications", }, diff --git a/extensions/notifications/pkg/config/parser/parse.go b/extensions/notifications/pkg/config/parser/parse.go index 2a4876a33c5..bd378a42bc9 100644 --- a/extensions/notifications/pkg/config/parser/parse.go +++ b/extensions/notifications/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/notifications/pkg/config" "github.com/owncloud/ocis/extensions/notifications/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/notifications/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/ocs/pkg/command/server.go b/extensions/ocs/pkg/command/server.go index 0b88c99728e..34c8beabee0 100644 --- a/extensions/ocs/pkg/command/server.go +++ b/extensions/ocs/pkg/command/server.go @@ -23,6 +23,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/ocs/pkg/config/config.go b/extensions/ocs/pkg/config/config.go index 52d7e954248..c393339bdd9 100644 --- a/extensions/ocs/pkg/config/config.go +++ b/extensions/ocs/pkg/config/config.go @@ -27,6 +27,8 @@ type Config struct { StorageUsersDriver string `yaml:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"` MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"` + ConfigFile string `yaml:"-" env:"OCS_CONFIG_FILE" desc:"config file to be used by the ocs extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/ocs/pkg/config/defaults/defaultconfig.go b/extensions/ocs/pkg/config/defaults/defaultconfig.go index 90edea71eb4..f72f4e5b328 100644 --- a/extensions/ocs/pkg/config/defaults/defaultconfig.go +++ b/extensions/ocs/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/ocs/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "ocs.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9114", Token: "", diff --git a/extensions/ocs/pkg/config/parser/parse.go b/extensions/ocs/pkg/config/parser/parse.go index b9c312ca3d3..99227d51629 100644 --- a/extensions/ocs/pkg/config/parser/parse.go +++ b/extensions/ocs/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/ocs/pkg/config" "github.com/owncloud/ocis/extensions/ocs/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/ocs/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/ocs/pkg/service/v0/data/user.go b/extensions/ocs/pkg/service/v0/data/user.go index 34da73400e5..8b210afb570 100644 --- a/extensions/ocs/pkg/service/v0/data/user.go +++ b/extensions/ocs/pkg/service/v0/data/user.go @@ -8,7 +8,7 @@ type Users struct { // User holds the payload for a GetUser response type User struct { Enabled string `json:"enabled" xml:"enabled"` - UserID string `json:"id" xml:"id"`// UserID is mapped to the preferred_name attribute in accounts + UserID string `json:"id" xml:"id"` // UserID is mapped to the preferred_name attribute in accounts DisplayName string `json:"display-name" xml:"display-name"` LegacyDisplayName string `json:"displayname" xml:"displayname"` Email string `json:"email" xml:"email"` diff --git a/extensions/proxy/pkg/command/server.go b/extensions/proxy/pkg/command/server.go index 83322463998..b51cc895a57 100644 --- a/extensions/proxy/pkg/command/server.go +++ b/extensions/proxy/pkg/command/server.go @@ -42,6 +42,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/proxy/pkg/config/config.go b/extensions/proxy/pkg/config/config.go index 7beb4d9c4cd..69b1fc632d4 100644 --- a/extensions/proxy/pkg/config/config.go +++ b/extensions/proxy/pkg/config/config.go @@ -34,6 +34,8 @@ type Config struct { InsecureBackends bool `yaml:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"` AuthMiddleware AuthMiddleware `yaml:"auth_middleware"` + ConfigFile string `yaml:"-" env:"PROXY_CONFIG_FILE" desc:"config file to be used by the proxy extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/proxy/pkg/config/defaults/defaultconfig.go b/extensions/proxy/pkg/config/defaults/defaultconfig.go index 487f9f09ab3..816b00514a6 100644 --- a/extensions/proxy/pkg/config/defaults/defaultconfig.go +++ b/extensions/proxy/pkg/config/defaults/defaultconfig.go @@ -10,6 +10,8 @@ import ( func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "proxy.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9205", Token: "", diff --git a/extensions/proxy/pkg/config/parser/parse.go b/extensions/proxy/pkg/config/parser/parse.go index 2f29670f658..f917435e4d6 100644 --- a/extensions/proxy/pkg/config/parser/parse.go +++ b/extensions/proxy/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/proxy/pkg/config" "github.com/owncloud/ocis/extensions/proxy/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/proxy/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,12 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/settings/pkg/command/server.go b/extensions/settings/pkg/command/server.go index 877b48b2fa3..a5f091e017c 100644 --- a/extensions/settings/pkg/command/server.go +++ b/extensions/settings/pkg/command/server.go @@ -23,6 +23,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/settings/pkg/config/config.go b/extensions/settings/pkg/config/config.go index a60b2df1f3f..7753092476e 100644 --- a/extensions/settings/pkg/config/config.go +++ b/extensions/settings/pkg/config/config.go @@ -26,6 +26,8 @@ type Config struct { Asset Asset `yaml:"asset"` TokenManager TokenManager `yaml:"token_manager"` + ConfigFile string `yaml:"-" env:"SETTINGS_CONFIG_FILE" desc:"config file to be used by the settings extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/settings/pkg/config/defaults/defaultconfig.go b/extensions/settings/pkg/config/defaults/defaultconfig.go index 4a3a4cd3189..22ffed1dea5 100644 --- a/extensions/settings/pkg/config/defaults/defaultconfig.go +++ b/extensions/settings/pkg/config/defaults/defaultconfig.go @@ -20,6 +20,8 @@ func FullDefaultConfig() *config.Config { // DefaultConfig returns the default config func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "settings.yaml"), + Service: config.Service{ Name: "settings", }, diff --git a/extensions/settings/pkg/config/parser/parse.go b/extensions/settings/pkg/config/parser/parse.go index 3880a7ebbc4..c5049620ffa 100644 --- a/extensions/settings/pkg/config/parser/parse.go +++ b/extensions/settings/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/settings/pkg/config" "github.com/owncloud/ocis/extensions/settings/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/settings/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,12 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -25,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/storage/pkg/command/gateway.go b/extensions/storage/pkg/command/gateway.go index 944d39d7501..390b393a1a2 100644 --- a/extensions/storage/pkg/command/gateway.go +++ b/extensions/storage/pkg/command/gateway.go @@ -14,6 +14,7 @@ import ( "github.com/mitchellh/mapstructure" "github.com/oklog/run" "github.com/owncloud/ocis/extensions/storage/pkg/config" + "github.com/owncloud/ocis/extensions/storage/pkg/config/defaults" "github.com/owncloud/ocis/extensions/storage/pkg/server/debug" "github.com/owncloud/ocis/extensions/storage/pkg/service/external" "github.com/owncloud/ocis/extensions/storage/pkg/tracing" @@ -415,7 +416,7 @@ func (s GatewaySutureService) Serve(ctx context.Context) error { // ParseConfig loads accounts configuration from known paths. func ParseConfig(c *cli.Context, cfg *config.Config, storageExtension string) error { - conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg) + conf, err := ociscfg.BindSourcesToStructs(storageExtension, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { return err } diff --git a/extensions/storage/pkg/config/config.go b/extensions/storage/pkg/config/config.go index cfd35175e71..f21ddae9880 100644 --- a/extensions/storage/pkg/config/config.go +++ b/extensions/storage/pkg/config/config.go @@ -531,6 +531,8 @@ type Config struct { Reva Reva `yaml:"reva"` Tracing Tracing `yaml:"tracing"` Asset Asset `yaml:"asset"` + + ConfigFile string `yaml:"-" env:"STORAGE_CONFIG_FILE" desc:"config file to be used by the storage extensions"` } // New initializes a new configuration with or without defaults. diff --git a/extensions/storage/pkg/config/defaults/defaultconfig.go b/extensions/storage/pkg/config/defaults/defaultconfig.go index 95cc5c6cd2f..14a996e6552 100644 --- a/extensions/storage/pkg/config/defaults/defaultconfig.go +++ b/extensions/storage/pkg/config/defaults/defaultconfig.go @@ -29,6 +29,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "storage.yaml"), + // log is inherited Debug: config.Debug{ Addr: "127.0.0.1:9109", diff --git a/extensions/store/pkg/command/server.go b/extensions/store/pkg/command/server.go index ac14affd2cf..2db6888ab5f 100644 --- a/extensions/store/pkg/command/server.go +++ b/extensions/store/pkg/command/server.go @@ -23,6 +23,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/store/pkg/config/config.go b/extensions/store/pkg/config/config.go index 2c210a34a8a..2888be49731 100644 --- a/extensions/store/pkg/config/config.go +++ b/extensions/store/pkg/config/config.go @@ -20,5 +20,7 @@ type Config struct { Datapath string `yaml:"data_path" env:"STORE_DATA_PATH"` + ConfigFile string `yaml:"-" env:"STORE_CONFIG_FILE" desc:"config file to be used by the store extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/store/pkg/config/defaults/defaultconfig.go b/extensions/store/pkg/config/defaults/defaultconfig.go index 1d84c1c4746..427f87b3404 100644 --- a/extensions/store/pkg/config/defaults/defaultconfig.go +++ b/extensions/store/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "store.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9464", Token: "", diff --git a/extensions/store/pkg/config/parser/parse.go b/extensions/store/pkg/config/parser/parse.go index 7c9f02bda38..0b2016dab53 100644 --- a/extensions/store/pkg/config/parser/parse.go +++ b/extensions/store/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/store/pkg/config" "github.com/owncloud/ocis/extensions/store/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/store/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) return nil } diff --git a/extensions/thumbnails/pkg/command/server.go b/extensions/thumbnails/pkg/command/server.go index 8bfd35a1bdb..2b1cb641abd 100644 --- a/extensions/thumbnails/pkg/command/server.go +++ b/extensions/thumbnails/pkg/command/server.go @@ -23,6 +23,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/thumbnails/pkg/config/config.go b/extensions/thumbnails/pkg/config/config.go index 0afad535c69..56f5fcac697 100644 --- a/extensions/thumbnails/pkg/config/config.go +++ b/extensions/thumbnails/pkg/config/config.go @@ -21,6 +21,8 @@ type Config struct { Thumbnail Thumbnail `yaml:"thumbnail"` + ConfigFile string `yaml:"-" env:"THUMBNAILS_CONFIG_FILE" desc:"config file to be used by the thumbnails extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go index c74b85065b1..d3a124b3472 100644 --- a/extensions/thumbnails/pkg/config/defaults/defaultconfig.go +++ b/extensions/thumbnails/pkg/config/defaults/defaultconfig.go @@ -18,6 +18,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "thumbnails.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9189", Token: "", diff --git a/extensions/thumbnails/pkg/config/parser/parse.go b/extensions/thumbnails/pkg/config/parser/parse.go index 4ed73255342..5c542917507 100644 --- a/extensions/thumbnails/pkg/config/parser/parse.go +++ b/extensions/thumbnails/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/thumbnails/pkg/config" "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/thumbnails/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,9 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - // sanitize config - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/web/pkg/command/server.go b/extensions/web/pkg/command/server.go index e62494d0729..39e0b282f50 100644 --- a/extensions/web/pkg/command/server.go +++ b/extensions/web/pkg/command/server.go @@ -23,6 +23,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/web/pkg/config/config.go b/extensions/web/pkg/config/config.go index dbc7feee051..8f3c50a963d 100644 --- a/extensions/web/pkg/config/config.go +++ b/extensions/web/pkg/config/config.go @@ -22,6 +22,8 @@ type Config struct { File string `yaml:"file" env:"WEB_UI_CONFIG"` // TODO: rename this to a more self explaining string Web Web `yaml:"web"` + ConfigFile string `yaml:"-" env:"WEB_CONFIG_FILE" desc:"config file to be used by the web extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/web/pkg/config/defaults/defaultconfig.go b/extensions/web/pkg/config/defaults/defaultconfig.go index bbfad9bdfd3..8ff59503075 100644 --- a/extensions/web/pkg/config/defaults/defaultconfig.go +++ b/extensions/web/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/web/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "web.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9104", Token: "", diff --git a/extensions/web/pkg/config/parser/parse.go b/extensions/web/pkg/config/parser/parse.go index d850943577a..e5f07184fff 100644 --- a/extensions/web/pkg/config/parser/parse.go +++ b/extensions/web/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/web/pkg/config" "github.com/owncloud/ocis/extensions/web/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/web/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/webdav/pkg/command/server.go b/extensions/webdav/pkg/command/server.go index 291276cbbe7..47385cde033 100644 --- a/extensions/webdav/pkg/command/server.go +++ b/extensions/webdav/pkg/command/server.go @@ -22,6 +22,18 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name), Category: "server", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "config-file", + Value: cfg.ConfigFile, + Usage: "config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + &cli.StringFlag{ + Name: "ocis-config-file", + Hidden: true, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/extensions/webdav/pkg/config/config.go b/extensions/webdav/pkg/config/config.go index 4efe95ebdfe..f5861d537c3 100644 --- a/extensions/webdav/pkg/config/config.go +++ b/extensions/webdav/pkg/config/config.go @@ -22,5 +22,7 @@ type Config struct { WebdavNamespace string `yaml:"webdav_namespace" env:"STORAGE_WEBDAV_NAMESPACE"` //TODO: prevent this cross config RevaGateway string `yaml:"reva_gateway" env:"REVA_GATEWAY"` + ConfigFile string `yaml:"-" env:"WEBDAV_CONFIG_FILE" desc:"config file to be used by the webdav extension"` + Context context.Context `yaml:"-"` } diff --git a/extensions/webdav/pkg/config/defaults/defaultconfig.go b/extensions/webdav/pkg/config/defaults/defaultconfig.go index 48e00e17f1a..40f1d8b20a7 100644 --- a/extensions/webdav/pkg/config/defaults/defaultconfig.go +++ b/extensions/webdav/pkg/config/defaults/defaultconfig.go @@ -1,9 +1,11 @@ package defaults import ( + "path" "strings" "github.com/owncloud/ocis/extensions/webdav/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func FullDefaultConfig() *config.Config { @@ -17,6 +19,8 @@ func FullDefaultConfig() *config.Config { func DefaultConfig() *config.Config { return &config.Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "webdav.yaml"), + Debug: config.Debug{ Addr: "127.0.0.1:9119", Token: "", diff --git a/extensions/webdav/pkg/config/parser/parse.go b/extensions/webdav/pkg/config/parser/parse.go index 7597255f9cc..f5ab2ae810a 100644 --- a/extensions/webdav/pkg/config/parser/parse.go +++ b/extensions/webdav/pkg/config/parser/parse.go @@ -5,6 +5,7 @@ import ( "github.com/owncloud/ocis/extensions/webdav/pkg/config" "github.com/owncloud/ocis/extensions/webdav/pkg/config/defaults" + "github.com/owncloud/ocis/extensions/webdav/pkg/logging" ociscfg "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" @@ -12,13 +13,31 @@ import ( // ParseConfig loads accounts configuration from known paths. func ParseConfig(cfg *config.Config) error { - _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg) + + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg.ConfigFile, cfg.ConfigFile != defaults.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := logging.Configure(cfg.Service.Name, &config.Log{}) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } defaults.EnsureDefaults(cfg) + if err := loadEnv(cfg); err != nil { + return err + } + + defaults.Sanitize(cfg) + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -26,8 +45,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - - defaults.Sanitize(cfg) - return nil } diff --git a/extensions/webdav/pkg/metrics/metrics.go b/extensions/webdav/pkg/metrics/metrics.go index ea5f9626e11..d0869cdf829 100644 --- a/extensions/webdav/pkg/metrics/metrics.go +++ b/extensions/webdav/pkg/metrics/metrics.go @@ -28,8 +28,8 @@ func New() *Metrics { BuildInfo: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: Namespace, Subsystem: Subsystem, - Name: "build_info", - Help: "Build Information", + Name: "build_info", + Help: "Build Information", }, []string{"version"}), } diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go index f7c71952ecb..1a7277a89c9 100644 --- a/ocis-pkg/config/config.go +++ b/ocis-pkg/config/config.go @@ -51,8 +51,6 @@ type Config struct { Tracing shared.Tracing `yaml:"tracing"` Log *shared.Log `yaml:"log"` - Mode Mode // DEPRECATED - File string OcisURL string `yaml:"ocis_url"` Registry string `yaml:"registry"` @@ -76,4 +74,6 @@ type Config struct { Store *store.Config `yaml:"store"` Thumbnails *thumbnails.Config `yaml:"thumbnails"` WebDAV *webdav.Config `yaml:"webdav"` + + ConfigFile string `yaml:"-" env:"OCIS_CONFIG_FILE" desc:"config file to be used by the oCIS runtime and extensions"` } diff --git a/ocis-pkg/config/defaultconfig.go b/ocis-pkg/config/defaultconfig.go index bc94a224ce8..914f3cde3a5 100644 --- a/ocis-pkg/config/defaultconfig.go +++ b/ocis-pkg/config/defaultconfig.go @@ -1,6 +1,8 @@ package config import ( + "path" + accounts "github.com/owncloud/ocis/extensions/accounts/pkg/config/defaults" audit "github.com/owncloud/ocis/extensions/audit/pkg/config/defaults" glauth "github.com/owncloud/ocis/extensions/glauth/pkg/config/defaults" @@ -18,10 +20,13 @@ import ( thumbnails "github.com/owncloud/ocis/extensions/thumbnails/pkg/config/defaults" web "github.com/owncloud/ocis/extensions/web/pkg/config/defaults" webdav "github.com/owncloud/ocis/extensions/webdav/pkg/config/defaults" + "github.com/owncloud/ocis/ocis-pkg/config/defaults" ) func DefaultConfig() *Config { return &Config{ + ConfigFile: path.Join(defaults.BaseConfigPath(), "ocis.yaml"), + TokenManager: TokenManager{ JWTSecret: "Pive-Fumkiu4", }, diff --git a/ocis-pkg/config/defaults/paths.go b/ocis-pkg/config/defaults/paths.go index 9980daedaa6..fbbc2a6372b 100644 --- a/ocis-pkg/config/defaults/paths.go +++ b/ocis-pkg/config/defaults/paths.go @@ -10,16 +10,16 @@ const () var ( // switch between modes - BaseDataPathType = "homedir" - // don't read from this, only write + BaseDataPathType = "homedir" // or "path" + // default data path BaseDataPathValue = "/var/lib/ocis" ) func BaseDataPath() string { // It is not nice to have hidden / secrete configuration options - // But how can we update the base path for every occurence with a flageset option? - // This is currenlty not possible and needs a new configuration concept + // But how can we update the base path for every occurrence with a flagset option? + // This is currently not possible and needs a new configuration concept p := os.Getenv("OCIS_BASE_DATA_PATH") if p != "" { return p @@ -40,3 +40,36 @@ func BaseDataPath() string { return "" } } + +var ( + // switch between modes + BaseConfigPathType = "homedir" // or "path" + // default config path + BaseConfigPathValue = "/etc/ocis" +) + +func BaseConfigPath() string { + + // It is not nice to have hidden / secrete configuration options + // But how can we update the base path for every occurrence with a flagset option? + // This is currently not possible and needs a new configuration concept + p := os.Getenv("OCIS_CONFIG_DIR") + if p != "" { + return p + } + + switch BaseConfigPathType { + case "homedir": + dir, err := os.UserHomeDir() + if err != nil { + // fallback to BaseConfigPathValue for users without home + return BaseConfigPathValue + } + return path.Join(dir, ".ocis", "config") + case "path": + return BaseConfigPathValue + default: + log.Fatalf("BaseConfigPathType %s not found", BaseConfigPathType) + return "" + } +} diff --git a/ocis-pkg/config/helpers.go b/ocis-pkg/config/helpers.go index 6eac8984757..fa59776da16 100644 --- a/ocis-pkg/config/helpers.go +++ b/ocis-pkg/config/helpers.go @@ -1,89 +1,33 @@ package config import ( - "io/fs" - "os" - "path/filepath" - "strings" - gofig "github.com/gookit/config/v2" gooyaml "github.com/gookit/config/v2/yaml" ) var ( - defaultLocations = []string{ - filepath.Join(os.Getenv("HOME"), "/.ocis/config/"), - "/etc/ocis/", - ".config/", - } - - // supportedExtensions is determined by gookit/config. - supportedExtensions = []string{ - "yaml", - "yml", - } + // decoderConfigTagname sets the tag name to be used from the config structs + // currently we only support "yaml" because we only support config loading + // from yaml files and the yaml parser has no simple way to set a custom tag name to use + decoderConfigTagName = "yaml" ) -// DefaultConfigSources returns a slice with matched expected config files. It sugars coat several aspects of config file -// management by assuming there are 3 default locations a config file could be. -// It uses globbing to match a config file by name, and retrieve any supported extension supported by our drivers. -// It sanitizes the output depending on the list of drivers provided. -func DefaultConfigSources(filename string, drivers []string) []string { - var sources []string - - locations := []string{} - if v := os.Getenv("OCIS_CONFIG_DIR"); v != "" { - locations = append(locations, v) - // only use the configured config dir - locations = append(locations, os.Getenv("OCIS_CONFIG_DIR")) - } else { - // merge config from all default locations - locations = append(locations, defaultLocations...) - } - - for i := range locations { - dirFS := os.DirFS(locations[i]) - pattern := filename + ".*" - matched, _ := fs.Glob(dirFS, pattern) - if len(matched) > 0 { - // prepend path to results - for j := 0; j < len(matched); j++ { - matched[j] = filepath.Join(locations[i], matched[j]) - } - } - sources = append(sources, matched...) - } - - return sanitizeExtensions(sources, drivers, func(a, b string) bool { - return strings.HasSuffix(filepath.Base(a), b) - }) -} - -// sanitizeExtensions removes elements from "set" which extensions are not in "ext". -func sanitizeExtensions(set []string, ext []string, f func(a, b string) bool) []string { - var r []string - for i := 0; i < len(set); i++ { - for j := 0; j < len(ext); j++ { - if f(filepath.Base(set[i]), ext[j]) { - r = append(r, set[i]) - } - } - } - return r -} - // BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`. Its only purpose // is to solely modify `dst`, not dealing with the config structs; and do so in a thread safe manner. -func BindSourcesToStructs(extension string, dst interface{}) (*gofig.Config, error) { - sources := DefaultConfigSources(extension, supportedExtensions) +func BindSourcesToStructs(extension, ConfigFile string, failOnLoadErr bool, dst interface{}) (*gofig.Config, error) { cnf := gofig.NewWithOptions(extension) cnf.WithOptions(func(options *gofig.Options) { - options.DecoderConfig.TagName = "yaml" + options.DecoderConfig.TagName = decoderConfigTagName }) cnf.AddDriver(gooyaml.Driver) - _ = cnf.LoadFiles(sources...) - err := cnf.BindStruct("", &dst) + err := cnf.LoadFiles([]string{ConfigFile}...) + if err != nil && failOnLoadErr { + // fail only if config file was explicitly set + return nil, err + } + + err = cnf.BindStruct("", &dst) if err != nil { return nil, err } diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go index ba75a411c0d..a988adcca20 100644 --- a/ocis-pkg/config/parser/parse.go +++ b/ocis-pkg/config/parser/parse.go @@ -5,13 +5,23 @@ import ( "github.com/owncloud/ocis/ocis-pkg/config" "github.com/owncloud/ocis/ocis-pkg/config/envdecode" + "github.com/owncloud/ocis/ocis-pkg/log" "github.com/owncloud/ocis/ocis-pkg/shared" ) // ParseConfig loads ocis configuration. func ParseConfig(cfg *config.Config) error { - _, err := config.BindSourcesToStructs("ocis", cfg) + // cfg.ConfigFile can be set via env variable, therefore we need to do a environment variable run first + if err := loadEnv(cfg); err != nil { + return err + } + + _, err := config.BindSourcesToStructs("ocis", cfg.ConfigFile, cfg.ConfigFile != config.DefaultConfig().ConfigFile, cfg) if err != nil { + logger := log.NewLogger( + log.Name("oCIS"), + ) + logger.Error().Err(err).Msg("couldn't find the specified config file") return err } @@ -27,6 +37,14 @@ func ParseConfig(cfg *config.Config) error { cfg.Log = &shared.Log{} } + if err := loadEnv(cfg); err != nil { + return err + } + + return nil +} + +func loadEnv(cfg *config.Config) error { // load all env variables relevant to the config in the current context. if err := envdecode.Decode(cfg); err != nil { // no environment variable set for this config is an expected "error" @@ -34,6 +52,5 @@ func ParseConfig(cfg *config.Config) error { return err } } - return nil } diff --git a/ocis-pkg/sync/cache.go b/ocis-pkg/sync/cache.go index e63690b35d8..9638a93ef79 100644 --- a/ocis-pkg/sync/cache.go +++ b/ocis-pkg/sync/cache.go @@ -11,8 +11,8 @@ type Cache struct { // capacity and length have to be the first words // in order to be 64-aligned on 32-bit architectures. capacity, length uint64 // access atomically - entries sync.Map - pool sync.Pool + entries sync.Map + pool sync.Pool } // CacheEntry represents an entry on the cache. You can type assert on V. diff --git a/ocis/docker/Dockerfile.linux.amd64 b/ocis/docker/Dockerfile.linux.amd64 index 6729daf58b6..8d339141362 100644 --- a/ocis/docker/Dockerfile.linux.amd64 +++ b/ocis/docker/Dockerfile.linux.amd64 @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 diff --git a/ocis/docker/Dockerfile.linux.arm b/ocis/docker/Dockerfile.linux.arm index 922246bb051..cb6f757b85f 100644 --- a/ocis/docker/Dockerfile.linux.arm +++ b/ocis/docker/Dockerfile.linux.arm @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 diff --git a/ocis/docker/Dockerfile.linux.arm64 b/ocis/docker/Dockerfile.linux.arm64 index 47ccad92636..7601ed39e74 100644 --- a/ocis/docker/Dockerfile.linux.arm64 +++ b/ocis/docker/Dockerfile.linux.arm64 @@ -26,9 +26,12 @@ RUN addgroup -g 1000 -S ocis-group && \ RUN mkdir -p /var/lib/ocis && \ chown -R ocis-user:ocis-group /var/lib/ocis && \ - chmod -R 777 /var/lib/ocis + chmod -R 777 /var/lib/ocis && \ + mkdir -p /etc/ocis && \ + chown -R ocis-user:ocis-group /etc/ocis && \ + chmod -R 777 /etc/ocis -VOLUME [ "/var/lib/ocis" ] +VOLUME [ "/var/lib/ocis", "/etc/ocis" ] WORKDIR /var/lib/ocis USER 1000 diff --git a/ocis/pkg/command/accounts.go b/ocis/pkg/command/accounts.go index f8a56bfcc5b..5475ffb5cef 100644 --- a/ocis/pkg/command/accounts.go +++ b/ocis/pkg/command/accounts.go @@ -14,6 +14,14 @@ func AccountsCommand(cfg *config.Config) *cli.Command { Name: cfg.Accounts.Service.Name, Usage: subcommandDescription(cfg.Accounts.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/audit.go b/ocis/pkg/command/audit.go index 638367a166b..fb73c602a1f 100644 --- a/ocis/pkg/command/audit.go +++ b/ocis/pkg/command/audit.go @@ -14,6 +14,14 @@ func AuditCommand(cfg *config.Config) *cli.Command { Name: "audit", Usage: "start audit service", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index ad91954eb03..a60598db87a 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -14,6 +14,14 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Name: cfg.GLAuth.Service.Name, Usage: subcommandDescription(cfg.GLAuth.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graph.go b/ocis/pkg/command/graph.go index 836ad44465d..ad00998082b 100644 --- a/ocis/pkg/command/graph.go +++ b/ocis/pkg/command/graph.go @@ -14,6 +14,14 @@ func GraphCommand(cfg *config.Config) *cli.Command { Name: cfg.Graph.Service.Name, Usage: subcommandDescription(cfg.Graph.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/graphexplorer.go b/ocis/pkg/command/graphexplorer.go index 95be9e503ff..8a407c9056d 100644 --- a/ocis/pkg/command/graphexplorer.go +++ b/ocis/pkg/command/graphexplorer.go @@ -14,6 +14,14 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command { Name: cfg.GraphExplorer.Service.Name, Usage: subcommandDescription(cfg.GraphExplorer.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/idm.go b/ocis/pkg/command/idm.go index d768b6dc58b..886b6f79d27 100644 --- a/ocis/pkg/command/idm.go +++ b/ocis/pkg/command/idm.go @@ -14,6 +14,14 @@ func IDMCommand(cfg *config.Config) *cli.Command { Name: "idm", Usage: "idm extension commands", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the extension", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/idp.go b/ocis/pkg/command/idp.go index 0c6828c5928..e84c31c9508 100644 --- a/ocis/pkg/command/idp.go +++ b/ocis/pkg/command/idp.go @@ -14,6 +14,14 @@ func IDPCommand(cfg *config.Config) *cli.Command { Name: cfg.IDP.Service.Name, Usage: subcommandDescription(cfg.IDP.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/natsserver.go b/ocis/pkg/command/natsserver.go index 1e7f3432317..dd14365c6a9 100644 --- a/ocis/pkg/command/natsserver.go +++ b/ocis/pkg/command/natsserver.go @@ -14,6 +14,14 @@ func NatsServerCommand(cfg *config.Config) *cli.Command { Name: "nats-server", Usage: "start nats server", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/notifications.go b/ocis/pkg/command/notifications.go index f4108e299af..356fa15b5ed 100644 --- a/ocis/pkg/command/notifications.go +++ b/ocis/pkg/command/notifications.go @@ -14,6 +14,14 @@ func NotificationsCommand(cfg *config.Config) *cli.Command { Name: "notifications", Usage: "start notifications service", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/ocdav.go b/ocis/pkg/command/ocdav.go index c458ee28564..62ec1119c1d 100644 --- a/ocis/pkg/command/ocdav.go +++ b/ocis/pkg/command/ocdav.go @@ -13,6 +13,14 @@ func OCDavCommand(cfg *config.Config) *cli.Command { Name: "ocdav", Usage: "start ocdav", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/ocs.go b/ocis/pkg/command/ocs.go index 2fae3beb95d..9c0b5cc7139 100644 --- a/ocis/pkg/command/ocs.go +++ b/ocis/pkg/command/ocs.go @@ -14,6 +14,14 @@ func OCSCommand(cfg *config.Config) *cli.Command { Name: cfg.OCS.Service.Name, Usage: subcommandDescription(cfg.OCS.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/proxy.go b/ocis/pkg/command/proxy.go index 429ca83e19f..eb639588dfa 100644 --- a/ocis/pkg/command/proxy.go +++ b/ocis/pkg/command/proxy.go @@ -14,6 +14,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command { Name: cfg.Proxy.Service.Name, Usage: subcommandDescription(cfg.Proxy.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/server.go b/ocis/pkg/command/server.go index 00b9c89da31..7acbc557d30 100644 --- a/ocis/pkg/command/server.go +++ b/ocis/pkg/command/server.go @@ -15,6 +15,14 @@ func Server(cfg *config.Config) *cli.Command { Name: "server", Usage: "start a fullstack server (runtime and all extensions in supervised mode)", Category: "fullstack", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(c *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/settings.go b/ocis/pkg/command/settings.go index 32c8b43e690..0338d22878f 100644 --- a/ocis/pkg/command/settings.go +++ b/ocis/pkg/command/settings.go @@ -14,6 +14,14 @@ func SettingsCommand(cfg *config.Config) *cli.Command { Name: cfg.Settings.Service.Name, Usage: subcommandDescription(cfg.Settings.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/storageappprovider.go b/ocis/pkg/command/storageappprovider.go index 39444d49262..66e2767e915 100644 --- a/ocis/pkg/command/storageappprovider.go +++ b/ocis/pkg/command/storageappprovider.go @@ -13,7 +13,14 @@ func StorageAppProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-app-provider", Usage: "start storage app-provider service", Category: "extensions", - //Flags: flagset.AppProviderWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthbasic.go b/ocis/pkg/command/storageauthbasic.go index 5059fd1e0ad..22f3aaea79c 100644 --- a/ocis/pkg/command/storageauthbasic.go +++ b/ocis/pkg/command/storageauthbasic.go @@ -13,7 +13,14 @@ func StorageAuthBasicCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-basic", Usage: "start storage auth-basic service", Category: "extensions", - //Flags: flagset.AuthBasicWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthbearer.go b/ocis/pkg/command/storageauthbearer.go index f9b1912f507..464d0206194 100644 --- a/ocis/pkg/command/storageauthbearer.go +++ b/ocis/pkg/command/storageauthbearer.go @@ -13,7 +13,14 @@ func StorageAuthBearerCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-bearer", Usage: "Start storage auth-bearer service", Category: "extensions", - //Flags: flagset.AuthBearerWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageauthmachine.go b/ocis/pkg/command/storageauthmachine.go index 64bded070cb..fd02f367de1 100644 --- a/ocis/pkg/command/storageauthmachine.go +++ b/ocis/pkg/command/storageauthmachine.go @@ -13,7 +13,14 @@ func StorageAuthMachineCommand(cfg *config.Config) *cli.Command { Name: "storage-auth-machine", Usage: "start storage auth-machine service", Category: "extensions", - //Flags: flagset.AuthMachineWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagefrontend.go b/ocis/pkg/command/storagefrontend.go index 0bc98cbbdb5..184096fb645 100644 --- a/ocis/pkg/command/storagefrontend.go +++ b/ocis/pkg/command/storagefrontend.go @@ -13,7 +13,14 @@ func StorageFrontendCommand(cfg *config.Config) *cli.Command { Name: "storage-frontend", Usage: "start storage frontend", Category: "extensions", - //Flags: flagset.FrontendWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagegateway.go b/ocis/pkg/command/storagegateway.go index fb96d116d5a..51f723a61d0 100644 --- a/ocis/pkg/command/storagegateway.go +++ b/ocis/pkg/command/storagegateway.go @@ -13,7 +13,14 @@ func StorageGatewayCommand(cfg *config.Config) *cli.Command { Name: "storage-gateway", Usage: "start storage gateway", Category: "extensions", - //Flags: flagset.GatewayWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagegroupprovider.go b/ocis/pkg/command/storagegroupprovider.go index a3703ac795e..e92dadba22e 100644 --- a/ocis/pkg/command/storagegroupprovider.go +++ b/ocis/pkg/command/storagegroupprovider.go @@ -13,7 +13,14 @@ func StorageGroupProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-groupprovider", Usage: "start storage groupprovider service", Category: "extensions", - //Flags: flagset.GroupsWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagemetadata.go b/ocis/pkg/command/storagemetadata.go index ef3d4d205d4..de8edfd4304 100644 --- a/ocis/pkg/command/storagemetadata.go +++ b/ocis/pkg/command/storagemetadata.go @@ -13,6 +13,14 @@ func StorageMetadataCommand(cfg *config.Config) *cli.Command { Name: "storage-metadata", Usage: "start storage and data service for metadata", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagepubliclink.go b/ocis/pkg/command/storagepubliclink.go index 516bc6c72d0..529ece013d6 100644 --- a/ocis/pkg/command/storagepubliclink.go +++ b/ocis/pkg/command/storagepubliclink.go @@ -13,7 +13,14 @@ func StoragePublicLinkCommand(cfg *config.Config) *cli.Command { Name: "storage-public-link", Usage: "start storage public link storage", Category: "extensions", - //Flags: flagset.StoragePublicLink(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageshares.go b/ocis/pkg/command/storageshares.go index e906cb20e0e..b68c00d6bf0 100644 --- a/ocis/pkg/command/storageshares.go +++ b/ocis/pkg/command/storageshares.go @@ -13,6 +13,14 @@ func StorageSharesCommand(cfg *config.Config) *cli.Command { Name: "storage-shares", Usage: "start storage and data provider for shares jail", Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storagesharing.go b/ocis/pkg/command/storagesharing.go index 4a70baa80a3..43f6a1c9c97 100644 --- a/ocis/pkg/command/storagesharing.go +++ b/ocis/pkg/command/storagesharing.go @@ -13,7 +13,14 @@ func StorageSharingCommand(cfg *config.Config) *cli.Command { Name: "storage-sharing", Usage: "start storage sharing service", Category: "extensions", - //Flags: flagset.SharingWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageuserprovider.go b/ocis/pkg/command/storageuserprovider.go index 896d0572069..951822a46df 100644 --- a/ocis/pkg/command/storageuserprovider.go +++ b/ocis/pkg/command/storageuserprovider.go @@ -13,7 +13,14 @@ func StorageUserProviderCommand(cfg *config.Config) *cli.Command { Name: "storage-userprovider", Usage: "start storage userprovider service", Category: "extensions", - //Flags: flagset.UsersWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/storageusers.go b/ocis/pkg/command/storageusers.go index 0c2a62c77c1..5cec411d12c 100644 --- a/ocis/pkg/command/storageusers.go +++ b/ocis/pkg/command/storageusers.go @@ -13,7 +13,14 @@ func StorageUsersCommand(cfg *config.Config) *cli.Command { Name: "storage-users", Usage: "start storage and data provider for /users mount", Category: "extensions", - //Flags: flagset.StorageUsersWithConfig(cfg.Storage), + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return ParseStorageCommon(ctx, cfg) }, diff --git a/ocis/pkg/command/store.go b/ocis/pkg/command/store.go index e37d5ab79f1..8843000bb78 100644 --- a/ocis/pkg/command/store.go +++ b/ocis/pkg/command/store.go @@ -15,6 +15,14 @@ func StoreCommand(cfg *config.Config) *cli.Command { Name: cfg.Store.Service.Name, Usage: subcommandDescription(cfg.Store.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/thumbnails.go b/ocis/pkg/command/thumbnails.go index 8409c98dc07..3507520ce8d 100644 --- a/ocis/pkg/command/thumbnails.go +++ b/ocis/pkg/command/thumbnails.go @@ -14,6 +14,14 @@ func ThumbnailsCommand(cfg *config.Config) *cli.Command { Name: cfg.Thumbnails.Service.Name, Usage: subcommandDescription(cfg.Thumbnails.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/web.go b/ocis/pkg/command/web.go index 0b3ec822e24..2e8025c15b2 100644 --- a/ocis/pkg/command/web.go +++ b/ocis/pkg/command/web.go @@ -14,6 +14,14 @@ func WebCommand(cfg *config.Config) *cli.Command { Name: cfg.Web.Service.Name, Usage: subcommandDescription(cfg.Web.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) }, diff --git a/ocis/pkg/command/webdav.go b/ocis/pkg/command/webdav.go index 7add32497fa..f94e19140e5 100644 --- a/ocis/pkg/command/webdav.go +++ b/ocis/pkg/command/webdav.go @@ -15,6 +15,14 @@ func WebDAVCommand(cfg *config.Config) *cli.Command { Name: cfg.WebDAV.Service.Name, Usage: subcommandDescription(cfg.WebDAV.Service.Name), Category: "extensions", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "ocis-config-file", + Value: cfg.ConfigFile, + Usage: "oCIS config file to be loaded by the runtime and extensions", + Destination: &cfg.ConfigFile, + }, + }, Before: func(ctx *cli.Context) error { return parser.ParseConfig(cfg) },