refactor groups tracing config
This commit is contained in:
+100
-129
@@ -7,6 +7,8 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/storage/pkg/tracing"
|
||||||
|
|
||||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||||
|
|
||||||
"github.com/cs3org/reva/cmd/revad/runtime"
|
"github.com/cs3org/reva/cmd/revad/runtime"
|
||||||
@@ -33,149 +35,55 @@ func Groups(cfg *config.Config) *cli.Command {
|
|||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger := NewLogger(cfg)
|
logger := NewLogger(cfg)
|
||||||
|
tracing.Configure(cfg, logger)
|
||||||
|
gr := run.Group{}
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
if cfg.Tracing.Enabled {
|
// pre-create folders
|
||||||
switch t := cfg.Tracing.Type; t {
|
|
||||||
case "agent":
|
|
||||||
logger.Error().
|
|
||||||
Str("type", t).
|
|
||||||
Msg("Reva only supports the jaeger tracing backend")
|
|
||||||
|
|
||||||
case "jaeger":
|
|
||||||
logger.Info().
|
|
||||||
Str("type", t).
|
|
||||||
Msg("configuring storage to use the jaeger tracing backend")
|
|
||||||
|
|
||||||
case "zipkin":
|
|
||||||
logger.Error().
|
|
||||||
Str("type", t).
|
|
||||||
Msg("Reva only supports the jaeger tracing backend")
|
|
||||||
|
|
||||||
default:
|
|
||||||
logger.Warn().
|
|
||||||
Str("type", t).
|
|
||||||
Msg("Unknown tracing backend")
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
logger.Debug().
|
|
||||||
Msg("Tracing is not enabled")
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
gr = run.Group{}
|
|
||||||
ctx, cancel = context.WithCancel(context.Background())
|
|
||||||
//metrics = metrics.New()
|
|
||||||
)
|
|
||||||
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// precreate folders
|
|
||||||
if cfg.Reva.Groups.Driver == "json" && cfg.Reva.Groups.JSON != "" {
|
if cfg.Reva.Groups.Driver == "json" && cfg.Reva.Groups.JSON != "" {
|
||||||
if err := os.MkdirAll(filepath.Dir(cfg.Reva.Groups.JSON), os.FileMode(0700)); err != nil {
|
if err := os.MkdirAll(filepath.Dir(cfg.Reva.Groups.JSON), os.FileMode(0700)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
uuid := uuid.Must(uuid.NewV4())
|
||||||
uuid := uuid.Must(uuid.NewV4())
|
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
||||||
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid")
|
defer cancel()
|
||||||
|
|
||||||
rcfg := map[string]interface{}{
|
rcfg := groupsConfigFromStruct(c, cfg)
|
||||||
"core": map[string]interface{}{
|
|
||||||
"max_cpus": cfg.Reva.Groups.MaxCPUs,
|
|
||||||
"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.Reva.JWTSecret,
|
|
||||||
},
|
|
||||||
"grpc": map[string]interface{}{
|
|
||||||
"network": cfg.Reva.Groups.GRPCNetwork,
|
|
||||||
"address": cfg.Reva.Groups.GRPCAddr,
|
|
||||||
// TODO build services dynamically
|
|
||||||
"services": map[string]interface{}{
|
|
||||||
"groupprovider": map[string]interface{}{
|
|
||||||
"driver": cfg.Reva.Groups.Driver,
|
|
||||||
"drivers": map[string]interface{}{
|
|
||||||
"json": map[string]interface{}{
|
|
||||||
"groups": cfg.Reva.Groups.JSON,
|
|
||||||
},
|
|
||||||
"ldap": map[string]interface{}{
|
|
||||||
"hostname": cfg.Reva.LDAP.Hostname,
|
|
||||||
"port": cfg.Reva.LDAP.Port,
|
|
||||||
"base_dn": cfg.Reva.LDAP.BaseDN,
|
|
||||||
"groupfilter": cfg.Reva.LDAP.GroupFilter,
|
|
||||||
"attributefilter": cfg.Reva.LDAP.GroupAttributeFilter,
|
|
||||||
"findfilter": cfg.Reva.LDAP.GroupFindFilter,
|
|
||||||
"memberfilter": cfg.Reva.LDAP.GroupMemberFilter,
|
|
||||||
"bind_username": cfg.Reva.LDAP.BindDN,
|
|
||||||
"bind_password": cfg.Reva.LDAP.BindPassword,
|
|
||||||
"idp": cfg.Reva.LDAP.IDP,
|
|
||||||
"schema": map[string]interface{}{
|
|
||||||
"dn": "dn",
|
|
||||||
"gid": cfg.Reva.LDAP.GroupSchema.GID,
|
|
||||||
"mail": cfg.Reva.LDAP.GroupSchema.Mail,
|
|
||||||
"displayName": cfg.Reva.LDAP.GroupSchema.DisplayName,
|
|
||||||
"cn": cfg.Reva.LDAP.GroupSchema.CN,
|
|
||||||
"gidNumber": cfg.Reva.LDAP.GroupSchema.GIDNumber,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"rest": map[string]interface{}{
|
|
||||||
"client_id": cfg.Reva.UserGroupRest.ClientID,
|
|
||||||
"client_secret": cfg.Reva.UserGroupRest.ClientSecret,
|
|
||||||
"redis_address": cfg.Reva.UserGroupRest.RedisAddress,
|
|
||||||
"redis_username": cfg.Reva.UserGroupRest.RedisUsername,
|
|
||||||
"redis_password": cfg.Reva.UserGroupRest.RedisPassword,
|
|
||||||
"group_members_cache_expiration": cfg.Reva.Groups.GroupMembersCacheExpiration,
|
|
||||||
"id_provider": cfg.Reva.UserGroupRest.IDProvider,
|
|
||||||
"api_base_url": cfg.Reva.UserGroupRest.APIBaseURL,
|
|
||||||
"oidc_token_endpoint": cfg.Reva.UserGroupRest.OIDCTokenEndpoint,
|
|
||||||
"target_api": cfg.Reva.UserGroupRest.TargetAPI,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
gr.Add(func() error {
|
gr.Add(func() error {
|
||||||
runtime.RunWithOptions(
|
runtime.RunWithOptions(
|
||||||
rcfg,
|
rcfg,
|
||||||
pidFile,
|
pidFile,
|
||||||
runtime.WithLogger(&logger.Logger),
|
runtime.WithLogger(&logger.Logger),
|
||||||
)
|
|
||||||
return nil
|
|
||||||
}, func(_ error) {
|
|
||||||
logger.Info().
|
|
||||||
Str("server", c.Command.Name).
|
|
||||||
Msg("Shutting down server")
|
|
||||||
|
|
||||||
cancel()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
server, err := debug.Server(
|
|
||||||
debug.Name(c.Command.Name+"-debug"),
|
|
||||||
debug.Addr(cfg.Reva.Users.DebugAddr),
|
|
||||||
debug.Logger(logger),
|
|
||||||
debug.Context(ctx),
|
|
||||||
debug.Config(cfg),
|
|
||||||
)
|
)
|
||||||
|
return nil
|
||||||
|
}, func(_ error) {
|
||||||
|
logger.Info().
|
||||||
|
Str("server", c.Command.Name).
|
||||||
|
Msg("Shutting down server")
|
||||||
|
|
||||||
if err != nil {
|
cancel()
|
||||||
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
gr.Add(server.ListenAndServe, func(_ error) {
|
debugServer, err := debug.Server(
|
||||||
cancel()
|
debug.Name(c.Command.Name+"-debug"),
|
||||||
})
|
debug.Addr(cfg.Reva.Users.DebugAddr),
|
||||||
|
debug.Logger(logger),
|
||||||
|
debug.Context(ctx),
|
||||||
|
debug.Config(cfg),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Info().Err(err).Str("server", c.Command.Name+"-debug").Msg("Failed to initialize server")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gr.Add(debugServer.ListenAndServe, func(_ error) {
|
||||||
|
cancel()
|
||||||
|
})
|
||||||
|
|
||||||
if !cfg.Reva.StorageMetadata.Supervised {
|
if !cfg.Reva.StorageMetadata.Supervised {
|
||||||
sync.Trap(&gr, cancel)
|
sync.Trap(&gr, cancel)
|
||||||
}
|
}
|
||||||
@@ -185,6 +93,69 @@ func Groups(cfg *config.Config) *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// groupsConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
|
||||||
|
func groupsConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} {
|
||||||
|
return map[string]interface{}{
|
||||||
|
"core": map[string]interface{}{
|
||||||
|
"max_cpus": cfg.Reva.Groups.MaxCPUs,
|
||||||
|
"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.Reva.JWTSecret,
|
||||||
|
},
|
||||||
|
"grpc": map[string]interface{}{
|
||||||
|
"network": cfg.Reva.Groups.GRPCNetwork,
|
||||||
|
"address": cfg.Reva.Groups.GRPCAddr,
|
||||||
|
// TODO build services dynamically
|
||||||
|
"services": map[string]interface{}{
|
||||||
|
"groupprovider": map[string]interface{}{
|
||||||
|
"driver": cfg.Reva.Groups.Driver,
|
||||||
|
"drivers": map[string]interface{}{
|
||||||
|
"json": map[string]interface{}{
|
||||||
|
"groups": cfg.Reva.Groups.JSON,
|
||||||
|
},
|
||||||
|
"ldap": map[string]interface{}{
|
||||||
|
"hostname": cfg.Reva.LDAP.Hostname,
|
||||||
|
"port": cfg.Reva.LDAP.Port,
|
||||||
|
"base_dn": cfg.Reva.LDAP.BaseDN,
|
||||||
|
"groupfilter": cfg.Reva.LDAP.GroupFilter,
|
||||||
|
"attributefilter": cfg.Reva.LDAP.GroupAttributeFilter,
|
||||||
|
"findfilter": cfg.Reva.LDAP.GroupFindFilter,
|
||||||
|
"memberfilter": cfg.Reva.LDAP.GroupMemberFilter,
|
||||||
|
"bind_username": cfg.Reva.LDAP.BindDN,
|
||||||
|
"bind_password": cfg.Reva.LDAP.BindPassword,
|
||||||
|
"idp": cfg.Reva.LDAP.IDP,
|
||||||
|
"schema": map[string]interface{}{
|
||||||
|
"dn": "dn",
|
||||||
|
"gid": cfg.Reva.LDAP.GroupSchema.GID,
|
||||||
|
"mail": cfg.Reva.LDAP.GroupSchema.Mail,
|
||||||
|
"displayName": cfg.Reva.LDAP.GroupSchema.DisplayName,
|
||||||
|
"cn": cfg.Reva.LDAP.GroupSchema.CN,
|
||||||
|
"gidNumber": cfg.Reva.LDAP.GroupSchema.GIDNumber,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"rest": map[string]interface{}{
|
||||||
|
"client_id": cfg.Reva.UserGroupRest.ClientID,
|
||||||
|
"client_secret": cfg.Reva.UserGroupRest.ClientSecret,
|
||||||
|
"redis_address": cfg.Reva.UserGroupRest.RedisAddress,
|
||||||
|
"redis_username": cfg.Reva.UserGroupRest.RedisUsername,
|
||||||
|
"redis_password": cfg.Reva.UserGroupRest.RedisPassword,
|
||||||
|
"group_members_cache_expiration": cfg.Reva.Groups.GroupMembersCacheExpiration,
|
||||||
|
"id_provider": cfg.Reva.UserGroupRest.IDProvider,
|
||||||
|
"api_base_url": cfg.Reva.UserGroupRest.APIBaseURL,
|
||||||
|
"oidc_token_endpoint": cfg.Reva.UserGroupRest.OIDCTokenEndpoint,
|
||||||
|
"target_api": cfg.Reva.UserGroupRest.TargetAPI,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree.
|
// GroupsProvider allows for the storage-groupsprovider command to be embedded and supervised by a suture supervisor tree.
|
||||||
type GroupsProvider struct {
|
type GroupsProvider struct {
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
|
|||||||
Reference in New Issue
Block a user