From aace2cb3b6e210145d8db5c1c3ba4b049f085518 Mon Sep 17 00:00:00 2001 From: Giuseppe Lo Presti Date: Wed, 26 Apr 2023 09:56:18 +0200 Subject: [PATCH] Renamed config to discovery and moved real config to ocm.go --- .../services/ocmd/{config.go => discovery.go} | 40 ++++++++----------- internal/http/services/ocmd/ocm.go | 27 ++++++++----- 2 files changed, 32 insertions(+), 35 deletions(-) rename internal/http/services/ocmd/{config.go => discovery.go} (69%) diff --git a/internal/http/services/ocmd/config.go b/internal/http/services/ocmd/discovery.go similarity index 69% rename from internal/http/services/ocmd/config.go rename to internal/http/services/ocmd/discovery.go index 369715cb65..891f914cf9 100644 --- a/internal/http/services/ocmd/config.go +++ b/internal/http/services/ocmd/discovery.go @@ -26,7 +26,7 @@ import ( "github.com/cs3org/reva/pkg/appctx" ) -type configData struct { +type discoveryData struct { Enabled bool `json:"enabled" xml:"enabled"` APIVersion string `json:"apiVersion" xml:"apiVersion"` Endpoint string `json:"endPoint" xml:"endPoint"` @@ -41,48 +41,40 @@ type resourceTypes struct { Protocols map[string]string `json:"protocols"` } -type configHandler struct { - c configData +type discoHandler struct { + d discoveryData } -func (h *configHandler) init(c *config) { - h.c = c.Config - h.c.Enabled = true - h.c.APIVersion = "1.1.0" - if len(c.Prefix) > 0 { - h.c.Endpoint = fmt.Sprintf("https://%s/%s", c.Host, c.Prefix) - } else { - h.c.Endpoint = fmt.Sprintf("https://%s", c.Host) - } - h.c.Provider = c.Provider - if c.Provider == "" { - h.c.Provider = "reva" - } +func (h *discoHandler) init(c *config) { + h.d.Enabled = true + h.d.APIVersion = "1.1.0" + h.d.Endpoint = fmt.Sprintf("%s/%s", c.Endpoint, c.Prefix) + h.d.Provider = c.Provider rtProtos := map[string]string{} // webdav is always enabled - rtProtos["webdav"] = fmt.Sprintf("https://%s/remote.php/dav/%s", c.Host, c.Prefix) + rtProtos["webdav"] = fmt.Sprintf("%s/remote.php/dav/%s", c.Endpoint, c.Prefix) if c.EnableWebApp { - rtProtos["webapp"] = fmt.Sprintf("https://%s/external/sciencemesh", c.Host) + rtProtos["webapp"] = fmt.Sprintf("%s/external/sciencemesh", c.Endpoint) } if c.EnableDataTx { - rtProtos["datatx"] = fmt.Sprintf("https://%s/remote.php/dav/%s", c.Host, c.Prefix) + rtProtos["datatx"] = fmt.Sprintf("%s/remote.php/dav/%s", c.Endpoint, c.Prefix) } - h.c.ResourceTypes = []resourceTypes{{ + h.d.ResourceTypes = []resourceTypes{{ 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"} + h.d.Capabilities = []string{"/invite-accepted"} } -// Send sends the configuration to the caller. -func (h *configHandler) Send(w http.ResponseWriter, r *http.Request) { +// Send sends the discovery info to the caller. +func (h *discoHandler) Send(w http.ResponseWriter, r *http.Request) { log := appctx.GetLogger(r.Context()) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - indentedConf, _ := json.MarshalIndent(h.c, "", " ") + indentedConf, _ := json.MarshalIndent(h.d, "", " ") if _, err := w.Write(indentedConf); err != nil { log.Err(err).Msg("Error writing to ResponseWriter") } diff --git a/internal/http/services/ocmd/ocm.go b/internal/http/services/ocmd/ocm.go index a67e4975da..f91f29c4ae 100644 --- a/internal/http/services/ocmd/ocm.go +++ b/internal/http/services/ocmd/ocm.go @@ -34,14 +34,13 @@ 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"` + Prefix string `mapstructure:"prefix"` + GatewaySvc string `mapstructure:"gatewaysvc"` + Endpoint string `mapstructure:"endpoint"` + Provider string `mapstructure:"provider"` + EnableWebApp bool `mapstructure:"enable_webapp"` + EnableDataTx bool `mapstructure:"enable_datatx"` + ExposeRecipientDisplayName bool `mapstructure:"expose_recipient_display_name"` } func (c *config) init() { @@ -50,6 +49,12 @@ func (c *config) init() { if c.Prefix == "" { c.Prefix = "ocm" } + if c.Endpoint == "" { + c.Endpoint = "http://localhost" + } + if c.Provider == "" { + c.Provider = "reva" + } } type svc struct { @@ -80,12 +85,12 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) } func (s *svc) routerInit() error { - configHandler := new(configHandler) + discoHandler := new(discoHandler) sharesHandler := new(sharesHandler) notificationsHandler := new(notificationsHandler) invitesHandler := new(invitesHandler) - configHandler.init(s.Conf) + discoHandler.init(s.Conf) if err := sharesHandler.init(s.Conf); err != nil { return err } @@ -94,7 +99,7 @@ func (s *svc) routerInit() error { return err } - s.router.Get("/ocm-provider", configHandler.Send) + s.router.Get("/ocm-provider", discoHandler.Send) s.router.Post("/shares", sharesHandler.CreateShare) s.router.Post("/notifications", notificationsHandler.SendNotification) s.router.Post("/invite-accepted", invitesHandler.AcceptInvite)