2022-01-03 15:21:56 +01:00
|
|
|
package parser
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
|
2022-05-04 14:49:59 +02:00
|
|
|
ociscfg "github.com/owncloud/ocis/v2/ocis-pkg/config"
|
2023-11-24 08:35:10 +01:00
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
2022-06-20 16:49:06 +02:00
|
|
|
"github.com/owncloud/ocis/v2/services/search/pkg/config"
|
|
|
|
|
"github.com/owncloud/ocis/v2/services/search/pkg/config/defaults"
|
2022-01-03 15:21:56 +01:00
|
|
|
|
2022-05-04 14:49:59 +02:00
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/config/envdecode"
|
2022-01-03 15:21:56 +01:00
|
|
|
)
|
|
|
|
|
|
2022-05-02 14:19:08 +00:00
|
|
|
// ParseConfig loads configuration from known paths.
|
2022-01-03 15:21:56 +01:00
|
|
|
func ParseConfig(cfg *config.Config) error {
|
2024-04-30 18:18:31 +02:00
|
|
|
err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
2022-01-03 15:21:56 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 13:04:48 +01:00
|
|
|
defaults.EnsureDefaults(cfg)
|
2022-01-03 15:21:56 +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-08 17:35:55 +01:00
|
|
|
defaults.Sanitize(cfg)
|
2022-01-03 15:21:56 +01:00
|
|
|
|
2022-05-02 14:19:08 +00:00
|
|
|
return Validate(cfg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Validate(cfg *config.Config) error {
|
2023-11-24 08:35:10 +01:00
|
|
|
if cfg.TokenManager.JWTSecret == "" {
|
|
|
|
|
return shared.MissingJWTTokenError(cfg.Service.Name)
|
|
|
|
|
}
|
2024-02-29 11:19:01 +01:00
|
|
|
|
|
|
|
|
if cfg.ServiceAccount.ServiceAccountID == "" {
|
|
|
|
|
return shared.MissingServiceAccountID(cfg.Service.Name)
|
|
|
|
|
}
|
|
|
|
|
if cfg.ServiceAccount.ServiceAccountSecret == "" {
|
|
|
|
|
return shared.MissingServiceAccountSecret(cfg.Service.Name)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 15:21:56 +01:00
|
|
|
return nil
|
|
|
|
|
}
|