Skip to content

Commit

Permalink
Handle trailing / for all storage prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhiemstrawisc committed Oct 16, 2024
1 parent d84b720 commit d1569c5
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions server_utils/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -418,33 +422,40 @@ 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
if strings.HasSuffix(export.StoragePrefix, "/") {
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,
}

Expand Down

0 comments on commit d1569c5

Please sign in to comment.