From 6a62631c1a4f5b43fba713e3a84cd79cf1b960e1 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Mon, 3 Apr 2023 15:55:53 +0200 Subject: [PATCH] Adapted OCM discovery endpoint --- changelog/unreleased/ocm-discovery.md | 6 ++++ internal/http/services/ocmd/config.go | 41 ++++++++++++++++----------- internal/http/services/ocmd/ocm.go | 6 +++- 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 changelog/unreleased/ocm-discovery.md diff --git a/changelog/unreleased/ocm-discovery.md b/changelog/unreleased/ocm-discovery.md new file mode 100644 index 00000000000..7fc0da8a4f4 --- /dev/null +++ b/changelog/unreleased/ocm-discovery.md @@ -0,0 +1,6 @@ +Enhancement: new OCM discovery endpoint + +This PR implements the new OCM v1.1 specifications +for the /ocm-provider endpoint. + +https://github.com/cs3org/reva/pull/3772 diff --git a/internal/http/services/ocmd/config.go b/internal/http/services/ocmd/config.go index a8666e53f18..444b5baf272 100644 --- a/internal/http/services/ocmd/config.go +++ b/internal/http/services/ocmd/config.go @@ -29,10 +29,10 @@ import ( type configData struct { Enabled bool `json:"enabled" xml:"enabled"` APIVersion string `json:"apiVersion" xml:"apiVersion"` - Host string `json:"host" xml:"host"` Endpoint string `json:"endPoint" xml:"endPoint"` Provider string `json:"provider" xml:"provider"` ResourceTypes []resourceTypes `json:"resourceTypes" xml:"resourceTypes"` + Capabilities []string `json:"capabilities" xml:"capabilities"` } type resourceTypes struct { @@ -43,6 +43,8 @@ type resourceTypes struct { type resourceTypesProtocols struct { Webdav string `json:"webdav"` + Webapp string `json:"webapp"` + DataTx string `json:"datatx"` } type configHandler struct { @@ -51,28 +53,33 @@ type configHandler struct { func (h *configHandler) init(c *config) { h.c = c.Config - if h.c.APIVersion == "" { - h.c.APIVersion = "1.0-proposal1" - } - if h.c.Host == "" { - h.c.Host = "localhost" - } - if h.c.Provider == "" { - h.c.Provider = "cernbox" - } h.c.Enabled = true + h.c.APIVersion = "1.1.0" if len(c.Prefix) > 0 { - h.c.Endpoint = fmt.Sprintf("https://%s/%s", h.c.Host, c.Prefix) + h.c.Endpoint = fmt.Sprintf("https://%s/%s", c.Host, c.Prefix) } else { - h.c.Endpoint = fmt.Sprintf("https://%s", h.c.Host) + h.c.Endpoint = fmt.Sprintf("https://%s", c.Host) + } + h.c.Provider = c.Provider + if c.Provider == "" { + h.c.Provider = "reva" + } + rtProtos := resourceTypesProtocols{} + // webdav is always enabled + rtProtos.Webdav = fmt.Sprintf("https://%s/remote.php/dav/%s", c.Host, c.Prefix) + if c.EnableWebApp { + rtProtos.Webapp = fmt.Sprintf("https://%s/external/sciencemesh", c.Host) + } + if c.EnableDataTx { + rtProtos.DataTx = fmt.Sprintf("https://%s/remote.php/dav/%s", c.Host, c.Prefix) } h.c.ResourceTypes = []resourceTypes{{ - Name: "file", - ShareTypes: []string{"user"}, - Protocols: resourceTypesProtocols{ - Webdav: fmt.Sprintf("/%s/ocm_webdav", h.c.Provider), - }, + Name: "file", // so far we only support `file` + ShareTypes: []string{"user"}, // so far we only support `user` + Protocols: rtProtos, // expose the protocols as per configuration }} + // for now we hardcode the capabilities, as this is currently only advisory + h.c.Capabilities = []string{"/invite-accepted"} } // Send sends the configuration to the caller. diff --git a/internal/http/services/ocmd/ocm.go b/internal/http/services/ocmd/ocm.go index f998db52da7..a67e4975dac 100644 --- a/internal/http/services/ocmd/ocm.go +++ b/internal/http/services/ocmd/ocm.go @@ -36,6 +36,10 @@ func init() { type config struct { Prefix string `mapstructure:"prefix"` GatewaySvc string `mapstructure:"gatewaysvc"` + Host string `mapstructure:"host"` + Provider string `mapstructure:"provider"` + EnableWebApp bool `mapstructure:"enable_webapp"` + EnableDataTx bool `mapstructure:"enable_datatx"` Config configData `mapstructure:"config"` ExposeRecipientDisplayName bool `mapstructure:"expose_recipient_display_name"` } @@ -90,7 +94,7 @@ func (s *svc) routerInit() error { return err } - s.router.Get("/ocm-provider", configHandler.Send) // FIXME: where this endpoint is documented? + s.router.Get("/ocm-provider", configHandler.Send) s.router.Post("/shares", sharesHandler.CreateShare) s.router.Post("/notifications", notificationsHandler.SendNotification) s.router.Post("/invite-accepted", invitesHandler.AcceptInvite)