From 97c190e0aadc83205aba9c29a26fd1d8fedd81e7 Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Wed, 10 Jun 2020 16:38:05 +0200 Subject: [PATCH] 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. --- pkg/command/frontend.go | 13 ++++++++++++- pkg/command/gateway.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/command/frontend.go b/pkg/command/frontend.go index 15789286a..e3e6b54ad 100644 --- a/pkg/command/frontend.go +++ b/pkg/command/frontend.go @@ -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 +} diff --git a/pkg/command/gateway.go b/pkg/command/gateway.go index d4802dd6c..e8f649881 100644 --- a/pkg/command/gateway.go +++ b/pkg/command/gateway.go @@ -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, },