ing
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"git.loafle.net/commons/configuration-go"
|
||||
cda "git.loafle.net/commons/di-go/annotation"
|
||||
cdr "git.loafle.net/commons/di-go/registry"
|
||||
logging "git.loafle.net/commons/logging-go"
|
||||
ocnc "git.loafle.net/overflow/commons-go/noauthprobe/config"
|
||||
ocpc "git.loafle.net/overflow/commons-go/probe/config"
|
||||
"git.loafle.net/overflow/probe/config"
|
||||
|
||||
// For annotation
|
||||
_ "git.loafle.net/overflow/commons-go/core/annotation"
|
||||
)
|
||||
|
||||
@@ -17,16 +27,54 @@ func init() {
|
||||
type NoAuthProbeService struct {
|
||||
cda.TypeAnnotation `annotation:"@overflow:RPCService()"`
|
||||
|
||||
AcceptedChan chan<- string `annotation:"@Resource(name='AcceptedChan')"`
|
||||
DeniedChan chan<- struct{} `annotation:"@Resource(name='DeniedChan')"`
|
||||
ConfigDir string `annotation:"@Resource(name='ConfigDir')"`
|
||||
Config *config.Config `annotation:"@Resource(name='Config')"`
|
||||
AuthConfig *ocnc.Auth `annotation:"@Resource(name='AuthConfig')"`
|
||||
AuthDoneChan chan error `annotation:"@Resource(name='AuthDoneChan')"`
|
||||
}
|
||||
|
||||
func (s *NoAuthProbeService) Start() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NoAuthProbeService) Stop(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NoAuthProbeService) Accept(probeKey string) error {
|
||||
s.AcceptedChan <- probeKey
|
||||
logging.Logger().Infof("accepted by central")
|
||||
|
||||
n := time.Now()
|
||||
s.AuthConfig.AcceptedDate = &n
|
||||
if err := configuration.Save(s.AuthConfig, path.Join(s.ConfigDir, ocnc.ConfigFileName), true); nil != err {
|
||||
logging.Logger().Error(err)
|
||||
s.AuthDoneChan <- err
|
||||
return nil
|
||||
}
|
||||
|
||||
s.Config.Probe.Key = &probeKey
|
||||
if err := configuration.Save(s.Config, path.Join(s.ConfigDir, ocpc.ConfigFileName), true); nil != err {
|
||||
logging.Logger().Error(err)
|
||||
s.AuthDoneChan <- err
|
||||
return nil
|
||||
}
|
||||
|
||||
s.AuthDoneChan <- nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *NoAuthProbeService) Deny() error {
|
||||
s.DeniedChan <- struct{}{}
|
||||
logging.Logger().Infof("denied by central")
|
||||
n := time.Now()
|
||||
s.AuthConfig.DeniedDate = &n
|
||||
if err := configuration.Save(s.AuthConfig, path.Join(s.ConfigDir, ocnc.ConfigFileName), true); nil != err {
|
||||
logging.Logger().Error(err)
|
||||
s.AuthDoneChan <- err
|
||||
return nil
|
||||
}
|
||||
|
||||
s.AuthDoneChan <- nil
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user