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-29 12:30:27 +00:00
|
|
|
func (a *auth) onNotify(method string, params []string) {
|
2017-09-28 06:08:43 +00:00
|
|
|
switch method {
|
|
|
|
case module.NoAuthProbeService_AcceptNoAuthProbe:
|
2017-09-29 12:30:27 +00:00
|
|
|
a.onNoAuthProbeAccept(params)
|
2017-09-28 06:08:43 +00:00
|
|
|
break
|
|
|
|
case module.NoAuthProbeService_DenyNoauthProbe:
|
2017-09-29 12:30:27 +00:00
|
|
|
a.onNoAuthProbeDeny(params)
|
2017-09-28 06:08:43 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-29 12:30:27 +00:00
|
|
|
func (a *auth) 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-29 12:30:27 +00:00
|
|
|
// 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))
|
2017-09-28 10:09:33 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
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))
|
|
|
|
return
|
2017-09-28 06:08:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 10:02:38 +00:00
|
|
|
a.accepted <- true
|
2017-09-28 06:08:43 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 12:30:27 +00:00
|
|
|
func (a *auth) onNoAuthProbeDeny(params []string) {
|
2017-09-28 06:08:43 +00:00
|
|
|
n := time.Now()
|
2017-09-29 12:30:27 +00:00
|
|
|
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))
|
2017-10-12 10:02:38 +00:00
|
|
|
|
2017-09-28 10:09:33 +00:00
|
|
|
return
|
2017-09-28 06:08:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 10:02:38 +00:00
|
|
|
a.denied <- fmt.Errorf("This probe have been denied from overFlow")
|
2017-09-28 06:08:43 +00:00
|
|
|
}
|