Files

38 lines
917 B
Go
Raw Permalink Normal View History

2022-03-08 11:25:26 +01:00
package parser
import (
"errors"
2022-05-04 14:49:59 +02:00
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
2022-06-20 16:49:06 +02:00
"github.com/owncloud/ocis/v2/services/audit/pkg/config"
"github.com/owncloud/ocis/v2/services/audit/pkg/config/defaults"
2022-03-08 11:25:26 +01:00
2022-05-04 14:49:59 +02:00
"github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode"
2022-03-08 11:25:26 +01:00
)
2022-04-29 20:21:14 +00:00
// ParseConfig loads configuration from known paths.
2022-03-08 11:25:26 +01:00
func ParseConfig(cfg *config.Config) error {
err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
2022-03-08 11:25:26 +01:00
if err != nil {
return err
}
2022-03-14 14:21:37 +01:00
defaults.EnsureDefaults(cfg)
2022-03-08 11:25:26 +01:00
// 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
}
}
2022-03-14 14:21:37 +01:00
defaults.Sanitize(cfg)
return Validate(cfg)
}
2022-08-11 15:19:49 +02:00
// Validate validates the configuration
func Validate(cfg *config.Config) error {
2022-03-08 11:25:26 +01:00
return nil
}