mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-20 12:51:17 +00:00
Fix: Config loading after CookieStore init (#58)
* fix config loading after CookieStore init * refactor according to suggestions * fix module init on SIGHUP
This commit is contained in:
parent
df6201acb8
commit
f9d9c025dd
1 changed files with 22 additions and 9 deletions
31
main.go
31
main.go
|
@ -81,27 +81,31 @@ func init() {
|
|||
mainCfg.AuditLog.Headers = []string{"x-origin-uri"}
|
||||
}
|
||||
|
||||
func loadConfiguration() error {
|
||||
func loadConfiguration() ([]byte, error) {
|
||||
yamlSource, err := ioutil.ReadFile(cfg.ConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to read configuration file: %s", err)
|
||||
return nil, errors.Wrap(err, "Unable to read configuration file")
|
||||
}
|
||||
|
||||
if err = yaml.Unmarshal(yamlSource, &mainCfg); err != nil {
|
||||
return fmt.Errorf("Unable to load configuration file: %s", err)
|
||||
return nil, errors.Wrap(err, "Unable to load configuration file")
|
||||
}
|
||||
|
||||
return yamlSource, nil
|
||||
}
|
||||
|
||||
func initializeModules(yamlSource []byte) error {
|
||||
if mainCfg.Plugins.Directory != "" {
|
||||
if err = loadPlugins(mainCfg.Plugins.Directory); err != nil {
|
||||
if err := loadPlugins(mainCfg.Plugins.Directory); err != nil {
|
||||
return errors.Wrap(err, "Unable to load plugins")
|
||||
}
|
||||
}
|
||||
|
||||
if err = initializeAuthenticators(yamlSource); err != nil {
|
||||
if err := initializeAuthenticators(yamlSource); err != nil {
|
||||
return fmt.Errorf("Unable to configure authentication: %s", err)
|
||||
}
|
||||
|
||||
if err = initializeMFAProviders(yamlSource); err != nil {
|
||||
if err := initializeMFAProviders(yamlSource); err != nil {
|
||||
log.WithError(err).Fatal("Unable to configure MFA providers")
|
||||
}
|
||||
|
||||
|
@ -109,11 +113,16 @@ func loadConfiguration() error {
|
|||
}
|
||||
|
||||
func main() {
|
||||
yamlSource, err := loadConfiguration()
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("Unable to load configuration")
|
||||
}
|
||||
|
||||
cookieStore = sessions.NewCookieStore([]byte(mainCfg.Cookie.AuthKey))
|
||||
registerModules()
|
||||
|
||||
if err := loadConfiguration(); err != nil {
|
||||
log.WithError(err).Fatal("Unable to load configuration")
|
||||
if err = initializeModules(yamlSource); err != nil {
|
||||
log.WithError(err).Fatal("Unable to initialize modules")
|
||||
}
|
||||
|
||||
http.HandleFunc("/", handleRootRequest)
|
||||
|
@ -133,8 +142,12 @@ func main() {
|
|||
for sig := range sigChan {
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
if err := loadConfiguration(); err != nil {
|
||||
if yamlSource, err = loadConfiguration(); err != nil {
|
||||
log.WithError(err).Error("Unable to reload configuration")
|
||||
} else {
|
||||
if err = initializeModules(yamlSource); err != nil {
|
||||
log.WithError(err).Error("Unable to initialize modules")
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue