-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2204 from owncloud/add_reva_app_provider
add app provider and app provider registry
- Loading branch information
Showing
17 changed files
with
445 additions
and
122 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Enhancement: Add app provider and app provider registry | ||
|
||
We added the app provider and app provider registry. Now the CS3org WOPI server can be registered and OpenInApp requests can be done. | ||
|
||
https://github.com/owncloud/ocis/pull/2204 | ||
https://github.com/cs3org/reva/pull/1785 |
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
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" | ||
) | ||
|
||
// 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
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,160 @@ | ||
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{}{ | ||
"gatewaysvc": cfg.Reva.Gateway.Endpoint, | ||
"app_provider_url": cfg.Reva.AppProvider.ExternalAddr, | ||
"driver": cfg.Reva.AppProvider.Driver, | ||
"drivers": map[string]interface{}{ | ||
"wopi": map[string]interface{}{ | ||
"app_api_key": cfg.Reva.AppProvider.WopiDriver.AppAPIKey, | ||
"app_desktop_only": cfg.Reva.AppProvider.WopiDriver.AppDesktopOnly, | ||
"app_icon_uri": cfg.Reva.AppProvider.WopiDriver.AppIconURI, | ||
"app_int_url": cfg.Reva.AppProvider.WopiDriver.AppInternalURL, | ||
"app_name": cfg.Reva.AppProvider.WopiDriver.AppName, | ||
"app_url": cfg.Reva.AppProvider.WopiDriver.AppURL, | ||
"insecure_connections": cfg.Reva.AppProvider.WopiDriver.Insecure, | ||
"iop_secret": cfg.Reva.AppProvider.WopiDriver.IopSecret, | ||
"jwt_secret": cfg.Reva.AppProvider.WopiDriver.JWTSecret, | ||
"wopi_url": cfg.Reva.AppProvider.WopiDriver.WopiURL, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
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
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.