Files
opencloud/ocis-pkg/config/parser/parse.go
Christian Richter 58a24e620e Move reva transfer secret to shared.Commons
Signed-off-by: Christian Richter <crichter@owncloud.com>
2022-04-26 14:10:03 +02:00

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
}