Skip to content

Commit

Permalink
internal/config: always have an externalURL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fsouza committed May 27, 2023
1 parent d1073d0 commit d2c9a5d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand All @@ -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
}
Expand All @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d2c9a5d

Please sign in to comment.