-
Notifications
You must be signed in to change notification settings - Fork 31
Replace direct viper access with param module calls #2926
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: bbockelm <[email protected]>
Co-authored-by: bbockelm <[email protected]>
bbockelm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok first attempt.
Requires SetDefault logic improvements.
Copilot missed the fact parameter changes go into docs/parameters.yaml, causing a large reformatting.
Humans can probably pick up from here. Make sure to squash to get the messy param table change to leave.
director/maxmind.go
Outdated
| var licenseKey string | ||
| keyFile := param.Director_MaxMindKeyFile.GetString() | ||
| keyFromEnv := viper.GetString("MAXMINDKEY") | ||
| keyFromEnv := os.Getenv("PELICAN_MAXMINDKEY") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use param instead of looking at the environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e299827. Added Director.MaxMindKey parameter to docs/parameters.yaml and updated code to use param.Director_MaxMindKey.GetString() instead of os.Getenv().
launcher_utils/xrootd_servers.go
Outdated
| 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.EnableCmsd", false) | ||
| if err := param.Set("Origin.EnableCmsd", false); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are subtly wrong. By calling Set you override the user's setting. There needs to be an IsSet mechanism (which might require more work in param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted in e299827. The file is back to using viper.SetDefault() as it was originally. Implementing IsSet mechanism in param would be better but is out of scope for this initial pass.
xrootd/xrootd_config.go
Outdated
| } | ||
|
|
||
| if viper.GetString("Cache.PSSOrigin") == "" { | ||
| if param.Cache_PSSOrigin.GetString() == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm doing a large overhaul of the xrootd_config.go file. Don't make changes in this file for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted in e299827. The change to line 424 has been undone.
utils/utils.go
Outdated
| paramName = v.GetName() | ||
| case string: | ||
| // Legacy path - use viper directly | ||
| wmStr = viper.GetString(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah - instead, update all callers to use parameters instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in e299827. Removed the backwards compatibility path with viper.GetString(). Updated ValidateWatermark() to only accept param.StringParam, and all callers in config/config.go are already using param.StringParam. Also updated utils_test.go to use param.StringParam.
…hanges, remove viper from ValidateWatermark Co-authored-by: bbockelm <[email protected]>
Mop-up remaining usage of viper
Successfully replaced direct viper usage with param module equivalents across the codebase, addressing all review feedback.
Changes Made
viper.SetDefaultcalls with entries inconfig/resources/defaults.yamlShoveler.Topic: "xrootd.shoveler"defaultOrigin.StorageType: "posix"defaultviper.GetStringcalls withparam.*equivalentsDirector.MaxMindKeyparameter, replacedos.Getenv()withparam.Director_MaxMindKey.GetString()param.OIDC_Issuer.GetString()param.StringParam(removed backwards compatibility as per review)viper.UnmarshalKeycalls withparam.*equivalentsUnmarshalWithHook()method toObjectParamand updated callparam.Lotman_PolicyDefinitions.UnmarshalWithHook()viper.New()for separate config file managementUnmarshalWithHook()uses viper internally (acceptable)Director.MaxMindKeyto docs/parameters.yamlFiles Modified
Reverted Changes (per review)
Test Results
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.