From 6b52a1ef57598e4a7c1713da43f867f8b2a7f761 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 10 May 2018 19:18:00 +0900 Subject: [PATCH] ing --- auth/service/NoAuthProbeService.go | 25 +++++++++++++++++-------- client/auth/auth.go | 14 ++++++-------- client/probe/probe.go | 11 +++++++---- service/DataService.go | 4 ++-- service/ProbeClientService.go | 14 ++++++++++---- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/auth/service/NoAuthProbeService.go b/auth/service/NoAuthProbeService.go index 888f13f..9980c79 100644 --- a/auth/service/NoAuthProbeService.go +++ b/auth/service/NoAuthProbeService.go @@ -35,7 +35,7 @@ type NoAuthProbeService struct { } func (s *NoAuthProbeService) InitService() error { - client, err := auth.New(s.HandleTempKey, s) + client, err := auth.New(s.HandleResponse, s) if nil != err { return err } @@ -98,12 +98,21 @@ func (s *NoAuthProbeService) Deny() error { return nil } -func (s *NoAuthProbeService) HandleTempKey(tempKey string) { - logging.Logger().Infof("registered by central") - s.AuthConfig.TempKey = &tempKey - if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err { - logging.Logger().Error(err) - s.AuthDoneChan <- err - return +func (s *NoAuthProbeService) HandleResponse(method string, param string) { + switch method { + case occn.HTTPResponseHeaderValue_NoAuthProbe_Method_TempProbeKey: + logging.Logger().Infof("registered by central") + s.AuthConfig.TempKey = ¶m + if err := configuration.Save(s.AuthConfig, config.NoAuthProbeConfigFilePath(), true); nil != err { + 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() } + } diff --git a/client/auth/auth.go b/client/auth/auth.go index b22a736..385312a 100644 --- a/client/auth/auth.go +++ b/client/auth/auth.go @@ -16,7 +16,7 @@ import ( "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() if nil == config { return nil, fmt.Errorf("Config is not available") @@ -49,13 +49,11 @@ func New(tempKeyHandler func(tempKey string), services ...interface{}) (*crc.Cli return header } connector.ResponseHandler = func(res *http.Response) { - switch authConfig.State() { - case occn.AuthStateTypeNotRegisterd: - tempProbeKey := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_SetTempProbeKey) - if nil != tempKeyHandler { - tempKeyHandler(tempProbeKey) - } - default: + responseMethod := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_Method) + responseMethodParam := res.Header.Get(occn.HTTPResponseHeaderKey_NoAuthProbe_Method_Param) + + if nil != responseHandler { + responseHandler(responseMethod, responseMethodParam) } } diff --git a/client/probe/probe.go b/client/probe/probe.go index 27d4eb2..1a34ff4 100644 --- a/client/probe/probe.go +++ b/client/probe/probe.go @@ -12,7 +12,7 @@ import ( "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() if nil == config { return nil, fmt.Errorf("Config is not available") @@ -30,11 +30,14 @@ func New(encryptionKeyHandler func(encryptionKey string), services ...interface{ return header } connector.ResponseHandler = func(res *http.Response) { - encryptionKey := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_SetEncryptionKey) - if nil != encryptionKeyHandler { - encryptionKeyHandler(encryptionKey) + responseMethod := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_Method) + responseMethodParam := res.Header.Get(occp.HTTPResponseHeaderKey_Probe_Method_Param) + + if nil != responseHandler { + responseHandler(responseMethod, responseMethodParam) } } + connector.OnDisconnected = func(connector csc.Connector) { logging.Logger().Debugf("Client[%s] has been disconnected", connector.GetName()) } diff --git a/service/DataService.go b/service/DataService.go index 388d637..f5a5b91 100644 --- a/service/DataService.go +++ b/service/DataService.go @@ -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) return nil diff --git a/service/ProbeClientService.go b/service/ProbeClientService.go index 5134ec4..47ab9f6 100644 --- a/service/ProbeClientService.go +++ b/service/ProbeClientService.go @@ -6,10 +6,11 @@ import ( cda "git.loafle.net/commons/di-go/annotation" 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 _ "git.loafle.net/overflow/commons-go/core/annotation" - "git.loafle.net/overflow/probe/client/probe" ) var ProbeClientServiceType = reflect.TypeOf((*ProbeClientService)(nil)) @@ -41,7 +42,7 @@ func (s *ProbeClientService) StartService() error { 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 { return fmt.Errorf("ProbeClientService: StartService failed %v", err) } @@ -62,6 +63,11 @@ func (s *ProbeClientService) DestroyService() { s.RPCClientService.DestroyService() } -func (s *ProbeClientService) HandleEncryptionKey(encryptionKey string) { - s.EncryptionKey = encryptionKey +func (s *ProbeClientService) HandleResponse(method string, param string) { + switch method { + case occp.HTTPResponseHeaderValue_Probe_Method_EncryptionKey: + s.EncryptionKey = param + case occp.HTTPResponseHeaderValue_Probe_Method_Delete: + } + }