Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support full URL endpoints in ocm-provider #4189

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/ocm-provider-root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: support full URL endpoints in ocm-provider

This patch enables a reva server to properly show any configured
endpoint route in all relevant properties exposed by /ocm-provider.
This allows reverse proxy configurations of the form https://server/route
to be supported for the OCM discovery mechanism.

https://github.com/cs3org/reva/pull/4189
46 changes: 27 additions & 19 deletions internal/http/services/ocmprovider/ocmprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ package ocmprovider
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"path/filepath"

"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rhttp/global"
Expand All @@ -37,7 +38,7 @@ func init() {

type config struct {
OCMPrefix string `mapstructure:"ocm_prefix" docs:"ocm;The prefix URL where the OCM API is served."`
Endpoint string `mapstructure:"endpoint" docs:"This host's URL. If it's not configured, it is assumed OCM is not available."`
Endpoint string `mapstructure:"endpoint" docs:"This host's full URL. If it's not configured, it is assumed OCM is not available."`
Provider string `mapstructure:"provider" docs:"reva;A friendly name that defines this service."`
WebdavRoot string `mapstructure:"webdav_root" docs:"/remote.php/dav/ocm;The root URL of the WebDAV endpoint to serve OCM shares."`
WebappRoot string `mapstructure:"webapp_root" docs:"/external/sciencemesh;The root URL to serve Web apps via OCM."`
Expand Down Expand Up @@ -86,33 +87,40 @@ func (c *config) ApplyDefaults() {
}

func (c *config) prepare() *DiscoveryData {
// generates the (static) data structure to be exposed by /ocm-provider
// generates the (static) data structure to be exposed by /ocm-provider:
// first prepare an empty and disabled payload
d := &DiscoveryData{}
d.Enabled = false
d.Endpoint = ""
d.APIVersion = OCMAPIVersion
d.Provider = c.Provider
d.ResourceTypes = []resourceTypes{{
Name: "file",
ShareTypes: []string{},
Protocols: map[string]string{},
}}
d.Capabilities = []string{}

if c.Endpoint == "" {
d.Enabled = false
d.Endpoint = ""
d.APIVersion = OCMAPIVersion
d.Provider = c.Provider
d.ResourceTypes = []resourceTypes{{
Name: "file",
ShareTypes: []string{},
Protocols: map[string]string{},
}}
d.Capabilities = []string{}
return d
}

endpointURL, err := url.Parse(c.Endpoint)
if err != nil {
return d
}

// now prepare the enabled one
d.Enabled = true
d.APIVersion = OCMAPIVersion
d.Endpoint = fmt.Sprintf("%s/%s", c.Endpoint, c.OCMPrefix)
d.Provider = c.Provider
d.Endpoint, _ = url.JoinPath(c.Endpoint, c.OCMPrefix)
rtProtos := map[string]string{}
// webdav is always enabled
rtProtos["webdav"] = c.WebdavRoot
rtProtos["webdav"] = filepath.Join(endpointURL.Path, c.WebdavRoot)
if c.EnableWebapp {
rtProtos["webapp"] = c.WebappRoot
rtProtos["webapp"] = filepath.Join(endpointURL.Path, c.WebappRoot)
}
if c.EnableDatatx {
rtProtos["datatx"] = c.WebdavRoot
rtProtos["datatx"] = filepath.Join(endpointURL.Path, c.WebdavRoot)
}
d.ResourceTypes = []resourceTypes{{
Name: "file", // so far we only support `file`
Expand Down