Skip to content

Commit

Permalink
Remove hardcoded originUrl
Browse files Browse the repository at this point in the history
This commit removes the hardcoded origin url and instead makes the value configurable
via the pelican config file. Specifying an origin url is required to serve an origin,
and the command `pelican origin serve` will fail unless the value is set. It will also
fail if the configured origin url specifies a port that doesn't match the port passed
via the `-p` flag.
  • Loading branch information
jhiemstrawisc committed Sep 11, 2023
1 parent 3bec835 commit 5ccc980
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 24 additions & 0 deletions cmd/origin_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"net/url"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -355,6 +356,29 @@ func checkDefaults() error {
return err
}

// Check that OriginUrl is defined in the config file. Make sure it parses.
// Fail if either condition isn't met, although note that url.Parse doesn't
// generate errors for many things that are not recognizable urls.
originUrlStr := viper.GetString("OriginUrl")
if originUrlStr == "" {
return errors.New("OriginUrl must be configured to serve an origin")
}
originUrlParsed, err := url.Parse(originUrlStr)
if err != nil {
return errors.Wrap(err, "Could not parse the provided OriginUrl")
}

if originUrlParsed.Port() == "" {
// No port was specified, let's tack on whatever was passed in the
// command line argument
viper.Set("OriginUrl", originUrlParsed.String()+":"+viper.GetString("WebPort"))
} else if originUrlParsed.Port() != viper.GetString("WebPort") {
// The web port configured via the config file and the webport configured
// via commandline don't match. Perhaps the user is confused?
return errors.New("Mismatched webports: from command line: " + viper.GetString("WebPort") +
", from config file: " + originUrlParsed.Port() + ". Please ensure these match")
}

return nil
}

Expand Down
7 changes: 5 additions & 2 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ func AdvertiseOrigin() error {
if name == "" {
return errors.New("Origin name isn't set")
}

// TODO: waiting on a different branch to merge origin URL generation
originUrl := "https://localhost:8444"
// The checkdefaults func that runs before the origin is served checks for and
// parses the originUrl, so it should be safe to just grab it as a string here.
originUrl := viper.GetString("OriginUrl")

// Here we instantiate the namespaceAd slice, but we still need to define the namespace
namespaceUrl, err := url.Parse(viper.GetString("NamespaceUrl"))
if err != nil {
return errors.New("Bad namespaceUrl")
return errors.Wrap(err, "Bad NamespaceUrl")
}
if namespaceUrl.String() == "" {
return errors.New("No NamespaceUrl is set")
Expand Down

0 comments on commit 5ccc980

Please sign in to comment.