From 89f8320c7406b7c3e4cd43281a66a821c660a7f1 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 21 Jun 2021 15:26:45 +0200 Subject: [PATCH] Make webdav namespace configurable across services --- changelog/unreleased/webdav-ns-config.md | 7 +++++++ graph/pkg/config/config.go | 19 ++++++++++--------- graph/pkg/flagset/flagset.go | 7 +++++++ graph/pkg/service/v0/drives.go | 2 +- thumbnails/pkg/config/config.go | 1 + thumbnails/pkg/flagset/flagset.go | 7 +++++++ thumbnails/pkg/service/v0/service.go | 18 ++++++++++-------- webdav/pkg/config/config.go | 1 + webdav/pkg/flagset/flagset.go | 7 +++++++ webdav/pkg/service/v0/service.go | 2 +- 10 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 changelog/unreleased/webdav-ns-config.md diff --git a/changelog/unreleased/webdav-ns-config.md b/changelog/unreleased/webdav-ns-config.md new file mode 100644 index 0000000000..298e35de48 --- /dev/null +++ b/changelog/unreleased/webdav-ns-config.md @@ -0,0 +1,7 @@ +Bugfix: Make webdav namespace configurable across services + +The WebDAV namespace is used across various services, but it was previously +hardcoded in some of the services. This PR uses the same environment variable +to set the config correctly across the services. + +https://github.com/owncloud/ocis/pull/2198 \ No newline at end of file diff --git a/graph/pkg/config/config.go b/graph/pkg/config/config.go index 433e9e72ff..b2f5f58bbc 100644 --- a/graph/pkg/config/config.go +++ b/graph/pkg/config/config.go @@ -65,15 +65,16 @@ type Reva struct { // Config combines all available configuration parts. type Config struct { - File string - Log Log - Debug Debug - HTTP HTTP - Server Server - Tracing Tracing - Ldap Ldap - OpenIDConnect OpenIDConnect - Reva Reva + File string + WebdavNamespace string + Log Log + Debug Debug + HTTP HTTP + Server Server + Tracing Tracing + Ldap Ldap + OpenIDConnect OpenIDConnect + Reva Reva Context context.Context Supervised bool diff --git a/graph/pkg/flagset/flagset.go b/graph/pkg/flagset/flagset.go index c4734797a2..8b96cbf372 100644 --- a/graph/pkg/flagset/flagset.go +++ b/graph/pkg/flagset/flagset.go @@ -209,5 +209,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"REVA_GATEWAY_ADDR"}, Destination: &cfg.Reva.Address, }, + &cli.StringFlag{ + Name: "webdav-namespace", + Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"), + Usage: "Namespace prefix for the webdav endpoint", + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.WebdavNamespace, + }, } } diff --git a/graph/pkg/service/v0/drives.go b/graph/pkg/service/v0/drives.go index 943277eced..03c8761e80 100644 --- a/graph/pkg/service/v0/drives.go +++ b/graph/pkg/service/v0/drives.go @@ -43,7 +43,7 @@ func (g Graph) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) { } ctx := r.Context() - fn := "/home" + fn := g.config.WebdavNamespace client, err := g.GetClient() if err != nil { diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index d825831c75..7f8a97a81c 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -64,6 +64,7 @@ type Thumbnail struct { FileSystemStorage FileSystemStorage WebdavAllowInsecure bool RevaGateway string + WebdavNamespace string } // New initializes a new configuration with or without defaults. diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go index acf3896656..c1c68b8aa1 100644 --- a/thumbnails/pkg/flagset/flagset.go +++ b/thumbnails/pkg/flagset/flagset.go @@ -162,6 +162,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { Usage: "--thumbnail-resolution 16x16 [--thumbnail-resolution 32x32]", EnvVars: []string{"THUMBNAILS_RESOLUTIONS"}, }, + &cli.StringFlag{ + Name: "webdav-namespace", + Value: flags.OverrideDefaultString(cfg.Thumbnail.WebdavNamespace, "/home"), + Usage: "Namespace prefix for the webdav endpoint", + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.Thumbnail.WebdavNamespace, + }, } } diff --git a/thumbnails/pkg/service/v0/service.go b/thumbnails/pkg/service/v0/service.go index 227196cd9b..8c07a9babf 100644 --- a/thumbnails/pkg/service/v0/service.go +++ b/thumbnails/pkg/service/v0/service.go @@ -29,7 +29,8 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { logger.Fatal().Err(err).Msg("resolutions not configured correctly") } svc := Thumbnail{ - serviceID: options.Config.Server.Namespace + "." + options.Config.Server.Name, + serviceID: options.Config.Server.Namespace + "." + options.Config.Server.Name, + webdavNamespace: options.Config.Thumbnail.WebdavNamespace, manager: thumbnail.NewSimpleManager( resolutions, options.ThumbnailStorage, @@ -46,12 +47,13 @@ func NewService(opts ...Option) v0proto.ThumbnailServiceHandler { // Thumbnail implements the GRPC handler. type Thumbnail struct { - serviceID string - manager thumbnail.Manager - webdavSource imgsource.Source - cs3Source imgsource.Source - logger log.Logger - cs3Client gateway.GatewayAPIClient + serviceID string + webdavNamespace string + manager thumbnail.Manager + webdavSource imgsource.Source + cs3Source imgsource.Source + logger log.Logger + cs3Client gateway.GatewayAPIClient } // GetThumbnail retrieves a thumbnail for an image @@ -160,7 +162,7 @@ func (g Thumbnail) handleWebdavSource(ctx context.Context, req *v0proto.GetThumb statPath = path.Join("/public", src.PublicLinkToken, req.Filepath) } else { auth = src.RevaAuthorization - statPath = path.Join("/home", req.Filepath) + statPath = path.Join(g.webdavNamespace, req.Filepath) } sRes, err := g.stat(statPath, auth) if err != nil { diff --git a/webdav/pkg/config/config.go b/webdav/pkg/config/config.go index 9cb6e08da0..16fc4618b8 100644 --- a/webdav/pkg/config/config.go +++ b/webdav/pkg/config/config.go @@ -49,6 +49,7 @@ type Config struct { Tracing Tracing Service Service OcisPublicURL string + WebdavNamespace string Context context.Context Supervised bool diff --git a/webdav/pkg/flagset/flagset.go b/webdav/pkg/flagset/flagset.go index d60bed265e..0d8a29b955 100644 --- a/webdav/pkg/flagset/flagset.go +++ b/webdav/pkg/flagset/flagset.go @@ -148,6 +148,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"}, Destination: &cfg.OcisPublicURL, }, + &cli.StringFlag{ + Name: "webdav-namespace", + Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"), + Usage: "Namespace prefix for the /webdav endpoint", + EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"}, + Destination: &cfg.WebdavNamespace, + }, } } diff --git a/webdav/pkg/service/v0/service.go b/webdav/pkg/service/v0/service.go index ee253cf42d..de5125e1d2 100644 --- a/webdav/pkg/service/v0/service.go +++ b/webdav/pkg/service/v0/service.go @@ -89,7 +89,7 @@ func (g Webdav) Thumbnail(w http.ResponseWriter, r *http.Request) { Height: tr.Height, Source: &thumbnails.GetThumbnailRequest_Cs3Source{ Cs3Source: &thumbnails.CS3Source{ - Path: path.Join("/home", tr.Filepath), + Path: path.Join(g.config.WebdavNamespace, tr.Filepath), Authorization: t, }, },