add webdav

This commit is contained in:
A.Unger
2021-03-04 14:37:37 +01:00
parent e8b1665f63
commit 8aed339867
6 changed files with 61 additions and 42 deletions

View File

@@ -15,6 +15,7 @@ import (
store "github.com/owncloud/ocis/store/pkg/command"
thumbnails "github.com/owncloud/ocis/thumbnails/pkg/command"
web "github.com/owncloud/ocis/web/pkg/command"
webdav "github.com/owncloud/ocis/webdav/pkg/command"
"github.com/thejerf/suture"
@@ -58,7 +59,7 @@ var (
"storage-users",
"storage-public-link",
"thumbnails", // done
"web",
"web", // done
"webdav",
}
@@ -130,6 +131,7 @@ func (r *Runtime) Start() error {
addServiceToken("store", supervisor.Add(store.NewSutureService(globalCtx, r.c.Store)))
addServiceToken("thumbnails", supervisor.Add(thumbnails.NewSutureService(globalCtx, r.c.Thumbnails)))
addServiceToken("web", supervisor.Add(web.NewSutureService(globalCtx, r.c.Web)))
addServiceToken("webdav", supervisor.Add(webdav.NewSutureService(globalCtx, r.c.WebDAV)))
// TODO(refs) debug line with supervised services.
go supervisor.ServeBackground()

View File

@@ -4,10 +4,11 @@ import (
"os"
"github.com/owncloud/ocis/webdav/pkg/command"
"github.com/owncloud/ocis/webdav/pkg/config"
)
func main() {
if err := command.Execute(); err != nil {
if err := command.Execute(config.New()); err != nil {
os.Exit(1)
}
}

View File

@@ -1,21 +1,19 @@
package command
import (
"context"
"os"
"strings"
"github.com/micro/cli/v2"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/webdav/pkg/config"
"github.com/owncloud/ocis/webdav/pkg/flagset"
"github.com/owncloud/ocis/webdav/pkg/version"
"github.com/spf13/viper"
)
// Execute is the entry point for the ocis-webdav command.
func Execute() error {
cfg := config.New()
func Execute(cfg *config.Config) error {
app := &cli.App{
Name: "webdav",
Version: version.String,
@@ -28,9 +26,6 @@ func Execute() error {
Email: "support@owncloud.com",
},
},
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return nil
@@ -107,3 +102,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error {
return nil
}
// SutureService allows for the webdav command to be embedded and supervised by a suture supervisor tree.
type SutureService struct {
ctx context.Context
cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service.
cfg *config.Config
}
// NewSutureService creates a new webdav.SutureService
func NewSutureService(ctx context.Context, cfg *config.Config) SutureService {
sctx, cancel := context.WithCancel(ctx)
cfg.Context = sctx // propagate the context down to the go-micro services.
return SutureService{
ctx: sctx,
cancel: cancel,
cfg: cfg,
}
}
func (s SutureService) Serve() {
if err := Execute(s.cfg); err != nil {
return
}
}
func (s SutureService) Stop() {
s.cancel()
}

View File

@@ -141,8 +141,6 @@ func Server(cfg *config.Config) *cli.Command {
http.Context(ctx),
http.Config(cfg),
http.Metrics(metrics),
http.Flags(flagset.RootWithConfig(config.New())),
http.Flags(flagset.ServerWithConfig(config.New())),
)
if err != nil {

View File

@@ -1,5 +1,7 @@
package config
import "context"
// Log defines the available logging configuration.
type Log struct {
Level string
@@ -17,15 +19,15 @@ type Debug struct {
// HTTP defines the available http configuration.
type HTTP struct {
Addr string
Root string
Addr string
Root string
}
// Service defines the available service configuration.
type Service struct {
Name string
Name string
Namespace string
Version string
Version string
}
// Tracing defines the available tracing configuration.
@@ -45,6 +47,8 @@ type Config struct {
HTTP HTTP
Tracing Tracing
Service Service
Context context.Context
}
// New initializes a new configuration with or without defaults.

View File

@@ -5,33 +5,6 @@ import (
"github.com/owncloud/ocis/webdav/pkg/config"
)
// RootWithConfig applies cfg to the root flagset
func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVars: []string{"WEBDAV_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Value: true,
Name: "log-pretty",
Usage: "Enable pretty logging",
EnvVars: []string{"WEBDAV_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Value: true,
Name: "log-color",
Usage: "Enable colored logging",
EnvVars: []string{"WEBDAV_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
}
}
// HealthWithConfig applies cfg to the root flagset
func HealthWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
@@ -48,6 +21,24 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag {
// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "log-level",
Usage: "Set logging level",
EnvVars: []string{"WEBDAV_LOG_LEVEL", "OCIS_LOG_LEVEL"},
Destination: &cfg.Log.Level,
},
&cli.BoolFlag{
Name: "log-pretty",
Usage: "Enable pretty logging",
EnvVars: []string{"WEBDAV_LOG_PRETTY", "OCIS_LOG_PRETTY"},
Destination: &cfg.Log.Pretty,
},
&cli.BoolFlag{
Name: "log-color",
Usage: "Enable colored logging",
EnvVars: []string{"WEBDAV_LOG_COLOR", "OCIS_LOG_COLOR"},
Destination: &cfg.Log.Color,
},
&cli.StringFlag{
Name: "config-file",
Value: "",