mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-02 02:11:18 -06:00
* refactor middleware options Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use ocmemstore micro store implementaiton for token cache Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * refactor ocis store options, support redis sentinel Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * align cache configuration Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * database and tabe are used to build prefixes for inmemory stores Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add global persistent store options to userlog config Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * log cache errors but continue Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * drup unnecessary type conversion Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * Better description for the default userinfo ttl Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use global cache options for even more caches Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * don't log userinfo cache misses Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * default to stock memory store Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use correct mem store typo string Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * split cache options, doc cleanup Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * mint and write userinfo to cache async Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * use hashed token as key Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * go mod tidy Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update docs Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update cache store naming Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * bring back depreceted ocis-pkg/store package for backwards compatability Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * update changelog Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * Apply suggestions from code review Co-authored-by: kobergj <jkoberg@owncloud.com> * revert ocis-pkg/cache to store rename Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> * add waiting for each step 50 milliseconds * starlack check --------- Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de> Co-authored-by: kobergj <jkoberg@owncloud.com> Co-authored-by: Viktor Scharf <scharf.vi@gmail.com>
137 lines
3.3 KiB
Go
137 lines
3.3 KiB
Go
package parser
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/config"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/structs"
|
|
)
|
|
|
|
// ParseConfig loads the ocis configuration and
|
|
// copies applicable parts into the commons part, from
|
|
// where the services can copy it into their own config
|
|
func ParseConfig(cfg *config.Config, skipValidate bool) error {
|
|
_, err := config.BindSourcesToStructs("ocis", cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
EnsureDefaults(cfg)
|
|
|
|
// 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"
|
|
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
|
|
return err
|
|
}
|
|
}
|
|
|
|
EnsureCommons(cfg)
|
|
|
|
if skipValidate {
|
|
return nil
|
|
}
|
|
|
|
return Validate(cfg)
|
|
}
|
|
|
|
// EnsureDefaults ensures that all pointers in the
|
|
// oCIS config (not the services configs) are initialized
|
|
func EnsureDefaults(cfg *config.Config) {
|
|
if cfg.Tracing == nil {
|
|
cfg.Tracing = &shared.Tracing{}
|
|
}
|
|
if cfg.Log == nil {
|
|
cfg.Log = &shared.Log{}
|
|
}
|
|
if cfg.TokenManager == nil {
|
|
cfg.TokenManager = &shared.TokenManager{}
|
|
}
|
|
if cfg.Cache == nil {
|
|
cfg.Cache = &shared.Cache{}
|
|
}
|
|
if cfg.GRPCClientTLS == nil {
|
|
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
|
}
|
|
if cfg.GRPCServiceTLS == nil {
|
|
cfg.GRPCServiceTLS = &shared.GRPCServiceTLS{}
|
|
}
|
|
|
|
}
|
|
|
|
// EnsureCommons copies applicable parts of the oCIS config into the commons part
|
|
func EnsureCommons(cfg *config.Config) {
|
|
// ensure the commons part is initialized
|
|
if cfg.Commons == nil {
|
|
cfg.Commons = &shared.Commons{}
|
|
}
|
|
|
|
cfg.Commons.Log = structs.CopyOrZeroValue(cfg.Log)
|
|
cfg.Commons.Tracing = structs.CopyOrZeroValue(cfg.Tracing)
|
|
cfg.Commons.Cache = structs.CopyOrZeroValue(cfg.Cache)
|
|
|
|
if cfg.GRPCClientTLS != nil {
|
|
cfg.Commons.GRPCClientTLS = cfg.GRPCClientTLS
|
|
}
|
|
|
|
if cfg.GRPCServiceTLS != nil {
|
|
cfg.Commons.GRPCServiceTLS = cfg.GRPCServiceTLS
|
|
}
|
|
|
|
cfg.Commons.HTTPServiceTLS = cfg.HTTPServiceTLS
|
|
|
|
cfg.Commons.TokenManager = structs.CopyOrZeroValue(cfg.TokenManager)
|
|
|
|
// copy machine auth api key to the commons part if set
|
|
if cfg.MachineAuthAPIKey != "" {
|
|
cfg.Commons.MachineAuthAPIKey = cfg.MachineAuthAPIKey
|
|
}
|
|
|
|
if cfg.SystemUserAPIKey != "" {
|
|
cfg.Commons.SystemUserAPIKey = cfg.SystemUserAPIKey
|
|
}
|
|
|
|
// copy transfer secret to the commons part if set
|
|
if cfg.TransferSecret != "" {
|
|
cfg.Commons.TransferSecret = cfg.TransferSecret
|
|
}
|
|
|
|
// copy metadata user id to the commons part if set
|
|
if cfg.SystemUserID != "" {
|
|
cfg.Commons.SystemUserID = cfg.SystemUserID
|
|
}
|
|
|
|
// copy admin user id to the commons part if set
|
|
if cfg.AdminUserID != "" {
|
|
cfg.Commons.AdminUserID = cfg.AdminUserID
|
|
}
|
|
|
|
if cfg.OcisURL != "" {
|
|
cfg.Commons.OcisURL = cfg.OcisURL
|
|
}
|
|
}
|
|
|
|
// Validate checks that all required configs are set. If a required config value
|
|
// is missing an error will be returned.
|
|
func Validate(cfg *config.Config) error {
|
|
if cfg.TokenManager.JWTSecret == "" {
|
|
return shared.MissingJWTTokenError("ocis")
|
|
}
|
|
|
|
if cfg.TransferSecret == "" {
|
|
return shared.MissingRevaTransferSecretError("ocis")
|
|
}
|
|
|
|
if cfg.MachineAuthAPIKey == "" {
|
|
return shared.MissingMachineAuthApiKeyError("ocis")
|
|
}
|
|
|
|
if cfg.SystemUserID == "" {
|
|
return shared.MissingSystemUserID("ocis")
|
|
}
|
|
|
|
return nil
|
|
}
|