-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
370 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build !simple | ||
|
||
package command | ||
|
||
import ( | ||
"github.com/micro/cli/v2" | ||
"github.com/owncloud/ocis/ocis-pkg/config" | ||
"github.com/owncloud/ocis/ocis/pkg/register" | ||
"github.com/owncloud/ocis/storage/pkg/command" | ||
svcconfig "github.com/owncloud/ocis/storage/pkg/config" | ||
"github.com/owncloud/ocis/storage/pkg/flagset" | ||
) | ||
|
||
// AppProviderCommand is the entrypoint for the reva-gateway command. | ||
func AppProviderCommand(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "app-provider", | ||
Usage: "Start appprovider for providing apps", | ||
Category: "Extensions", | ||
Flags: flagset.AppProviderWithConfig(cfg.Storage), | ||
Action: func(c *cli.Context) error { | ||
origCmd := command.AppProvider(configureAppProvider(cfg)) | ||
return handleOriginalAction(c, origCmd) | ||
}, | ||
} | ||
} | ||
|
||
func configureAppProvider(cfg *config.Config) *svcconfig.Config { | ||
cfg.Storage.Log.Level = cfg.Log.Level | ||
cfg.Storage.Log.Pretty = cfg.Log.Pretty | ||
cfg.Storage.Log.Color = cfg.Log.Color | ||
|
||
if cfg.Tracing.Enabled { | ||
cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled | ||
cfg.Storage.Tracing.Type = cfg.Tracing.Type | ||
cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint | ||
cfg.Storage.Tracing.Collector = cfg.Tracing.Collector | ||
} | ||
|
||
return cfg.Storage | ||
} | ||
|
||
func init() { | ||
register.AddCommand(AppProviderCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build !simple | ||
|
||
package command | ||
|
||
import ( | ||
"github.com/micro/cli/v2" | ||
"github.com/owncloud/ocis/ocis-pkg/config" | ||
"github.com/owncloud/ocis/ocis/pkg/register" | ||
"github.com/owncloud/ocis/storage/pkg/command" | ||
svcconfig "github.com/owncloud/ocis/storage/pkg/config" | ||
"github.com/owncloud/ocis/storage/pkg/flagset" | ||
) | ||
|
||
// StorageAppProviderCommand is the entrypoint for the reva-app-provider command. | ||
func StorageAppProviderCommand(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "storage-app-provider", | ||
Usage: "Start storage app-provider service", | ||
Category: "Extensions", | ||
Flags: flagset.AppProviderWithConfig(cfg.Storage), | ||
Action: func(c *cli.Context) error { | ||
origCmd := command.AppProvider(configureStorageAppProvider(cfg)) | ||
return handleOriginalAction(c, origCmd) | ||
}, | ||
} | ||
} | ||
|
||
func configureStorageAppProvider(cfg *config.Config) *svcconfig.Config { | ||
cfg.Storage.Log.Level = cfg.Log.Level | ||
cfg.Storage.Log.Pretty = cfg.Log.Pretty | ||
cfg.Storage.Log.Color = cfg.Log.Color | ||
|
||
if cfg.Tracing.Enabled { | ||
cfg.Storage.Tracing.Enabled = cfg.Tracing.Enabled | ||
cfg.Storage.Tracing.Type = cfg.Tracing.Type | ||
cfg.Storage.Tracing.Endpoint = cfg.Tracing.Endpoint | ||
cfg.Storage.Tracing.Collector = cfg.Tracing.Collector | ||
} | ||
|
||
return cfg.Storage | ||
} | ||
|
||
func init() { | ||
register.AddCommand(StorageAppProviderCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"os" | ||
"path" | ||
|
||
"github.com/cs3org/reva/cmd/revad/runtime" | ||
"github.com/gofrs/uuid" | ||
"github.com/micro/cli/v2" | ||
"github.com/oklog/run" | ||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config" | ||
"github.com/owncloud/ocis/ocis-pkg/sync" | ||
"github.com/owncloud/ocis/storage/pkg/config" | ||
"github.com/owncloud/ocis/storage/pkg/flagset" | ||
"github.com/owncloud/ocis/storage/pkg/server/debug" | ||
"github.com/owncloud/ocis/storage/pkg/tracing" | ||
"github.com/thejerf/suture/v4" | ||
) | ||
|
||
// AppProvider is the entrypoint for the app provider command. | ||
func AppProvider(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "app-provider", | ||
Usage: "Start appprovider for providing apps", | ||
Flags: flagset.AppProviderWithConfig(cfg), | ||
Before: func(c *cli.Context) error { | ||
cfg.Reva.AppProvider.Services = c.StringSlice("service") | ||
|
||
return nil | ||
}, | ||
Action: func(c *cli.Context) error { | ||
logger := NewLogger(cfg) | ||
tracing.Configure(cfg, logger) | ||
gr := run.Group{} | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
uuid := uuid.Must(uuid.NewV4()) | ||
pidFile := path.Join(os.TempDir(), "revad-"+c.Command.Name+"-"+uuid.String()+".pid") | ||
|
||
rcfg := appProviderConfigFromStruct(c, cfg) | ||
|
||
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.Name(c.Command.Name+"-debug"), | ||
debug.Addr(cfg.Reva.AppProvider.DebugAddr), | ||
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.Reva.AppProvider.Supervised { | ||
sync.Trap(&gr, cancel) | ||
} | ||
|
||
return gr.Run() | ||
}, | ||
} | ||
} | ||
|
||
// appProviderConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service. | ||
func appProviderConfigFromStruct(c *cli.Context, cfg *config.Config) map[string]interface{} { | ||
rcfg := map[string]interface{}{ | ||
"core": map[string]interface{}{ | ||
"max_cpus": cfg.Reva.AppProvider.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.AppProvider.GRPCNetwork, | ||
"address": cfg.Reva.AppProvider.GRPCAddr, | ||
// TODO build services dynamically | ||
"services": map[string]interface{}{ | ||
"appprovider": map[string]interface{}{ | ||
"driver": cfg.Reva.AppProvider.Driver, | ||
"demo": map[string]interface{}{}, | ||
"wopiinsecure": cfg.Reva.AppProvider.WopiInsecure, | ||
"iopsecret": cfg.Reva.AppProvider.IopSecret, | ||
"wopiurl": cfg.Reva.AppProvider.WopiUrl, | ||
"wopibridgeurl": cfg.Reva.AppProvider.WopiBridgeUrl, | ||
}, | ||
}, | ||
}, | ||
} | ||
return rcfg | ||
} | ||
|
||
// AppProviderSutureService allows for the app-provider command to be embedded and supervised by a suture supervisor tree. | ||
type AppProviderSutureService struct { | ||
cfg *config.Config | ||
} | ||
|
||
// NewAppProvider creates a new store.AppProviderSutureService | ||
func NewAppProvider(cfg *ociscfg.Config) suture.Service { | ||
if cfg.Mode == 0 { | ||
cfg.Storage.Reva.AppProvider.Supervised = true | ||
} | ||
return AppProviderSutureService{ | ||
cfg: cfg.Storage, | ||
} | ||
} | ||
|
||
func (s AppProviderSutureService) Serve(ctx context.Context) error { | ||
s.cfg.Reva.AppProvider.Context = ctx | ||
f := &flag.FlagSet{} | ||
for k := range AppProvider(s.cfg).Flags { | ||
if err := AppProvider(s.cfg).Flags[k].Apply(f); err != nil { | ||
return err | ||
} | ||
} | ||
cliCtx := cli.NewContext(nil, f, nil) | ||
if AppProvider(s.cfg).Before != nil { | ||
if err := AppProvider(s.cfg).Before(cliCtx); err != nil { | ||
return err | ||
} | ||
} | ||
if err := AppProvider(s.cfg).Action(cliCtx); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.