Skip to content

Commit

Permalink
Adapted OCM discovery endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Apr 25, 2023
1 parent bf56c23 commit 6a62631
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/ocm-discovery.md
Original file line number Diff line number Diff line change
@@ -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
41 changes: 24 additions & 17 deletions internal/http/services/ocmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion internal/http/services/ocmd/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6a62631

Please sign in to comment.