From d2c9a5da29c1646c87ad9fc0e122cb89ea57c57f Mon Sep 17 00:00:00 2001 From: francisco souza <108725+fsouza@users.noreply.github.com> Date: Sat, 27 May 2023 12:23:56 -0400 Subject: [PATCH] internal/config: always have an externalURL This is a regression introduced in #1159: when default parameters are used, the external URL would be empty, breaking resumable uploads. Fixes #1166. Fixes #1170. --- internal/config/config.go | 10 +++++++--- internal/config/config_test.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index ac307f4654..3302b1778e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -58,7 +58,7 @@ func Load(args []string) (Config, error) { var cfg Config var allowedCORSHeaders string var eventList string - var givenLogLevel string + var logLevel string fs := flag.NewFlagSet("fake-gcs-server", flag.ContinueOnError) fs.StringVar(&cfg.backend, "backend", filesystemBackend, "storage backend (memory or filesystem)") @@ -78,14 +78,14 @@ func Load(args []string) (Config, error) { fs.StringVar(&cfg.bucketLocation, "location", "US-CENTRAL1", "location for buckets") fs.StringVar(&cfg.CertificateLocation, "cert-location", "", "location for server certificate") fs.StringVar(&cfg.PrivateKeyLocation, "private-key-location", "", "location for private key") - fs.StringVar(&givenLogLevel, "log-level", "info", "level for logging. Options same as for logrus: trace, debug, info, warn, error, fatal, and panic") + fs.StringVar(&logLevel, "log-level", "info", "level for logging. Options same as for logrus: trace, debug, info, warn, error, fatal, and panic") err := fs.Parse(args) if err != nil { return cfg, err } - cfg.LogLevel, err = logrus.ParseLevel(givenLogLevel) + cfg.LogLevel, err = logrus.ParseLevel(logLevel) if err != nil { return cfg, err } @@ -97,6 +97,10 @@ func Load(args []string) (Config, error) { cfg.event.list = strings.Split(eventList, ",") } + if cfg.externalURL == "" { + cfg.externalURL = fmt.Sprintf("%s://%s:%d", cfg.Scheme, cfg.Host, cfg.Port) + } + return cfg, cfg.validate() } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 4c7aece263..9e33018ff4 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -68,7 +68,7 @@ func TestLoadConfig(t *testing.T) { backend: "filesystem", fsRoot: "/storage", publicHost: "storage.googleapis.com", - externalURL: "", + externalURL: "https://0.0.0.0:4443", allowedCORSHeaders: nil, Host: "0.0.0.0", Port: 4443,