add callback for pipe start and pipe err (#145)
* add onstart onerr cb * cover by e2e * add missing plugin * happy lint
This commit is contained in:
parent
f0e9accbd0
commit
1cd6cd86d9
11 changed files with 823 additions and 131 deletions
|
|
@ -54,6 +54,10 @@ type SshPiperPluginConfig struct {
|
|||
BannerCallback func(conn ConnMetadata) string
|
||||
|
||||
VerifyHostKeyCallback func(conn ConnMetadata, hostname, netaddr string, key []byte) error
|
||||
|
||||
PipeStartCallback func(conn ConnMetadata)
|
||||
|
||||
PipeErrorCallback func(conn ConnMetadata, err error)
|
||||
}
|
||||
|
||||
type SshPiperPlugin interface {
|
||||
|
|
@ -180,6 +184,14 @@ func (s *server) ListCallbacks(ctx context.Context, req *ListCallbackRequest) (*
|
|||
cb = append(cb, "VerifyHostKey")
|
||||
}
|
||||
|
||||
if s.config.PipeStartCallback != nil {
|
||||
cb = append(cb, "PipeStart")
|
||||
}
|
||||
|
||||
if s.config.PipeErrorCallback != nil {
|
||||
cb = append(cb, "PipeError")
|
||||
}
|
||||
|
||||
return &ListCallbackResponse{
|
||||
Callbacks: cb,
|
||||
}, nil
|
||||
|
|
@ -377,7 +389,7 @@ func (s *server) Banner(ctx context.Context, req *BannerRequest) (*BannerRespons
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) VerifyHostKey(ctx context.Context, req *VerifyHostKeyRequest) (*VerifyHostKeyReply, error) {
|
||||
func (s *server) VerifyHostKey(ctx context.Context, req *VerifyHostKeyRequest) (*VerifyHostKeyResponse, error) {
|
||||
if s.config.VerifyHostKeyCallback == nil {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method VerifyHostKey not implemented")
|
||||
}
|
||||
|
|
@ -387,7 +399,27 @@ func (s *server) VerifyHostKey(ctx context.Context, req *VerifyHostKeyRequest) (
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &VerifyHostKeyReply{
|
||||
return &VerifyHostKeyResponse{
|
||||
Verified: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) PipeStartNotice(ctx context.Context, req *PipeStartNoticeRequest) (*PipeStartNoticeResponse, error) {
|
||||
if s.config.PipeStartCallback == nil {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PipeStartNotice not implemented")
|
||||
}
|
||||
|
||||
s.config.PipeStartCallback(req.Meta)
|
||||
|
||||
return &PipeStartNoticeResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *server) PipeErrorNotice(ctx context.Context, req *PipeErrorNoticeRequest) (*PipeErrorNoticeResponse, error) {
|
||||
if s.config.PipeErrorCallback == nil {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PipeErrorNotice not implemented")
|
||||
}
|
||||
|
||||
s.config.PipeErrorCallback(req.Meta, fmt.Errorf(req.Error))
|
||||
|
||||
return &PipeErrorNoticeResponse{}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue