overflow_probes/auth/on_notify.go

57 lines
1.5 KiB
Go
Raw Normal View History

2017-09-28 06:08:43 +00:00
package auth
import (
"fmt"
"time"
lfcc "git.loafle.net/commons_go/config"
"git.loafle.net/commons_go/logging"
"git.loafle.net/overflow/overflow_probes/central/api/module"
2017-09-28 10:09:33 +00:00
"git.loafle.net/overflow/overflow_probes/config"
2017-09-28 06:08:43 +00:00
)
2017-09-28 06:53:04 +00:00
func (h *authHandlers) onNotify(method string, params []string) {
2017-09-28 06:08:43 +00:00
switch method {
case module.NoAuthProbeService_AcceptNoAuthProbe:
h.onNoAuthProbeAccept(params)
break
case module.NoAuthProbeService_DenyNoauthProbe:
h.onNoAuthProbeDeny(params)
break
}
}
2017-09-28 06:53:04 +00:00
func (h *authHandlers) onNoAuthProbeAccept(params []string) {
2017-09-28 06:08:43 +00:00
var err error
2017-09-28 10:09:33 +00:00
probeKey := params[0]
2017-09-28 06:08:43 +00:00
2017-09-28 10:09:33 +00:00
// if lfcc.Exists(h.probeConfigPath) {
// if err = lfcc.Load(&h.probeConfig, h.probeConfigPath); nil != err {
// logging.Logger.Error(fmt.Sprintf("Auth: Loading of Probe config file[%s] failed error[%v]", h.probeConfigPath, err))
// }
// }
config.CFG.Probe.Key = &probeKey
2017-09-28 06:08:43 +00:00
2017-09-28 10:09:33 +00:00
if err = lfcc.Save(*config.CFG, *config.ConfigFilePath, true); nil != err {
logging.Logger.Error(fmt.Sprintf("Auth: Saving of config file[%s] failed error[%v]", *config.ConfigFilePath, err))
h.shutdownChan <- true
return
2017-09-28 06:08:43 +00:00
}
h.acceptedChan <- true
}
2017-09-28 06:53:04 +00:00
func (h *authHandlers) onNoAuthProbeDeny(params []string) {
2017-09-28 06:08:43 +00:00
n := time.Now()
h.noAuthConfig.DenyDate = &n
if err := lfcc.Save(h.noAuthConfig, h.noAuthConfigPath, true); nil != err {
logging.Logger.Error(fmt.Sprintf("Auth: Saving of NoAuth config file[%s] failed error[%v]", h.noAuthConfigPath, err))
2017-09-28 10:09:33 +00:00
h.shutdownChan <- true
return
2017-09-28 06:08:43 +00:00
}
h.deniedChan <- fmt.Errorf("This probe have been denied from overFlow")
}