Skip to content

Commit

Permalink
Renamed config to discovery and moved real config to ocm.go
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Apr 26, 2023
1 parent dfbc6b2 commit aace2cb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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")
}
Expand Down
27 changes: 16 additions & 11 deletions internal/http/services/ocmd/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit aace2cb

Please sign in to comment.