mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-08 21:30:07 -06:00
move config parsing in separate package for each service
This commit is contained in:
@@ -18,11 +18,12 @@ type Config struct {
|
||||
|
||||
HTTP HTTP `ocisConfig:"http"`
|
||||
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
|
||||
Policies []Policy `ocisConfig:"policies"`
|
||||
OIDC OIDC `ocisConfig:"oidc"`
|
||||
TokenManager TokenManager `ocisConfig:"token_manager"`
|
||||
PolicySelector *PolicySelector `ocisConfig:"policy_selector"`
|
||||
Reva Reva `ocisConfig:"reva"`
|
||||
PreSignedURL PreSignedURL `ocisConfig:"pre_signed_url"`
|
||||
AccountBackend string `ocisConfig:"account_backend" env:"PROXY_ACCOUNT_BACKEND_TYPE"`
|
||||
UserOIDCClaim string `ocisConfig:"user_oidc_claim" env:"PROXY_USER_OIDC_CLAIM"`
|
||||
@@ -31,6 +32,7 @@ type Config struct {
|
||||
AutoprovisionAccounts bool `ocisConfig:"auto_provision_accounts" env:"PROXY_AUTOPROVISION_ACCOUNTS"`
|
||||
EnableBasicAuth bool `ocisConfig:"enable_basic_auth" env:"PROXY_ENABLE_BASIC_AUTH"`
|
||||
InsecureBackends bool `ocisConfig:"insecure_backends" env:"PROXY_INSECURE_BACKENDS"`
|
||||
AuthMiddleware AuthMiddleware `ocisConfig:"auth_middleware"`
|
||||
|
||||
Context context.Context
|
||||
}
|
||||
@@ -68,21 +70,9 @@ var (
|
||||
RouteTypes = []RouteType{QueryRoute, RegexRoute, PrefixRoute}
|
||||
)
|
||||
|
||||
// TODO: use reva config here
|
||||
// Reva defines all available REVA configuration.
|
||||
type Reva struct {
|
||||
Address string `ocisConfig:"address" env:"REVA_GATEWAY"`
|
||||
Middleware Middleware `ocisConfig:"middleware"`
|
||||
}
|
||||
|
||||
// Middleware configures proxy middlewares.
|
||||
type Middleware struct {
|
||||
Auth Auth `ocisConfig:"middleware"`
|
||||
}
|
||||
|
||||
// Auth configures proxy http auth middleware.
|
||||
type Auth struct {
|
||||
CredentialsByUserAgent map[string]string `ocisConfig:""`
|
||||
// AuthMiddleware configures the proxy http auth middleware.
|
||||
type AuthMiddleware struct {
|
||||
CredentialsByUserAgent map[string]string `ocisConfig:"credentials_by_user_agent"`
|
||||
}
|
||||
|
||||
// OIDC is the config for the OpenID-Connect middleware. If set the proxy will try to authenticate every request
|
||||
|
||||
51
proxy/pkg/config/parser/parse.go
Normal file
51
proxy/pkg/config/parser/parse.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/proxy/pkg/config"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
|
||||
)
|
||||
|
||||
// ParseConfig loads accounts configuration from known paths.
|
||||
func ParseConfig(cfg *config.Config) error {
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &config.Log{}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
// sanitize config
|
||||
|
||||
if cfg.Policies == nil {
|
||||
cfg.Policies = config.DefaultPolicies()
|
||||
}
|
||||
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
6
proxy/pkg/config/reva.go
Normal file
6
proxy/pkg/config/reva.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
// Reva defines all available REVA configuration.
|
||||
type Reva struct {
|
||||
Address string `ocisConfig:"address" env:"REVA_GATEWAY"`
|
||||
}
|
||||
Reference in New Issue
Block a user