diff --git a/server_utils/origin.go b/server_utils/origin.go index e13e59517..569a010c1 100644 --- a/server_utils/origin.go +++ b/server_utils/origin.go @@ -389,6 +389,10 @@ func GetOriginExports() ([]OriginExport, error) { return nil, err } + // clean up trailing / in the storage prefix + if strings.HasSuffix(storagePrefix, "/") { + log.Warningln("Removing trailing '/' from storage prefix", storagePrefix) + } originExport := OriginExport{ FederationPrefix: federationPrefix, StoragePrefix: storagePrefix, @@ -418,15 +422,6 @@ func GetOriginExports() ([]OriginExport, error) { // Assume there's only one export export := tmpExports[0] - capabilities := export.Capabilities - reads := capabilities.Reads || capabilities.PublicReads - viper.Set("Origin.FederationPrefix", export.FederationPrefix) - viper.Set("Origin.StoragePrefix", export.StoragePrefix) - viper.Set("Origin.EnableReads", reads) - viper.Set("Origin.EnablePublicReads", capabilities.PublicReads) - viper.Set("Origin.EnableWrites", capabilities.Writes) - viper.Set("Origin.EnableListings", capabilities.Listings) - viper.Set("Origin.EnableDirectReads", capabilities.DirectReads) // Clean up any path components that might have been added by the user to guarantee the correct // URL is constructed without duplicate or missing slashes @@ -434,17 +429,33 @@ func GetOriginExports() ([]OriginExport, error) { log.Warningln("Removing trailing '/' from storage prefix", export.StoragePrefix) export.StoragePrefix = strings.TrimSuffix(export.StoragePrefix, "/") } + if err = validateExportPaths(export.StoragePrefix, export.FederationPrefix); err != nil { return nil, err } + capabilities := export.Capabilities + reads := capabilities.Reads || capabilities.PublicReads + viper.Set("Origin.FederationPrefix", export.FederationPrefix) + viper.Set("Origin.StoragePrefix", export.StoragePrefix) + viper.Set("Origin.EnableReads", reads) + viper.Set("Origin.EnablePublicReads", capabilities.PublicReads) + viper.Set("Origin.EnableWrites", capabilities.Writes) + viper.Set("Origin.EnableListings", capabilities.Listings) + viper.Set("Origin.EnableDirectReads", capabilities.DirectReads) + originExports = []OriginExport{export} return originExports, nil } else { // we're using the simple Origin.FederationPrefix log.Infoln("Configuring single-export origin") + federationPrefix := param.Origin_FederationPrefix.GetString() + storagePrefix := param.Origin_StoragePrefix.GetString() + if strings.HasSuffix(storagePrefix, "/") { + log.Warningln("Removing trailing '/' from storage prefix", storagePrefix) + } originExport = OriginExport{ - FederationPrefix: param.Origin_FederationPrefix.GetString(), - StoragePrefix: param.Origin_StoragePrefix.GetString(), + FederationPrefix: federationPrefix, + StoragePrefix: storagePrefix, Capabilities: capabilities, }