Make sure that the reva frontend url has an url scheme

We have a lot of URLs in our flagset default values that don't have an
url scheme. In order to be able to make those changes over time we
introduced a helper function which appends "http://" as scheme.
This commit is contained in:
Benedikt Kulmann
2020-06-10 16:38:05 +02:00
parent fe284939a4
commit 97c190e0aa
2 changed files with 13 additions and 2 deletions
+12 -1
View File
@@ -6,6 +6,7 @@ import (
"os"
"os/signal"
"path"
"strings"
"time"
"github.com/cs3org/reva/cmd/revad/runtime"
@@ -132,7 +133,7 @@ func Frontend(cfg *config.Config) *cli.Command {
"config": map[string]interface{}{
"version": "1.8",
"website": "reva",
"host": "http://" + cfg.Reva.Frontend.URL, // TODO URLs should include the protocol
"host": urlWithScheme(cfg.Reva.Frontend.URL),
"contact": "admin@localhost",
"ssl": "false",
},
@@ -290,3 +291,13 @@ func Frontend(cfg *config.Config) *cli.Command {
},
}
}
// urlWithScheme checks if the given string is prefixed with "http". If it is not, "http://" will be added as prefix.
// As we can't tell if http or https should be the preferred scheme, the correct approach would be to fail on urls
// without scheme. As long as we have default urls in our flagsets which don't have a scheme, this is a feasible workaround.
func urlWithScheme(str string) string {
if !strings.HasPrefix(str, "http") {
str = "http://" + str
}
return str
}
+1 -1
View File
@@ -108,7 +108,7 @@ func Gateway(cfg *config.Config) *cli.Command {
"link_grants_file": cfg.Reva.Gateway.LinkGrants,
// other
"disable_home_creation_on_login": cfg.Reva.Gateway.DisableHomeCreationOnLogin,
"datagateway": cfg.Reva.Frontend.URL,
"datagateway": urlWithScheme(cfg.Reva.Frontend.URL),
"transfer_shared_secret": cfg.Reva.TransferSecret,
"transfer_expires": cfg.Reva.TransferExpires,
},