overflow_probes/auth/service/NoAuthProbeService.go

78 lines
2.5 KiB
Go
Raw Normal View History

2017-12-01 13:01:46 +00:00
package rpc
import (
2017-12-01 16:14:22 +00:00
"fmt"
"time"
"git.loafle.net/commons_go/logging"
cc "git.loafle.net/commons_go/config"
ooccn "git.loafle.net/overflow/overflow_commons_go/config/noauthprobe"
oocmn "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe"
2017-12-01 13:01:46 +00:00
noauthprobeM "git.loafle.net/overflow/overflow_commons_go/modules/noauthprobe/model"
probeM "git.loafle.net/overflow/overflow_commons_go/modules/probe/model"
2017-12-01 16:14:22 +00:00
oopai "git.loafle.net/overflow/overflow_probes/auth/info"
"git.loafle.net/overflow/overflow_probes/config"
2017-12-01 13:01:46 +00:00
)
type NoAuthProbeService struct {
2017-12-01 16:14:22 +00:00
DoneChan chan error
ConfigPath string
Config ooccn.NoAuthProbeConfig
2017-12-01 13:01:46 +00:00
}
func (s *NoAuthProbeService) Accept(probe *probeM.Probe) {
2017-12-01 16:14:22 +00:00
config.Config.Probe.Key = &probe.ProbeKey
if err := cc.Save(*config.Config, *config.ConfigFilePath, true); nil != err {
s.DoneChan <- fmt.Errorf("Auth: Saving of config file[%s] failed error[%v]", *config.ConfigFilePath, err)
return
}
s.DoneChan <- nil
2017-12-01 13:01:46 +00:00
}
func (s *NoAuthProbeService) Deny(noAuthProbe *noauthprobeM.NoAuthProbe) {
2017-12-01 16:14:22 +00:00
n := time.Now()
s.Config.DenyDate = &n
if err := cc.Save(s.Config, s.ConfigPath, true); nil != err {
s.DoneChan <- fmt.Errorf("Auth: Saving of NoAuth config file[%s] failed error[%v]", s.ConfigPath, err)
return
}
s.DoneChan <- nil
}
func (s *NoAuthProbeService) GetRequestHeader() map[string][]string {
header := make(map[string][]string)
switch s.Config.State() {
case ooccn.NoAuthProbeStateTypeNotRegisterd:
header[oocmn.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{oocmn.HTTPRequestHeaderValue_NoAuthProbe_Method_Regist}
header[oocmn.HTTPRequestHeaderKey_NoAuthProbe_Info] = []string{s.GetRegisterRequestHeader()}
case ooccn.NoAuthProbeStateTypeRegisterd:
header[oocmn.HTTPRequestHeaderKey_NoAuthProbe_Method] = []string{oocmn.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect}
header[oocmn.HTTPRequestHeaderKey_NoAuthProbe_TempProbeKey] = []string{oocmn.HTTPRequestHeaderValue_NoAuthProbe_Method_Connect}
}
return header
2017-12-01 13:01:46 +00:00
}
2017-12-01 16:14:22 +00:00
func (s *NoAuthProbeService) GetRegisterRequestHeader() string {
i, err := oopai.GetRegistHeader()
if nil != err {
logging.Logger().Error(fmt.Sprintf("Auth: Gathering system information has been failed %v", err))
}
return i
}
func (s *NoAuthProbeService) SetTempProbeKey(tempProbeKey string) {
s.Config.TempKey = &tempProbeKey
if err := cc.Save(s.Config, s.ConfigPath, true); nil != err {
s.DoneChan <- fmt.Errorf("Auth: Saving of NoAuth config file[%s] failed error[%v]", s.ConfigPath, err)
return
}
}