Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#1071 from haoming29/fix-dir-topo-u…
Browse files Browse the repository at this point in the history
…rl-broken

Fix broken URLs of namespaces from the topology at the director
  • Loading branch information
turetske authored Apr 9, 2024
2 parents a78aa24 + d97ebf4 commit e91131e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions director/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package director
import (
"context"
"net/url"
"strings"
"time"

"github.com/pkg/errors"
Expand All @@ -37,29 +38,35 @@ func parseServerAd(server utils.Server, serverType server_structs.ServerType) se
serverAd.Name = server.Resource

serverAd.Writes = param.Origin_EnableWrites.GetBool()
// url.Parse requires that the scheme be present before the hostname,
// but endpoints do not have a scheme. As such, we need to add one for the.
// correct parsing. Luckily, we don't use this anywhere else (it's just to
// make the url.Parse function behave as expected)
if !strings.HasPrefix(server.Endpoint, "http") { // just in case there's already an http(s) tacked in front
// Setting the scheme to http (and not https) in order to work with topology public caches and origins
server.Endpoint = "http://" + server.Endpoint
}
serverUrl, err := url.Parse(server.Endpoint)
if err != nil {
log.Warningf("Namespace JSON returned server %s with invalid unauthenticated URL %s",
server.Resource, server.Endpoint)
}
// Setting the scheme to http (and not https) in order to work with topology public caches and origins
serverUrl.Scheme = "http"
serverAd.URL = *serverUrl

if server.AuthEndpoint != "" {
if !strings.HasPrefix(server.AuthEndpoint, "http") { // just in case there's already an http(s) tacked in front
server.AuthEndpoint = "https://" + server.AuthEndpoint
}
serverAuthUrl, err := url.Parse(server.AuthEndpoint)
if err != nil {
log.Warningf("Namespace JSON returned server %s with invalid authenticated URL %s",
server.Resource, server.AuthEndpoint)
}

serverAuthUrl.Scheme = "https"

serverAd.AuthURL = *serverAuthUrl
}

// We will leave serverAd.WebURL as empty when fetched from topology

return serverAd
}

Expand Down

0 comments on commit e91131e

Please sign in to comment.