mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-21 03:25:24 -04:00
* add the ability to disable the gRPC API handler (POLICIES_GRPC_DISABLED) * add the ability to disable the Events API handler (POLICIES_EVENTS_DISABLED) * add metrics * add support for specifying rego files via the environment varirable POLICIES_ENGINE_FILES * for file paths specified in yaml or in POLICIES_ENGINE_FILES, support 'config:' and 'data:' path prefixes * fix typos in the documentation, and try to make it more clear * add metrics to the documentation * add a section for testing in the documentation * introduces a new top-level package pkg/metrics/ with utilities for metrics that are backported from the groupware branch, with unit tests
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package parser
|
|
|
|
import (
|
|
"errors"
|
|
|
|
occfg "github.com/opencloud-eu/opencloud/pkg/config"
|
|
"github.com/opencloud-eu/opencloud/services/policies/pkg/config"
|
|
"github.com/opencloud-eu/opencloud/services/policies/pkg/config/defaults"
|
|
|
|
"github.com/opencloud-eu/opencloud/pkg/config/envdecode"
|
|
)
|
|
|
|
// ParseConfig loads configuration from known paths.
|
|
func ParseConfig(cfg *config.Config) error {
|
|
err := occfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defaults.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
|
|
}
|
|
}
|
|
|
|
defaults.Sanitize(cfg)
|
|
|
|
return Validate(cfg)
|
|
}
|
|
|
|
func Validate(cfg *config.Config) error {
|
|
if cfg.GRPC.Disabled && cfg.Events.Disabled {
|
|
// might be debatable, but this situation should be treated as an error,
|
|
// as the process wouldn't be able to serve either API and would thus be
|
|
// completely useless -- in that case, just don't start this service
|
|
// in the first place (especially since it's optional)
|
|
return errors.New("both gRPC and events APIs are disabled by configuration; at least one must be enabled")
|
|
}
|
|
return nil
|
|
}
|