mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-19 14:57:59 -04:00
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package parser
|
|
|
|
import (
|
|
"errors"
|
|
"log"
|
|
|
|
"github.com/owncloud/ocis/ocis-pkg/config"
|
|
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
|
|
"github.com/owncloud/ocis/ocis-pkg/shared"
|
|
)
|
|
|
|
// ParseConfig loads ocis configuration.
|
|
func ParseConfig(cfg *config.Config) error {
|
|
_, err := config.BindSourcesToStructs("ocis", cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if cfg.Commons == nil {
|
|
cfg.Commons = &shared.Commons{}
|
|
}
|
|
|
|
if cfg.Log != nil {
|
|
cfg.Commons.Log = &shared.Log{
|
|
Level: cfg.Log.Level,
|
|
Pretty: cfg.Log.Pretty,
|
|
Color: cfg.Log.Color,
|
|
File: cfg.File,
|
|
}
|
|
} else {
|
|
cfg.Commons.Log = &shared.Log{}
|
|
cfg.Log = &shared.Log{}
|
|
}
|
|
|
|
if cfg.Tracing != nil {
|
|
cfg.Commons.Tracing = &shared.Tracing{
|
|
Enabled: cfg.Tracing.Enabled,
|
|
Type: cfg.Tracing.Type,
|
|
Endpoint: cfg.Tracing.Endpoint,
|
|
Collector: cfg.Tracing.Collector,
|
|
}
|
|
} else {
|
|
cfg.Commons.Tracing = &shared.Tracing{}
|
|
cfg.Tracing = &shared.Tracing{}
|
|
}
|
|
|
|
if cfg.TokenManager != nil {
|
|
cfg.Commons.TokenManager = cfg.TokenManager
|
|
} else {
|
|
cfg.Commons.TokenManager = &shared.TokenManager{}
|
|
cfg.TokenManager = cfg.Commons.TokenManager
|
|
}
|
|
|
|
if cfg.MachineAuthAPIKey != "" {
|
|
cfg.Commons.MachineAuthAPIKey = cfg.MachineAuthAPIKey
|
|
} else {
|
|
log.Fatalf("machine auth api key is not set up properly, bailing out (ocis)")
|
|
}
|
|
|
|
if cfg.TransferSecret != "" {
|
|
cfg.Commons.TransferSecret = cfg.TransferSecret
|
|
} else {
|
|
log.Fatalf("reva transfer secret not properly set, bailing out (ocis)")
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|