MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / reload

Method reload

auth/basic.go:78–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76}
77
78func (auth *BasicAuth) reload() error {
79 var oldModTime time.Time
80 if oldPw := auth.pw.Load(); oldPw != nil {
81 oldModTime = oldPw.modTime
82 }
83
84 f, modTime, err := openIfModified(auth.pwFilename, oldModTime)
85 if err != nil {
86 return err
87 }
88 if f == nil {
89 // no changes since last modTime
90 return nil
91 }
92
93 auth.logger.Info("reloading password file from %q...", auth.pwFilename)
94 newPwFile, err := htpasswd.NewFromReader(f, htpasswd.DefaultSystems, func(parseErr error) {
95 auth.logger.Error("failed to parse line in %q: %v", auth.pwFilename, parseErr)
96 })
97 if err != nil {
98 return err
99 }
100
101 newPw := &pwFile{
102 file: newPwFile,
103 modTime: modTime,
104 }
105 auth.pw.Store(newPw)
106 auth.logger.Info("password file reloaded.")
107
108 return nil
109}
110
111func (auth *BasicAuth) reloadLoop(interval time.Duration) {
112 ticker := time.NewTicker(interval)

Callers 2

NewBasicFileAuthFunction · 0.95
reloadLoopMethod · 0.95

Calls 3

openIfModifiedFunction · 0.85
InfoMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected