Skip to content

Commit

Permalink
add reva app provider
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Jul 27, 2021
1 parent 5825a9b commit e9c2756
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/extensions/storage/ports.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ For now, the storage service uses these ports to preconfigure those services:
| 9159 | storage users debug |
| 9160 | groups |
| 9161 | groups debug |
| 9164 | appprovider |
| 9165 | appprovider debug |
| 9178 | storage public link |
| 9179 | storage public link data |
| 9215 | storage meta grpc |
Expand Down
45 changes: 45 additions & 0 deletions ocis/pkg/command/appprovider.go
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)
}
45 changes: 45 additions & 0 deletions ocis/pkg/command/storageappprovider.go
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)
}
1 change: 1 addition & 0 deletions ocis/pkg/runtime/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func NewService(options ...Option) (*Service, error) {
s.ServicesRegistry["storage-home"] = storage.NewStorageHome
s.ServicesRegistry["storage-users"] = storage.NewStorageUsers
s.ServicesRegistry["storage-public-link"] = storage.NewStoragePublicLink
s.ServicesRegistry["storage-appprovider"] = storage.NewAppProvider

// populate delayed services
s.Delayed["storage-sharing"] = storage.NewSharing
Expand Down
148 changes: 148 additions & 0 deletions storage/pkg/command/appprovider.go
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
}
9 changes: 9 additions & 0 deletions storage/pkg/command/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ func gatewayConfigFromStruct(c *cli.Context, cfg *config.Config, logger log.Logg
},
},
},
"appregistry": map[string]interface{}{
"driver": "static",
"static": map[string]interface{}{
"rules": map[string]interface{}{
//TODO: add types configuration
"application/vnd.oasis.opendocument.text": cfg.Reva.AppProvider.Endpoint,
},
},
},
"storageregistry": map[string]interface{}{
"driver": cfg.Reva.StorageRegistry.Driver,
"drivers": map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions storage/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Execute(cfg *config.Config) error {
Gateway(cfg),
Users(cfg),
Groups(cfg),
AppProvider(cfg),
AuthBasic(cfg),
AuthBearer(cfg),
Sharing(cfg),
Expand Down
11 changes: 11 additions & 0 deletions storage/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ type StorageRegistry struct {
JSON string
}

// AppProvider defines the available app provider configuration
type AppProvider struct {
Port
Driver string
IopSecret string
WopiInsecure bool
WopiUrl string
WopiBridgeUrl string
}

// Sharing defines the available sharing configuration.
type Sharing struct {
Port
Expand Down Expand Up @@ -388,6 +398,7 @@ type Reva struct {
StorageUsers StoragePort
StoragePublicLink PublicStorage
StorageMetadata StoragePort
AppProvider AppProvider
// Configs can be used to configure the reva instance.
// Services and Ports will be ignored if this is used
Configs map[string]interface{}
Expand Down
Loading

0 comments on commit e9c2756

Please sign in to comment.