This commit is contained in:
crusader 2018-05-10 19:18:00 +09:00
parent c479442b6f
commit 6b52a1ef57
5 changed files with 42 additions and 26 deletions

View File

@ -35,7 +35,7 @@ type NoAuthProbeService struct {
} }
func (s *NoAuthProbeService) InitService() error { func (s *NoAuthProbeService) InitService() error {
client, err := auth.New(s.HandleTempKey, s) client, err := auth.New(s.HandleResponse, s)
if nil != err { if nil != err {
return err return err
} }
@ -98,12 +98,21 @@ func (s *NoAuthProbeService) Deny() error {
return nil return nil
} }
func (s *NoAuthProbeService) HandleTempKey(tempKey string) { func (s *NoAuthProbeService) HandleResponse(method string, param string) {
logging.Logger().Infof("registered by central") switch method {
s.AuthConfig.TempKey = &tempKey case occn.HTTPResponseHeaderValue_NoAuthProbe_Method_TempProbeKey:
if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err { logging.Logger().Infof("registered by central")
logging.Logger().Error(err) s.AuthConfig.TempKey = &param
s.AuthDoneChan <- err if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err {
return logging.Logger().Error(err)
s.AuthDoneChan <- err
return
}
case occn.HTTPResponseHeaderValue_NoAuthProbe_Method_Accept:
s.Accept(param)
case occn.HTTPResponseHeaderValue_NoAuthProbe_Method_Deny:
s.Deny()
} }
} }

View File

@ -16,7 +16,7 @@ import (
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
) )
func New(tempKeyHandler func(tempKey string), services ...interface{}) (*crc.Client, error) { func New(responseHandler func(method string, param string), services ...interface{}) (*crc.Client, error) {
config := config.GetConfig() config := config.GetConfig()
if nil == config { if nil == config {
return nil, fmt.Errorf("Config is not available") return nil, fmt.Errorf("Config is not available")
@ -49,13 +49,11 @@ func New(tempKeyHandler func(tempKey string), services ...interface{}) (*crc.Cli
return header return header
} }
connector.ResponseHandler = func(res *http.Response) { connector.ResponseHandler = func(res *http.Response) {
switch authConfig.State() { responseMethod := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_Method)
case occn.AuthStateTypeNotRegisterd: responseMethodParam := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_Method_Param)
tempProbeKey := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey)
if nil != tempKeyHandler { if nil != responseHandler {
tempKeyHandler(tempProbeKey) responseHandler(responseMethod, responseMethodParam)
}
default:
} }
} }

View File

@ -12,7 +12,7 @@ import (
"git.loafle.net/overflow/probe/config" "git.loafle.net/overflow/probe/config"
) )
func New(encryptionKeyHandler func(encryptionKey string), services ...interface{}) (*crc.Client, error) { func New(responseHandler func(method string, param string), services ...interface{}) (*crc.Client, error) {
config := config.GetConfig() config := config.GetConfig()
if nil == config { if nil == config {
return nil, fmt.Errorf("Config is not available") return nil, fmt.Errorf("Config is not available")
@ -30,11 +30,14 @@ func New(encryptionKeyHandler func(encryptionKey string), services ...interface{
return header return header
} }
connector.ResponseHandler = func(res *http.Response) { connector.ResponseHandler = func(res *http.Response) {
encryptionKey := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_SetEncryptionKey) responseMethod := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_Method)
if nil != encryptionKeyHandler { responseMethodParam := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_Method_Param)
encryptionKeyHandler(encryptionKey)
if nil != responseHandler {
responseHandler(responseMethod, responseMethodParam)
} }
} }
connector.OnDisconnected = func(connector csc.Connector) { connector.OnDisconnected = func(connector csc.Connector) {
logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName()) logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName())
} }

View File

@ -40,8 +40,8 @@ func (s *DataService) DestroyService() {
} }
func (s *DataService) Metric(metric map[string]string) error { func (s *DataService) Metric(sensorConfigID string, metric map[string]string) error {
// s.DataClientService.Send("MS", sensorConfigID, metric)
logging.Logger().Debugf("Metric: %v", metric) logging.Logger().Debugf("Metric: %v", metric)
return nil return nil

View File

@ -6,10 +6,11 @@ import (
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
occp "git.loafle.net/overflow/commons-go/config/probe"
"git.loafle.net/overflow/probe/client/probe"
// For annotation // For annotation
_ "git.loafle.net/overflow/commons-go/core/annotation" _ "git.loafle.net/overflow/commons-go/core/annotation"
"git.loafle.net/overflow/probe/client/probe"
) )
var ProbeClientServiceType = reflect.TypeOf((*ProbeClientService)(nil)) var ProbeClientServiceType = reflect.TypeOf((*ProbeClientService)(nil))
@ -41,7 +42,7 @@ func (s *ProbeClientService) StartService() error {
return fmt.Errorf("ProbeClientService: StartService failed %v", err) return fmt.Errorf("ProbeClientService: StartService failed %v", err)
} }
client, err := probe.New(s.HandleEncryptionKey, s.DiscoveryService) client, err := probe.New(s.HandleResponse, s.DiscoveryService)
if nil != err { if nil != err {
return fmt.Errorf("ProbeClientService: StartService failed %v", err) return fmt.Errorf("ProbeClientService: StartService failed %v", err)
} }
@ -62,6 +63,11 @@ func (s *ProbeClientService) DestroyService() {
s.RPCClientService.DestroyService() s.RPCClientService.DestroyService()
} }
func (s *ProbeClientService) HandleEncryptionKey(encryptionKey string) { func (s *ProbeClientService) HandleResponse(method string, param string) {
s.EncryptionKey = encryptionKey switch method {
case occp.HTTPResponseHeaderValue_Probe_Method_EncryptionKey:
s.EncryptionKey = param
case occp.HTTPResponseHeaderValue_Probe_Method_Delete:
}
} }