57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
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"
|
|
"git.loafle.net/overflow/overflow_probes/config"
|
|
)
|
|
|
|
func (a *auth) onNotify(method string, params []string) {
|
|
switch method {
|
|
case module.NoAuthProbeService_AcceptNoAuthProbe:
|
|
a.onNoAuthProbeAccept(params)
|
|
break
|
|
case module.NoAuthProbeService_DenyNoauthProbe:
|
|
a.onNoAuthProbeDeny(params)
|
|
break
|
|
}
|
|
|
|
}
|
|
|
|
func (a *auth) onNoAuthProbeAccept(params []string) {
|
|
var err error
|
|
probeKey := params[0]
|
|
|
|
// if lfcc.Exists(a.probeConfigPath) {
|
|
// if err = lfcc.Load(&a.probeConfig, a.probeConfigPath); nil != err {
|
|
// logging.Logger.Error(fmt.Sprintf("Auth: Loading of Probe config file[%s] failed error[%v]", a.probeConfigPath, err))
|
|
// }
|
|
// }
|
|
|
|
config.CFG.Probe.Key = &probeKey
|
|
|
|
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))
|
|
a.ShutdownChan <- true
|
|
return
|
|
}
|
|
|
|
a.acceptedChan <- true
|
|
}
|
|
|
|
func (a *auth) onNoAuthProbeDeny(params []string) {
|
|
n := time.Now()
|
|
a.noAuthConfig.DenyDate = &n
|
|
if err := lfcc.Save(a.noAuthConfig, a.noAuthConfigPath, true); nil != err {
|
|
logging.Logger.Error(fmt.Sprintf("Auth: Saving of NoAuth config file[%s] failed error[%v]", a.noAuthConfigPath, err))
|
|
a.ShutdownChan <- true
|
|
return
|
|
}
|
|
|
|
a.deniedChan <- fmt.Errorf("This probe have been denied from overFlow")
|
|
}
|