mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-06 08:17:42 -05:00
ensure commands for all services
This commit is contained in:
14
extensions/auth-basic/cmd/auth-basic/main.go
Normal file
14
extensions/auth-basic/cmd/auth-basic/main.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/command"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config/defaults"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := command.Execute(defaults.DefaultConfig()); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cs3org/reva/v2/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/server/debug"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/ldap"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Command is the entrypoint for the auth-basic command.
|
||||
func AuthBasic(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "auth-basic",
|
||||
Usage: "start authprovider for basic auth",
|
||||
Before: func(ctx *cli.Context) error {
|
||||
err := parser.ParseConfig(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("%v", err)
|
||||
}
|
||||
return err
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logCfg := cfg.Logging
|
||||
logger := log.NewLogger(
|
||||
log.Level(logCfg.Level),
|
||||
log.File(logCfg.File),
|
||||
log.Pretty(logCfg.Pretty),
|
||||
log.Color(logCfg.Color),
|
||||
)
|
||||
tracing.Configure(cfg.Tracing.Enabled, cfg.Tracing.Type, logger)
|
||||
gr := run.Group{}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// pre-create folders
|
||||
if cfg.AuthProvider == "json" && cfg.AuthProviders.JSON.File != "" {
|
||||
if err := os.MkdirAll(filepath.Dir(cfg.AuthProviders.JSON.File), os.FileMode(0700)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
uuid := uuid.Must(uuid.NewV4())
|
||||
|
||||
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
||||
|
||||
rcfg := authBasicConfigFromStruct(c, cfg)
|
||||
logger.Debug().
|
||||
Str("server", "authbasic").
|
||||
Interface("reva-config", rcfg).
|
||||
Msg("config")
|
||||
|
||||
if cfg.AuthProvider == "ldap" {
|
||||
ldapCfg := cfg.AuthProviders.LDAP
|
||||
if err := ldap.WaitForCA(logger, ldapCfg.Insecure, ldapCfg.CACert); err != nil {
|
||||
logger.Error().Err(err).Msg("The configured LDAP CA cert does not exist")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
gr.Add(func() error {
|
||||
runtime.RunWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger))
|
||||
return nil
|
||||
}, func(_ error) {
|
||||
logger.Info().
|
||||
Str("server", c.Command.Name).
|
||||
Msg("Shutting down server")
|
||||
|
||||
cancel()
|
||||
})
|
||||
|
||||
debugServer, err := debug.Server(
|
||||
debug.Logger(logger),
|
||||
debug.Context(ctx),
|
||||
debug.Config(cfg),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||
return err
|
||||
}
|
||||
|
||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||
cancel()
|
||||
})
|
||||
|
||||
if !cfg.Supervised {
|
||||
sync.Trap(&gr, cancel)
|
||||
}
|
||||
|
||||
return gr.Run()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// authBasicConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||
func authBasicConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
|
||||
rcfg := map[string]interface{}{
|
||||
"core": map[string]interface{}{
|
||||
"tracing_enabled": cfg.Tracing.Enabled,
|
||||
"tracing_endpoint": cfg.Tracing.Endpoint,
|
||||
"tracing_collector": cfg.Tracing.Collector,
|
||||
"tracing_service_name": c.Command.Name,
|
||||
},
|
||||
"shared": map[string]interface{}{
|
||||
"jwt_secret": cfg.TokenManager.JWTSecret,
|
||||
"gatewaysvc": cfg.Reva.Address,
|
||||
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
|
||||
},
|
||||
"grpc": map[string]interface{}{
|
||||
"network": cfg.GRPC.Protocol,
|
||||
"address": cfg.GRPC.Addr,
|
||||
// TODO build services dynamically
|
||||
"services": map[string]interface{}{
|
||||
"authprovider": map[string]interface{}{
|
||||
"auth_manager": cfg.AuthProvider,
|
||||
"auth_managers": map[string]interface{}{
|
||||
"json": map[string]interface{}{
|
||||
"users": cfg.AuthProviders.JSON.File,
|
||||
},
|
||||
"ldap": ldapConfigFromString(cfg.AuthProviders.LDAP),
|
||||
"owncloudsql": map[string]interface{}{
|
||||
"dbusername": cfg.AuthProviders.OwnCloudSQL.DBUsername,
|
||||
"dbpassword": cfg.AuthProviders.OwnCloudSQL.DBPassword,
|
||||
"dbhost": cfg.AuthProviders.OwnCloudSQL.DBHost,
|
||||
"dbport": cfg.AuthProviders.OwnCloudSQL.DBPort,
|
||||
"dbname": cfg.AuthProviders.OwnCloudSQL.DBName,
|
||||
"idp": cfg.AuthProviders.OwnCloudSQL.IDP,
|
||||
"nobody": cfg.AuthProviders.OwnCloudSQL.Nobody,
|
||||
"join_username": cfg.AuthProviders.OwnCloudSQL.JoinUsername,
|
||||
"join_ownclouduuid": cfg.AuthProviders.OwnCloudSQL.JoinOwnCloudUUID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rcfg
|
||||
}
|
||||
|
||||
// AuthBasicSutureService allows for the storage-authbasic command to be embedded and supervised by a suture supervisor tree.
|
||||
type AuthBasicSutureService struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewAuthBasicSutureService creates a new store.AuthBasicSutureService
|
||||
func NewAuthBasic(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.AuthBasic.Commons = cfg.Commons
|
||||
return AuthBasicSutureService{
|
||||
cfg: cfg.AuthBasic,
|
||||
}
|
||||
}
|
||||
|
||||
func (s AuthBasicSutureService) Serve(ctx context.Context) error {
|
||||
f := &flag.FlagSet{}
|
||||
cmdFlags := AuthBasic(s.cfg).Flags
|
||||
for k := range cmdFlags {
|
||||
if err := cmdFlags[k].Apply(f); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
cliCtx := cli.NewContext(nil, f, nil)
|
||||
if AuthBasic(s.cfg).Before != nil {
|
||||
if err := AuthBasic(s.cfg).Before(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := AuthBasic(s.cfg).Action(cliCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ldapConfigFromString(cfg config.LDAPProvider) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"uri": cfg.URI,
|
||||
"cacert": cfg.CACert,
|
||||
"insecure": cfg.Insecure,
|
||||
"bind_username": cfg.BindDN,
|
||||
"bind_password": cfg.BindPassword,
|
||||
"user_base_dn": cfg.UserBaseDN,
|
||||
"group_base_dn": cfg.GroupBaseDN,
|
||||
"user_filter": cfg.UserFilter,
|
||||
"group_filter": cfg.GroupFilter,
|
||||
"user_scope": cfg.UserScope,
|
||||
"group_scope": cfg.GroupScope,
|
||||
"user_objectclass": cfg.UserObjectClass,
|
||||
"group_objectclass": cfg.GroupObjectClass,
|
||||
"login_attributes": cfg.LoginAttributes,
|
||||
"idp": cfg.IDP,
|
||||
"user_schema": map[string]interface{}{
|
||||
"id": cfg.UserSchema.ID,
|
||||
"idIsOctetString": cfg.UserSchema.IDIsOctetString,
|
||||
"mail": cfg.UserSchema.Mail,
|
||||
"displayName": cfg.UserSchema.DisplayName,
|
||||
"userName": cfg.UserSchema.Username,
|
||||
},
|
||||
"group_schema": map[string]interface{}{
|
||||
"id": cfg.GroupSchema.ID,
|
||||
"idIsOctetString": cfg.GroupSchema.IDIsOctetString,
|
||||
"mail": cfg.GroupSchema.Mail,
|
||||
"displayName": cfg.GroupSchema.DisplayName,
|
||||
"groupName": cfg.GroupSchema.Groupname,
|
||||
"member": cfg.GroupSchema.Member,
|
||||
},
|
||||
}
|
||||
}
|
||||
57
extensions/auth-basic/pkg/command/health.go
Normal file
57
extensions/auth-basic/pkg/command/health.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/logging"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Health is the entrypoint for the health command.
|
||||
func Health(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "health",
|
||||
Usage: "check health status",
|
||||
Category: "info",
|
||||
Before: func(c *cli.Context) error {
|
||||
err := parser.ParseConfig(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("%v", err)
|
||||
}
|
||||
return err
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
|
||||
resp, err := http.Get(
|
||||
fmt.Sprintf(
|
||||
"http://%s/healthz",
|
||||
cfg.Debug.Addr,
|
||||
),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Fatal().
|
||||
Err(err).
|
||||
Msg("Failed to request health check")
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
logger.Fatal().
|
||||
Int("code", resp.StatusCode).
|
||||
Msg("Health seems to be in bad state")
|
||||
}
|
||||
|
||||
logger.Debug().
|
||||
Int("code", resp.StatusCode).
|
||||
Msg("Health got a good state")
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
64
extensions/auth-basic/pkg/command/root.go
Normal file
64
extensions/auth-basic/pkg/command/root.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/clihelper"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/thejerf/suture/v4"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// GetCommands provides all commands for this service
|
||||
func GetCommands(cfg *config.Config) cli.Commands {
|
||||
return []*cli.Command{
|
||||
// start this service
|
||||
Server(cfg),
|
||||
|
||||
// interaction with this service
|
||||
|
||||
// infos about this service
|
||||
Health(cfg),
|
||||
Version(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
// Execute is the entry point for the ocis-auth-basic command.
|
||||
func Execute(cfg *config.Config) error {
|
||||
app := clihelper.DefaultApp(&cli.App{
|
||||
Name: "ocis-auth-basic",
|
||||
Usage: "Provide basic authentication for oCIS",
|
||||
Commands: GetCommands(cfg),
|
||||
})
|
||||
|
||||
cli.HelpFlag = &cli.BoolFlag{
|
||||
Name: "help,h",
|
||||
Usage: "Show the help",
|
||||
}
|
||||
|
||||
return app.Run(os.Args)
|
||||
}
|
||||
|
||||
// SutureService allows for the auth-basic command to be embedded and supervised by a suture supervisor tree.
|
||||
type SutureService struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewSutureService creates a new auth-basic.SutureService
|
||||
func NewSutureService(cfg *ociscfg.Config) suture.Service {
|
||||
cfg.AuthBasic.Commons = cfg.Commons
|
||||
return SutureService{
|
||||
cfg: cfg.AuthBasic,
|
||||
}
|
||||
}
|
||||
|
||||
func (s SutureService) Serve(ctx context.Context) error {
|
||||
s.cfg.Context = ctx
|
||||
if err := Execute(s.cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
120
extensions/auth-basic/pkg/command/server.go
Normal file
120
extensions/auth-basic/pkg/command/server.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/cs3org/reva/v2/cmd/revad/runtime"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/oklog/run"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config/parser"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/logging"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/revaconfig"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/server/debug"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/tracing"
|
||||
"github.com/owncloud/ocis/ocis-pkg/ldap"
|
||||
"github.com/owncloud/ocis/ocis-pkg/service/external"
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Server is the entry point for the server command.
|
||||
func Server(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "server",
|
||||
Usage: fmt.Sprintf("start %s extension without runtime (unsupervised mode)", cfg.Service.Name),
|
||||
Category: "server",
|
||||
Before: func(c *cli.Context) error {
|
||||
err := parser.ParseConfig(cfg)
|
||||
if err != nil {
|
||||
fmt.Printf("%v", err)
|
||||
}
|
||||
return err
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||
err := tracing.Configure(cfg, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gr := run.Group{}
|
||||
ctx, cancel := defineContext(cfg)
|
||||
|
||||
defer cancel()
|
||||
|
||||
pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid")
|
||||
|
||||
rcfg := revaconfig.AuthBasicConfigFromStruct(cfg)
|
||||
|
||||
// the reva runtime calls os.Exit in the case of a failure and there is no way for the oCIS
|
||||
// runtime to catch it and restart a reva service. Therefore we need to ensure the service has
|
||||
// everything it needs, before starting the service.
|
||||
// In this case: CA certificates
|
||||
if cfg.AuthProvider == "ldap" {
|
||||
ldapCfg := cfg.AuthProviders.LDAP
|
||||
if err := ldap.WaitForCA(logger, ldapCfg.Insecure, ldapCfg.CACert); err != nil {
|
||||
logger.Error().Err(err).Msg("The configured LDAP CA cert does not exist")
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
gr.Add(func() error {
|
||||
runtime.RunWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger))
|
||||
return nil
|
||||
}, func(_ error) {
|
||||
logger.Info().
|
||||
Str("server", cfg.Service.Name).
|
||||
Msg("Shutting down server")
|
||||
|
||||
cancel()
|
||||
})
|
||||
|
||||
debugServer, err := debug.Server(
|
||||
debug.Logger(logger),
|
||||
debug.Context(ctx),
|
||||
debug.Config(cfg),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server")
|
||||
return err
|
||||
}
|
||||
|
||||
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||
cancel()
|
||||
})
|
||||
|
||||
if !cfg.Supervised {
|
||||
sync.Trap(&gr, cancel)
|
||||
}
|
||||
|
||||
if err := external.RegisterGRPCEndpoint(
|
||||
ctx,
|
||||
cfg.GRPC.Namespace+"."+cfg.Service.Name,
|
||||
uuid.Must(uuid.NewV4()).String(),
|
||||
cfg.GRPC.Addr,
|
||||
version.String,
|
||||
logger,
|
||||
); err != nil {
|
||||
logger.Fatal().Err(err).Msg("failed to register the grpc endpoint")
|
||||
}
|
||||
|
||||
return gr.Run()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// defineContext sets the context for the extension. If there is a context configured it will create a new child from it,
|
||||
// if not, it will create a root context that can be cancelled.
|
||||
func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) {
|
||||
return func() (context.Context, context.CancelFunc) {
|
||||
if cfg.Context == nil {
|
||||
return context.WithCancel(context.Background())
|
||||
}
|
||||
return context.WithCancel(cfg.Context)
|
||||
}()
|
||||
}
|
||||
50
extensions/auth-basic/pkg/command/version.go
Normal file
50
extensions/auth-basic/pkg/command/version.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/registry"
|
||||
"github.com/owncloud/ocis/ocis-pkg/version"
|
||||
|
||||
tw "github.com/olekukonko/tablewriter"
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version prints the service versions of all running instances.
|
||||
func Version(cfg *config.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "version",
|
||||
Usage: "print the version of this binary and the running extension instances",
|
||||
Category: "info",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("Version: " + version.String)
|
||||
fmt.Printf("Compiled: %s\n", version.Compiled())
|
||||
fmt.Println("")
|
||||
|
||||
reg := registry.GetRegistry()
|
||||
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err))
|
||||
return err
|
||||
}
|
||||
|
||||
if len(services) == 0 {
|
||||
fmt.Println("No running " + cfg.Service.Name + " service found.")
|
||||
return nil
|
||||
}
|
||||
|
||||
table := tw.NewWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Version", "Address", "Id"})
|
||||
table.SetAutoFormatHeaders(false)
|
||||
for _, s := range services {
|
||||
for _, n := range s.Nodes {
|
||||
table.Append([]string{s.Version, n.Address, n.Id})
|
||||
}
|
||||
}
|
||||
table.Render()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
*shared.Commons `yaml:"-"`
|
||||
Service Service `yaml:"-"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
Logging *Logging `yaml:"log"`
|
||||
Log *Log `yaml:"log"`
|
||||
Debug Debug `yaml:"debug"`
|
||||
Supervised bool `yaml:"-"`
|
||||
|
||||
GRPC GRPCConfig `yaml:"grpc"`
|
||||
|
||||
@@ -18,6 +21,9 @@ type Config struct {
|
||||
SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token"`
|
||||
AuthProvider string `yaml:"auth_provider" env:"AUTH_BASIC_AUTH_PROVIDER" desc:"The auth provider which should be used by the service"`
|
||||
AuthProviders AuthProviders `yaml:"auth_providers"`
|
||||
|
||||
Supervised bool `yaml:"-"`
|
||||
Context context.Context `yaml:"-"`
|
||||
}
|
||||
type Tracing struct {
|
||||
Enabled bool `yaml:"enabled" env:"OCIS_TRACING_ENABLED;AUTH_BASIC_TRACING_ENABLED" desc:"Activates tracing."`
|
||||
@@ -26,7 +32,7 @@ type Tracing struct {
|
||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR;AUTH_BASIC_TRACING_COLLECTOR"`
|
||||
}
|
||||
|
||||
type Logging struct {
|
||||
type Log struct {
|
||||
Level string `yaml:"level" env:"OCIS_LOG_LEVEL;AUTH_BASIC_LOG_LEVEL" desc:"The log level."`
|
||||
Pretty bool `yaml:"pretty" env:"OCIS_LOG_PRETTY;AUTH_BASIC_LOG_PRETTY" desc:"Activates pretty log output."`
|
||||
Color bool `yaml:"color" env:"OCIS_LOG_COLOR;AUTH_BASIC_LOG_COLOR" desc:"Activates colorized log output."`
|
||||
@@ -45,8 +51,9 @@ type Debug struct {
|
||||
}
|
||||
|
||||
type GRPCConfig struct {
|
||||
Addr string `yaml:"addr" env:"AUTH_BASIC_GRPC_ADDR" desc:"The address of the grpc service."`
|
||||
Protocol string `yaml:"protocol" env:"AUTH_BASIC_GRPC_PROTOCOL" desc:"The transport protocol of the grpc service."`
|
||||
Addr string `yaml:"addr" env:"AUTH_BASIC_GRPC_ADDR" desc:"The address of the grpc service."`
|
||||
Namespace string `yaml:"-"`
|
||||
Protocol string `yaml:"protocol" env:"AUTH_BASIC_GRPC_PROTOCOL" desc:"The transport protocol of the grpc service."`
|
||||
}
|
||||
|
||||
type AuthProviders struct {
|
||||
|
||||
@@ -24,6 +24,7 @@ func DefaultConfig() *config.Config {
|
||||
},
|
||||
GRPC: config.GRPCConfig{
|
||||
Addr: "127.0.0.1:9146",
|
||||
Namespace: "com.owncloud.api",
|
||||
Protocol: "tcp",
|
||||
},
|
||||
Service: config.Service{
|
||||
@@ -80,15 +81,15 @@ func DefaultConfig() *config.Config {
|
||||
|
||||
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.Logging{
|
||||
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.Logging == nil {
|
||||
cfg.Logging = &config.Logging{}
|
||||
} else if cfg.Log == nil {
|
||||
cfg.Log = &config.Log{}
|
||||
}
|
||||
// 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 {
|
||||
|
||||
17
extensions/auth-basic/pkg/logging/logging.go
Normal file
17
extensions/auth-basic/pkg/logging/logging.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// LoggerFromConfig initializes a service-specific logger instance.
|
||||
func Configure(name string, cfg *config.Log) log.Logger {
|
||||
return log.NewLogger(
|
||||
log.Name(name),
|
||||
log.Level(cfg.Level),
|
||||
log.Pretty(cfg.Pretty),
|
||||
log.Color(cfg.Color),
|
||||
log.File(cfg.File),
|
||||
)
|
||||
}
|
||||
83
extensions/auth-basic/pkg/revaconfig/config.go
Normal file
83
extensions/auth-basic/pkg/revaconfig/config.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package revaconfig
|
||||
|
||||
import "github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
|
||||
// AuthBasicConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||
func AuthBasicConfigFromStruct(cfg *config.Config) map[string]interface{} {
|
||||
rcfg := map[string]interface{}{
|
||||
"core": map[string]interface{}{
|
||||
"tracing_enabled": cfg.Tracing.Enabled,
|
||||
"tracing_endpoint": cfg.Tracing.Endpoint,
|
||||
"tracing_collector": cfg.Tracing.Collector,
|
||||
"tracing_service_name": cfg.Service.Name,
|
||||
},
|
||||
"shared": map[string]interface{}{
|
||||
"jwt_secret": cfg.TokenManager.JWTSecret,
|
||||
"gatewaysvc": cfg.Reva.Address,
|
||||
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
|
||||
},
|
||||
"grpc": map[string]interface{}{
|
||||
"network": cfg.GRPC.Protocol,
|
||||
"address": cfg.GRPC.Addr,
|
||||
// TODO build services dynamically
|
||||
"services": map[string]interface{}{
|
||||
"authprovider": map[string]interface{}{
|
||||
"auth_manager": cfg.AuthProvider,
|
||||
"auth_managers": map[string]interface{}{
|
||||
"json": map[string]interface{}{
|
||||
"users": cfg.AuthProviders.JSON.File,
|
||||
},
|
||||
"ldap": ldapConfigFromString(cfg.AuthProviders.LDAP),
|
||||
"owncloudsql": map[string]interface{}{
|
||||
"dbusername": cfg.AuthProviders.OwnCloudSQL.DBUsername,
|
||||
"dbpassword": cfg.AuthProviders.OwnCloudSQL.DBPassword,
|
||||
"dbhost": cfg.AuthProviders.OwnCloudSQL.DBHost,
|
||||
"dbport": cfg.AuthProviders.OwnCloudSQL.DBPort,
|
||||
"dbname": cfg.AuthProviders.OwnCloudSQL.DBName,
|
||||
"idp": cfg.AuthProviders.OwnCloudSQL.IDP,
|
||||
"nobody": cfg.AuthProviders.OwnCloudSQL.Nobody,
|
||||
"join_username": cfg.AuthProviders.OwnCloudSQL.JoinUsername,
|
||||
"join_ownclouduuid": cfg.AuthProviders.OwnCloudSQL.JoinOwnCloudUUID,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rcfg
|
||||
}
|
||||
|
||||
func ldapConfigFromString(cfg config.LDAPProvider) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"uri": cfg.URI,
|
||||
"cacert": cfg.CACert,
|
||||
"insecure": cfg.Insecure,
|
||||
"bind_username": cfg.BindDN,
|
||||
"bind_password": cfg.BindPassword,
|
||||
"user_base_dn": cfg.UserBaseDN,
|
||||
"group_base_dn": cfg.GroupBaseDN,
|
||||
"user_filter": cfg.UserFilter,
|
||||
"group_filter": cfg.GroupFilter,
|
||||
"user_scope": cfg.UserScope,
|
||||
"group_scope": cfg.GroupScope,
|
||||
"user_objectclass": cfg.UserObjectClass,
|
||||
"group_objectclass": cfg.GroupObjectClass,
|
||||
"login_attributes": cfg.LoginAttributes,
|
||||
"idp": cfg.IDP,
|
||||
"user_schema": map[string]interface{}{
|
||||
"id": cfg.UserSchema.ID,
|
||||
"idIsOctetString": cfg.UserSchema.IDIsOctetString,
|
||||
"mail": cfg.UserSchema.Mail,
|
||||
"displayName": cfg.UserSchema.DisplayName,
|
||||
"userName": cfg.UserSchema.Username,
|
||||
},
|
||||
"group_schema": map[string]interface{}{
|
||||
"id": cfg.GroupSchema.ID,
|
||||
"idIsOctetString": cfg.GroupSchema.IDIsOctetString,
|
||||
"mail": cfg.GroupSchema.Mail,
|
||||
"displayName": cfg.GroupSchema.DisplayName,
|
||||
"groupName": cfg.GroupSchema.Groupname,
|
||||
"member": cfg.GroupSchema.Member,
|
||||
},
|
||||
}
|
||||
}
|
||||
18
extensions/auth-basic/pkg/tracing/tracing.go
Normal file
18
extensions/auth-basic/pkg/tracing/tracing.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package tracing
|
||||
|
||||
import (
|
||||
"github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/ocis-pkg/tracing"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// TraceProvider is the global trace provider for the proxy service.
|
||||
TraceProvider = trace.NewNoopTracerProvider()
|
||||
)
|
||||
|
||||
func Configure(cfg *config.Config, logger log.Logger) error {
|
||||
tracing.Configure(cfg.Tracing.Enabled, cfg.Tracing.Type, logger)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user