mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-25 06:58:59 -06:00
normalize glauth
This commit is contained in:
@@ -19,21 +19,16 @@ func Execute(cfg *config.Config) error {
|
||||
Version: version.String,
|
||||
Usage: "Serve GLAuth API for oCIS",
|
||||
Compiled: version.Compiled(),
|
||||
|
||||
Authors: []*cli.Author{
|
||||
{
|
||||
Name: "ownCloud GmbH",
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
//Flags: flagset.RootWithConfig(cfg),
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Version = version.String
|
||||
return nil
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
@@ -73,12 +68,8 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
|
||||
if err = cfg.UnmapEnv(conf); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
bindings := config.StructMappings(cfg)
|
||||
return ociscfg.BindEnv(conf, bindings)
|
||||
}
|
||||
|
||||
// SutureService allows for the glauth command to be embedded and supervised by a suture supervisor tree.
|
||||
@@ -88,11 +79,7 @@ type SutureService struct {
|
||||
|
||||
// NewSutureService creates a new glauth.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
inheritLogging(cfg)
|
||||
if cfg.Mode == 0 {
|
||||
cfg.GLAuth.Supervised = true
|
||||
}
|
||||
cfg.GLAuth.Log.File = cfg.Log.File
|
||||
cfg.GLAuth.Log = cfg.Log
|
||||
return SutureService{
|
||||
cfg: cfg.GLAuth,
|
||||
}
|
||||
@@ -106,13 +93,3 @@ func (s SutureService) Serve(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// inheritLogging is a poor man's global logging state tip-toeing around circular dependencies. It sets the logging
|
||||
// of the service to whatever is in the higher config (in this case coming from ocis.yaml) and sets them as defaults,
|
||||
// being overwritten when the extension parses its config file / env variables.
|
||||
func inheritLogging(cfg *ociscfg.Config) {
|
||||
cfg.GLAuth.Log.File = cfg.Log.File
|
||||
cfg.GLAuth.Log.Color = cfg.Log.Color
|
||||
cfg.GLAuth.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.GLAuth.Log.Level = cfg.Log.Level
|
||||
}
|
||||
|
||||
@@ -6,18 +6,12 @@ import (
|
||||
"path"
|
||||
"reflect"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
gofig "github.com/gookit/config/v2"
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
|
||||
)
|
||||
|
||||
// Log defines the available logging configuration.
|
||||
type Log struct {
|
||||
Level string `mapstructure:"level"`
|
||||
Pretty bool `mapstructure:"pretty"`
|
||||
Color bool `mapstructure:"color"`
|
||||
File string `mapstructure:"file"`
|
||||
}
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `mapstructure:"addr"`
|
||||
@@ -70,17 +64,17 @@ type Backend struct {
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
type Config struct {
|
||||
File string `mapstructure:"file"`
|
||||
Log Log `mapstructure:"log"`
|
||||
Debug Debug `mapstructure:"debug"`
|
||||
HTTP HTTP `mapstructure:"http"`
|
||||
Tracing Tracing `mapstructure:"tracing"`
|
||||
Ldap Ldap `mapstructure:"ldap"`
|
||||
Ldaps Ldaps `mapstructure:"ldaps"`
|
||||
Backend Backend `mapstructure:"backend"`
|
||||
Fallback Backend `mapstructure:"fallback"`
|
||||
Version string `mapstructure:"version"`
|
||||
RoleBundleUUID string `mapstructure:"role_bundle_uuid"`
|
||||
File string `mapstructure:"file"`
|
||||
Log shared.Log `mapstructure:"log"`
|
||||
Debug Debug `mapstructure:"debug"`
|
||||
HTTP HTTP `mapstructure:"http"`
|
||||
Tracing Tracing `mapstructure:"tracing"`
|
||||
Ldap Ldap `mapstructure:"ldap"`
|
||||
Ldaps Ldaps `mapstructure:"ldaps"`
|
||||
Backend Backend `mapstructure:"backend"`
|
||||
Fallback Backend `mapstructure:"fallback"`
|
||||
Version string `mapstructure:"version"`
|
||||
RoleBundleUUID string `mapstructure:"role_bundle_uuid"`
|
||||
|
||||
Context context.Context
|
||||
Supervised bool
|
||||
@@ -93,7 +87,7 @@ func New() *Config {
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Log: Log{},
|
||||
Log: shared.Log{},
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9129",
|
||||
},
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
type mapping struct {
|
||||
EnvVars []string // name of the EnvVars var.
|
||||
Destination interface{} // memory address of the original config value to modify.
|
||||
}
|
||||
|
||||
// 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.
|
||||
func StructMappings(cfg *Config) []shared.EnvBinding {
|
||||
return structMappings(cfg)
|
||||
}
|
||||
|
||||
// structMappings binds a set of environment variables to a destination on cfg.
|
||||
func structMappings(cfg *Config) []mapping {
|
||||
return []mapping{
|
||||
func structMappings(cfg *Config) []shared.EnvBinding {
|
||||
return []shared.EnvBinding{
|
||||
{
|
||||
EnvVars: []string{"GLAUTH_LOG_LEVEL", "OCIS_LOG_LEVEL"},
|
||||
Destination: &cfg.Log.Level,
|
||||
@@ -19,19 +19,16 @@ func Execute(cfg *config.Config) error {
|
||||
Version: version.String,
|
||||
Usage: "proxy for oCIS",
|
||||
Compiled: version.Compiled(),
|
||||
|
||||
Authors: []*cli.Author{
|
||||
{
|
||||
Name: "ownCloud GmbH",
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
cfg.Service.Version = version.String
|
||||
return nil
|
||||
},
|
||||
|
||||
Commands: []*cli.Command{
|
||||
Server(cfg),
|
||||
Health(cfg),
|
||||
|
||||
Reference in New Issue
Block a user