remove auth basic command to improve config code

This commit is contained in:
David Christofas
2022-04-19 15:07:11 +02:00
parent 634d557279
commit 57e4e70888
14 changed files with 505 additions and 190 deletions

View File

@@ -0,0 +1,101 @@
package config
import "github.com/owncloud/ocis/ocis-pkg/shared"
type Config struct {
*shared.Commons `yaml:"-"`
Tracing *TracingConfig `yaml:"tracing"`
Logging *LoggingConfig `yaml:"log"`
Service ServiceConfig
DebugService DebugServiceConfig `yaml:"debug"`
Supervised bool
}
type TracingConfig struct {
Enabled bool
Endpoint string
Collector string
ServiceName string
Type string
}
type LoggingConfig struct {
Level string
Pretty bool
Color bool
File string
}
type ServiceConfig struct {
JWTSecret string
GatewayEndpoint string
SkipUserGroupsInToken bool
Network string // TODO: name transport or protocol?
Address string
AuthManager string
AuthManagers AuthManagers
}
type DebugServiceConfig struct {
Address string
Pprof bool
Zpages bool
Token string
}
type AuthManagers struct {
JSON JSONManager
LDAP LDAPManager
OwnCloudSQL OwnCloudSQLManager
}
type JSONManager struct {
Users string // TODO is there a better name?
}
type LDAPManager struct {
URI string
CACert string
Insecure bool
BindDN string
BindPassword string
UserBaseDN string
GroupBaseDN string
UserFilter string
GroupFilter string
UserObjectClass string
GroupObjectClass string
LoginAttributes []string
IDP string // TODO what is this for?
GatewayEndpoint string // TODO do we need this here?
UserSchema LDAPUserSchema
GroupSchema LDAPGroupSchema
}
type LDAPUserSchema struct {
ID string
IDIsOctetString bool
Mail string
DisplayName string
Username string
}
type LDAPGroupSchema struct {
ID string
IDIsOctetString bool
Mail string
DisplayName string
Groupname string
Member string
}
type OwnCloudSQLManager struct {
DBUsername string
DBPassword string
DBHost string
DBPort int
DBName string
IDP string // TODO do we need this?
Nobody int64 // TODO what is this?
JoinUsername bool
JoinOwnCloudUUID bool
}

View File

@@ -0,0 +1,83 @@
package defaults
import (
"path/filepath"
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
)
func FullDefaultConfig() *config.Config {
cfg := DefaultConfig()
EnsureDefaults(cfg)
return cfg
}
func DefaultConfig() *config.Config {
return &config.Config{
Service: config.ServiceConfig{
Network: "tcp",
Address: "127.0.0.1:9146",
GatewayEndpoint: "127.0.0.1:9142",
JWTSecret: "Pive-Fumkiu4",
AuthManager: "ldap",
AuthManagers: config.AuthManagers{
LDAP: config.LDAPManager{
URI: "ldaps:localhost:9126",
CACert: filepath.Join(defaults.BaseDataPath(), "ldap", "ldap.crt"),
Insecure: false,
UserBaseDN: "dc=ocis,dc=test",
GroupBaseDN: "dc=ocis,dc=test",
LoginAttributes: []string{"cn", "mail"},
UserFilter: "",
GroupFilter: "",
UserObjectClass: "posixAccount",
GroupObjectClass: "posixGroup",
BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test",
BindPassword: "reva",
IDP: "https://localhost:9200",
UserSchema: config.LDAPUserSchema{
ID: "ownclouduuid",
Mail: "mail",
DisplayName: "displayname",
Username: "cn",
},
GroupSchema: config.LDAPGroupSchema{
ID: "cn",
Mail: "mail",
DisplayName: "cn",
Groupname: "cn",
Member: "cn",
},
},
},
},
}
}
func EnsureDefaults(cfg *config.Config) {
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
if cfg.Logging == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
cfg.Logging = &config.LoggingConfig{
Level: cfg.Commons.Log.Level,
Pretty: cfg.Commons.Log.Pretty,
Color: cfg.Commons.Log.Color,
File: cfg.Commons.Log.File,
}
} else if cfg.Logging == nil {
cfg.Logging = &config.LoggingConfig{}
}
// provide with defaults for shared tracing, since we need a valid destination address for BindEnv.
if cfg.Tracing == nil && cfg.Commons != nil && cfg.Commons.Tracing != nil {
cfg.Tracing = &config.TracingConfig{
Enabled: cfg.Commons.Tracing.Enabled,
Type: cfg.Commons.Tracing.Type,
Endpoint: cfg.Commons.Tracing.Endpoint,
Collector: cfg.Commons.Tracing.Collector,
}
} else if cfg.Tracing == nil {
cfg.Tracing = &config.TracingConfig{}
}
}