Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul config names #182

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
HEAD=$(git rev-parse HEAD)
git reset --hard ${{ github.event.pull_request.base.sha }}
make web-build
go generate ./...
go test -coverpkg=./... -coverprofile=base_coverage.out -covermode=count ./...
go tool cover -func=base_coverage.out > unit-base.txt
git reset --hard $HEAD
Expand Down
14 changes: 7 additions & 7 deletions client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import (

grab "github.com/cavaliercoder/grab"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/studio-b12/gowebdav"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"

"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/namespaces"
"github.com/pelicanplatform/pelican/param"
)

var p = mpb.New()
Expand Down Expand Up @@ -107,15 +107,15 @@ func IsProxyEnabled() bool {
if _, isSet := os.LookupEnv("http_proxy"); !isSet {
return false
}
if viper.IsSet("DisableHttpProxy") {
if param.Client_DisableHttpProxy.GetBool() {
return false
}
return true
}

// Determine whether we are allowed to skip the proxy as a fallback
func CanDisableProxy() bool {
return !viper.IsSet("DisableProxyFallback")
return !param.Client_DisableProxyFallback.GetBool()
}

// ConnectionSetupError is an error that is returned when a connection to the remote server fails
Expand Down Expand Up @@ -469,7 +469,7 @@ func DownloadHTTP(transfer TransferDetails, dest string, token string) (int64, e
// Progress ticker
progressTicker := time.NewTicker(500 * time.Millisecond)
defer progressTicker.Stop()
downloadLimit := viper.GetInt("MinimumDownloadSpeed")
downloadLimit := param.Client_MinimumDownloadSpeed.GetInt()

// If we are doing a recursive, decrease the download limit by the number of likely workers ~5
if ObjectClientOptions.Recursive {
Expand Down Expand Up @@ -506,9 +506,9 @@ func DownloadHTTP(transfer TransferDetails, dest string, token string) (int64, e
)
}

stoppedTransferTimeout := viper.GetInt64("StoppedTransferTimeout")
slowTransferRampupTime := viper.GetInt64("SlowTransferRampupTime")
slowTransferWindow := viper.GetInt64("SlowTransferWindow")
stoppedTransferTimeout := int64(param.Client_StoppedTransferTimeout.GetInt())
slowTransferRampupTime := int64(param.Client_SlowTransferRampupTime.GetInt())
slowTransferWindow := int64(param.Client_SlowTransferWindow.GetInt())
var previousCompletedBytes int64 = 0
var startBelowLimit int64 = 0
var previousCompletedTime = time.Now()
Expand Down
8 changes: 4 additions & 4 deletions client/handle_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func TestNewTransferDetailsEnv(t *testing.T) {

func TestSlowTransfers(t *testing.T) {
// Adjust down some timeouts to speed up the test
viper.Set("SlowTransferWindow", 5)
viper.Set("SlowTransferRampupTime", 10)
viper.Set("Client.SlowTransferWindow", 5)
viper.Set("Client.SlowTransferRampupTime", 10)

channel := make(chan bool)
slowDownload := 1024 * 10 // 10 KiB/s < 100 KiB/s
Expand Down Expand Up @@ -201,8 +201,8 @@ func TestSlowTransfers(t *testing.T) {
// Test stopped transfer
func TestStoppedTransfer(t *testing.T) {
// Adjust down the timeouts
viper.Set("StoppedTransferTimeout", 3)
viper.Set("SlowTransferRampupTime", 100)
viper.Set("Client.StoppedTransferTimeout", 3)
viper.Set("Client.SlowTransferRampupTime", 100)

channel := make(chan bool)
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
10 changes: 5 additions & 5 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func CheckOSDF(destination string, methods []string) (remoteSize uint64, err err
federationUrl, _ := url.Parse(dest_uri.String())
federationUrl.Scheme = "https"
federationUrl.Path = ""
viper.Set("FederationURL", federationUrl.String())
viper.Set("Federation.DiscoveryUrl", federationUrl.String())
err = config.DiscoverFederation()
if err != nil {
return 0, err
Expand Down Expand Up @@ -405,7 +405,7 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
federationUrl, _ := url.Parse(source_url.String())
federationUrl.Scheme = "https"
federationUrl.Path = ""
viper.Set("FederationURL", federationUrl.String())
viper.Set("Federation.DiscoveryUrl", federationUrl.String())
err = config.DiscoverFederation()
if err != nil {
return 0, err
Expand All @@ -420,7 +420,7 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
federationUrl, _ := url.Parse(dest_url.String())
federationUrl.Scheme = "https"
federationUrl.Path = ""
viper.Set("FederationURL", federationUrl.String())
viper.Set("Federation.DiscoveryUrl", federationUrl.String())
err = config.DiscoverFederation()
if err != nil {
return 0, err
Expand Down Expand Up @@ -474,8 +474,8 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
sourceFile = "/" + sourceFile
}

OSDFDirectorUrl := param.DirectorUrl.GetString()
useOSDFDirector := viper.IsSet("DirectorURL")
OSDFDirectorUrl := param.Federation_DirectorUrl.GetString()
useOSDFDirector := viper.IsSet("Federation.DirectorURL")

var ns namespaces.Namespace
if useOSDFDirector {
Expand Down
2 changes: 1 addition & 1 deletion client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestGetIps(t *testing.T) {
func TestGetToken(t *testing.T) {

// Need a namespace for token acquisition
defer os.Unsetenv("PELICAN_TOPOLOGYNAMESPACEURL")
defer os.Unsetenv("PELICAN_FEDERATION_TOPOLOGYNAMESPACEURL")
os.Setenv("PELICAN_TOPOLOGY_NAMESPACE_URL", "https://topology.opensciencegrid.org/osdf/namespaces")
viper.Reset()
err := config.InitClient()
Expand Down
2 changes: 1 addition & 1 deletion cmd/director_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
func generateTLSCertIfNeeded() error {

// As necessary, generate a private key and corresponding cert
if err := config.GeneratePrivateKey(param.TLSKey.GetString(), elliptic.P256()); err != nil {
if err := config.GeneratePrivateKey(param.Server_TLSKey.GetString(), elliptic.P256()); err != nil {
return err
}
if err := config.GenerateCert(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/namespace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var pubkeyPath string
var privkeyPath string

func getNamespaceEndpoint() (string, error) {
namespaceEndpoint := param.NamespaceUrl.GetString()
namespaceEndpoint := param.Federation_NamespaceUrl.GetString()
if namespaceEndpoint == "" {
return "", errors.New("No namespace registry specified; either give the federation name (-f) or specify the namespace API endpoint directly (e.g., --namespace-url=https://namespace.osg-htc.org/namespaces)")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func init() {
originCmd.AddCommand(originConfigCmd)
originCmd.AddCommand(originServeCmd)
originServeCmd.Flags().StringP("volume", "v", "", "Setting the volue to /SRC:/DEST will export the contents of /SRC as /DEST in the Pelican federation")
if err := viper.BindPFlag("ExportVolume", originServeCmd.Flags().Lookup("volume")); err != nil {
if err := viper.BindPFlag("Origin.ExportVolume", originServeCmd.Flags().Lookup("volume")); err != nil {
panic(err)
}
originServeCmd.Flags().AddFlag(portFlag)
Expand Down
80 changes: 45 additions & 35 deletions cmd/origin_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,43 @@ var (

type (
OriginConfig struct {
Multiuser bool
UseCmsd bool
UseMacaroons bool
UseVoms bool
SelfTest bool
Multiuser bool
UseCmsd bool
UseMacaroons bool
UseVoms bool
SelfTest bool
NamespacePrefix string
}

XrootdConfig struct {
XrootdOptions struct {
Port int
ManagerHost string
ManagerPort string
TLSCertificate string
TLSKey string
TLSCertDir string
TLSCACertFile string
MacaroonsKeyFile string
RobotsTxtFile string
Sitename string
SummaryMonitoringHost string
SummaryMonitoringPort int
DetailedMonitoringHost string
DetailedMonitoringPort int
XrootdRun string
RunLocation string
Authfile string
ScitokensConfig string
Mount string
NamespacePrefix string
LocalMonitoringPort int
Origin OriginConfig
}

ServerConfig struct {
TLSCertificate string
TLSKey string
TLSCACertificateDirectory string
TLSCACertificateFile string
}

XrootdConfig struct {
Server ServerConfig
Origin OriginConfig
Xrootd XrootdOptions
}
)

Expand Down Expand Up @@ -114,7 +124,7 @@ func checkXrootdEnv() error {
}

// Ensure the runtime directory exists
runtimeDir := param.XrootdRun.GetString()
runtimeDir := param.Xrootd_RunLocation.GetString()
err = config.MkdirAll(runtimeDir, 0755, uid, gid)
if err != nil {
return errors.Wrapf(err, "Unable to create runtime directory %v", runtimeDir)
Expand All @@ -132,7 +142,7 @@ func checkXrootdEnv() error {
}

// If we use "volume mount" style options, configure the export directories.
volumeMount := viper.GetString("ExportVolume")
volumeMount := param.Origin_ExportVolume.GetString()
if volumeMount != "" {
volumeMount, err = filepath.Abs(volumeMount)
if err != nil {
Expand Down Expand Up @@ -163,10 +173,10 @@ func checkXrootdEnv() error {
if err != nil {
return errors.Wrapf(err, "Failed to create export symlink")
}
viper.Set("NamespacePrefix", volumeMountDst)
viper.Set("Origin.NamespacePrefix", volumeMountDst)
} else {
mountPath := viper.GetString("Mount")
namespacePrefix := viper.GetString("NamespacePrefix")
mountPath := param.Xrootd_Mount.GetString()
namespacePrefix := param.Origin_NamespacePrefix.GetString()
if mountPath == "" || namespacePrefix == "" {
return errors.New(`Export information was not provided.
Add command line flag:
Expand Down Expand Up @@ -197,9 +207,9 @@ to export the directory /mnt/foo to the path /bar in the data federation`)
return errors.Wrapf(err, "Failed to create export symlink")
}
}
viper.Set("Mount", exportPath)
viper.Set("Xrootd.Mount", exportPath)

if viper.GetBool("Origin.SelfTest") {
if param.Origin_SelfTest.GetBool() {
if err := origin_ui.ConfigureXrootdMonitoringDir(); err != nil {
return err
}
Expand All @@ -210,7 +220,7 @@ to export the directory /mnt/foo to the path /bar in the data federation`)
}

// If no robots.txt, create a ephemeral one for xrootd to use
robotsTxtFile := param.RobotsTxtFile.GetString()
robotsTxtFile := param.Xrootd_RobotsTxtFile.GetString()
if _, err := os.Open(robotsTxtFile); err != nil {
if errors.Is(err, os.ErrNotExist) {
newPath := filepath.Join(runtimeDir, "robots.txt")
Expand All @@ -227,14 +237,14 @@ to export the directory /mnt/foo to the path /bar in the data federation`)
if _, err := file.WriteString(robotsTxt); err != nil {
return errors.Wrap(err, "Failed to write out a default robots.txt file")
}
viper.Set("RobotsTxtFile", newPath)
viper.Set("Xrootd.RobotsTxtFile", newPath)
} else {
return err
}
}

// If macaroons secret does not exist, create one
macaroonsSecret := viper.GetString("MacaroonsKeyFile")
macaroonsSecret := param.Xrootd_MacaroonsKeyFile.GetString()
if _, err := os.Open(macaroonsSecret); err != nil {
if errors.Is(err, os.ErrNotExist) {
err = config.MkdirAll(path.Dir(macaroonsSecret), 0755, -1, gid)
Expand Down Expand Up @@ -266,7 +276,7 @@ to export the directory /mnt/foo to the path /bar in the data federation`)
}

// If the authfile or scitokens.cfg does not exist, create one
authfile := viper.GetString("Authfile")
authfile := param.Xrootd_Authfile.GetString()
err = config.MkdirAll(path.Dir(authfile), 0755, -1, gid)
if err != nil {
return errors.Wrapf(err, "Unable to create directory %v",
Expand Down Expand Up @@ -305,7 +315,7 @@ func checkConfigFileReadable(fileName string, errMsg string) error {
}

func checkDefaults() error {
requiredConfigs := []string{"TLSCertificate", "TLSKey", "XrootdRun", "RobotsTxtFile"}
requiredConfigs := []string{"Server.TLSCertificate", "Server.TLSKey", "Xrootd.RunLocation", "Xrootd.RobotsTxtFile"}
for _, configName := range requiredConfigs {
mgr := viper.GetString(configName) // TODO: Remove direct access once all parameters are generated
if mgr == "" {
Expand All @@ -314,7 +324,7 @@ func checkDefaults() error {
}
}

if managerHost := viper.GetString("ManagerHost"); managerHost == "" {
if managerHost := param.Xrootd_ManagerHost.GetString(); managerHost == "" {
log.Debug("No manager host specified for the cmsd process in origin; assuming no xrootd protocol support")
viper.SetDefault("Origin.UseCmsd", false)
metrics.DeleteComponentHealthStatus("cmsd")
Expand All @@ -323,19 +333,19 @@ func checkDefaults() error {
}

// As necessary, generate a private key and corresponding cert
if err := config.GeneratePrivateKey(param.TLSKey.GetString(), elliptic.P256()); err != nil {
if err := config.GeneratePrivateKey(param.Server_TLSKey.GetString(), elliptic.P256()); err != nil {
return err
}
if err := config.GenerateCert(); err != nil {
return err
}

// TODO: Could upgrade this to a check for a cert in the file...
if err := checkConfigFileReadable(param.TLSCertificate.GetString(),
if err := checkConfigFileReadable(param.Server_TLSCertificate.GetString(),
"A TLS certificate is required to serve HTTPS"); err != nil {
return err
}
if err := checkConfigFileReadable(param.TLSKey.GetString(),
if err := checkConfigFileReadable(param.Server_TLSKey.GetString(),
"A TLS key is required to serve HTTPS"); err != nil {
return err
}
Expand All @@ -347,7 +357,7 @@ func checkDefaults() error {
// 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")
originUrlStr := param.Origin_Url.GetString()
if originUrlStr == "" {
return errors.New("OriginUrl must be configured to serve an origin")
}
Expand All @@ -366,7 +376,7 @@ func configXrootd() (string, error) {
}

var xrdConfig XrootdConfig
xrdConfig.LocalMonitoringPort = -1
xrdConfig.Xrootd.LocalMonitoringPort = -1
if err := viper.Unmarshal(&xrdConfig); err != nil {
return "", err
}
Expand All @@ -383,7 +393,7 @@ func configXrootd() (string, error) {

templ := template.Must(template.New("xrootd.cfg").Parse(xrootdCfg))

xrootdRun := param.XrootdRun.GetString()
xrootdRun := param.Xrootd_RunLocation.GetString()
configPath := filepath.Join(xrootdRun, "xrootd.cfg")
file, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0640)
if err != nil {
Expand Down Expand Up @@ -425,7 +435,7 @@ func serveOrigin( /*cmd*/ *cobra.Command /*args*/, []string) error {
if err != nil {
return err
}
viper.Set("LocalMonitoringPort", monitorPort)
viper.Set("Xrootd.LocalMonitoringPort", monitorPort)

err = checkDefaults()
if err != nil {
Expand Down Expand Up @@ -462,11 +472,11 @@ func serveOrigin( /*cmd*/ *cobra.Command /*args*/, []string) error {
return err
}

if viper.GetBool("Origin.SelfTest") {
if param.Origin_SelfTest.GetBool() {
go origin_ui.PeriodicSelfTest()
}

privileged := viper.GetBool("Origin.Multiuser")
privileged := param.Origin_Multiuser.GetBool()
err = xrootd.LaunchXrootd(privileged, configPath)
if err != nil {
return err
Expand Down
Loading
Loading