Skip to content

Commit

Permalink
Reshuffled config options
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Apr 26, 2023
1 parent f928823 commit 5e7cb75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
32 changes: 12 additions & 20 deletions internal/http/services/ocmd/discovery.go
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 @@ -42,38 +42,30 @@ type resourceTypes struct {
}

type discoHandler struct {
c configData
d discoveryData
}

func (h *discoHandler) 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"
}
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.
Expand All @@ -82,7 +74,7 @@ func (h *discoHandler) Send(w http.ResponseWriter, r *http.Request) {

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
21 changes: 13 additions & 8 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

0 comments on commit 5e7cb75

Please sign in to comment.