mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 10:26:29 +02:00
internal/config: fix on config change
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
parent
83a30d80a5
commit
f73d3a09ac
2 changed files with 10 additions and 5 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/pomerium/pomerium/authenticate"
|
||||
|
@ -77,9 +76,7 @@ func run() error {
|
|||
defer proxy.AuthorizeClient.Close()
|
||||
}
|
||||
|
||||
go viper.WatchConfig()
|
||||
|
||||
viper.OnConfigChange(func(e fsnotify.Event) {
|
||||
opt.OnConfigChange(func(e fsnotify.Event) {
|
||||
log.Info().Str("file", e.Name).Msg("cmd/pomerium: config file changed")
|
||||
opt = config.HandleConfigUpdate(*configFile, opt, []config.OptionsUpdater{authz, proxy})
|
||||
})
|
||||
|
@ -112,7 +109,6 @@ func newAuthorizeService(opt config.Options, wg *sync.WaitGroup) (*authorize.Aut
|
|||
if !config.IsAuthorize(opt.Services) {
|
||||
return nil, nil
|
||||
}
|
||||
log.Info().Interface("opts", opt).Msg("newAuthorizeService")
|
||||
service, err := authorize.New(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/pomerium/pomerium/internal/cryptutil"
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/internal/telemetry/metrics"
|
||||
|
@ -220,6 +221,7 @@ func NewOptionsFromConfig(configFile string) (*Options, error) {
|
|||
log.Warn().Err(err).Msg("internal/config: could not parse config checksum into decimal")
|
||||
}
|
||||
metrics.SetConfigChecksum(o.Services, checksumDec)
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
|
@ -281,6 +283,13 @@ func (o *Options) parsePolicy() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// OnConfigChange starts a go routine and watches for any changes. If any are
|
||||
// detected, via an fsnotify event the provided function is run.
|
||||
func (o *Options) OnConfigChange(run func(in fsnotify.Event)) {
|
||||
go o.viper.WatchConfig()
|
||||
o.viper.OnConfigChange(run)
|
||||
}
|
||||
|
||||
func (o *Options) viperUnmarshalKey(key string, rawVal interface{}) error {
|
||||
return o.viper.UnmarshalKey(key, &rawVal)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue