mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-25 06:58:59 -06:00
add idp common options
This commit is contained in:
@@ -70,8 +70,20 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
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 = &shared.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 = &shared.Log{}
|
||||
}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
conf.LoadOSEnv(config.GetEnv(cfg), false)
|
||||
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
@@ -84,9 +96,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new idp.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
if (cfg.IDP.Log == shared.Log{}) {
|
||||
cfg.IDP.Log = cfg.Log
|
||||
}
|
||||
cfg.IDP.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.IDP,
|
||||
}
|
||||
|
||||
@@ -4,15 +4,12 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
gofig "github.com/gookit/config/v2"
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/idp/pkg/config"
|
||||
"github.com/owncloud/ocis/idp/pkg/metrics"
|
||||
"github.com/owncloud/ocis/idp/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/idp/pkg/server/http"
|
||||
"github.com/owncloud/ocis/idp/pkg/tracing"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@@ -23,9 +20,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
Name: "server",
|
||||
Usage: "Start integrated server",
|
||||
Before: func(ctx *cli.Context) error {
|
||||
// remember shared logging info to prevent empty overwrites
|
||||
inLog := cfg.Log
|
||||
|
||||
if cfg.HTTP.Root != "/" {
|
||||
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
|
||||
}
|
||||
@@ -46,19 +40,6 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) {
|
||||
// set the default to the parent config
|
||||
cfg.Log = inLog
|
||||
|
||||
// and parse the environment
|
||||
conf := &gofig.Config{}
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
if err := ociscfg.BindEnv(conf, bindings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
|
||||
@@ -98,15 +98,17 @@ type Settings struct {
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
File string `mapstructure:"file"`
|
||||
Log shared.Log `mapstructure:"log"`
|
||||
Debug Debug `mapstructure:"debug"`
|
||||
HTTP HTTP `mapstructure:"http"`
|
||||
Tracing Tracing `mapstructure:"tracing"`
|
||||
Asset Asset `mapstructure:"asset"`
|
||||
IDP Settings `mapstructure:"idp"`
|
||||
Ldap Ldap `mapstructure:"ldap"`
|
||||
Service Service `mapstructure:"service"`
|
||||
*shared.Commons
|
||||
|
||||
File string `mapstructure:"file"`
|
||||
Log *shared.Log `mapstructure:"log"`
|
||||
Debug Debug `mapstructure:"debug"`
|
||||
HTTP HTTP `mapstructure:"http"`
|
||||
Tracing Tracing `mapstructure:"tracing"`
|
||||
Asset Asset `mapstructure:"asset"`
|
||||
IDP Settings `mapstructure:"idp"`
|
||||
Ldap Ldap `mapstructure:"ldap"`
|
||||
Service Service `mapstructure:"service"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
@@ -119,7 +121,6 @@ func New() *Config {
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Log: shared.Log{},
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9134",
|
||||
},
|
||||
@@ -189,14 +190,3 @@ func DefaultConfig() *Config {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list
|
||||
// with all the environment variables an extension supports.
|
||||
func GetEnv() []string {
|
||||
var r = make([]string, len(structMappings(DefaultConfig())))
|
||||
for i := range structMappings(DefaultConfig()) {
|
||||
r = append(r, structMappings(DefaultConfig())[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -2,6 +2,17 @@ package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
// GetEnv fetches a list of known env variables for this extension. It is to be used by gookit, as it provides a list
|
||||
// with all the environment variables an extension supports.
|
||||
func GetEnv(cfg *Config) []string {
|
||||
var r = make([]string, len(structMappings(cfg)))
|
||||
for i := range structMappings(cfg) {
|
||||
r = append(r, structMappings(cfg)[i].EnvVars...)
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// StructMappings binds a set of environment variables to a destination on cfg. Iterating over this set and editing the
|
||||
// Destination value of a binding will alter the original value, as it is a pointer to its memory address. This lets
|
||||
// us propagate changes easier.
|
||||
|
||||
Reference in New Issue
Block a user