remove config file related code

This commit is contained in:
Willy Kloucek
2022-03-02 15:18:43 +01:00
parent 1db1c7b678
commit aeeff60011
2 changed files with 8 additions and 48 deletions
-23
View File
@@ -1,23 +0,0 @@
package main
import (
"fmt"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/config/parser"
"gopkg.in/yaml.v2"
)
func main() {
cfg := config.DefaultConfig()
parser.EnsureDefaults(cfg)
parser.Sanitize(cfg)
b, err := yaml.Marshal(cfg)
if err != nil {
return
}
fmt.Println(string(b))
}
+8 -25
View File
@@ -17,28 +17,6 @@ func ParseConfig(cfg *config.Config) error {
return err
}
err = EnsureDefaults(cfg)
if err != nil {
return err
}
// 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
}
}
err = Sanitize(cfg)
if err != nil {
return err
}
return nil
}
func EnsureDefaults(cfg *config.Config) error {
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Log = &config.Log{
@@ -62,14 +40,19 @@ func EnsureDefaults(cfg *config.Config) error {
cfg.Tracing = &config.Tracing{}
}
return nil
}
// 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
}
}
func Sanitize(cfg *config.Config) error {
// sanitize config
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
cfg.Repo.Backend = strings.ToLower(cfg.Repo.Backend)
return nil
}