ing
This commit is contained in:
parent
c479442b6f
commit
6b52a1ef57
|
@ -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()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user