-
Notifications
You must be signed in to change notification settings - Fork 2
/
ssh.go
54 lines (39 loc) · 1.53 KB
/
ssh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// gRPC Runtime of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// by CB-Spider Team, 2020.09.
package service
import (
"context"
"strings"
gc "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/common"
"github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/logger"
pb "github.com/cloud-barista/poc-cicd-spider/api-runtime/grpc-runtime/stub/cbspider"
sshrun "github.com/cloud-barista/poc-cicd-spider/cloud-control-manager/vm-ssh"
)
// ===== [ Constants and Variables ] =====
// ===== [ Types ] =====
// ===== [ Implementations ] =====
// SSHRun - SSH 실행
func (s *SSHService) SSHRun(ctx context.Context, req *pb.SSHRunRequest) (*pb.StringResponse, error) {
logger := logger.NewLogger()
logger.Debug("calling SSHService.SSHRun()")
strPrivateKey := strings.Join(req.PrivateKey[:], "\n")
sshInfo := sshrun.SSHInfo{
UserName: req.UserName,
PrivateKey: []byte(strPrivateKey),
ServerPort: req.ServerPort,
}
var result string
var err error
if result, err = sshrun.SSHRun(sshInfo, req.Command); err != nil {
return nil, gc.NewGrpcStatusErr("Error while running cmd: "+req.Command+"]"+err.Error(), "", "SSHService.SSHRun()")
}
resp := &pb.StringResponse{Result: result}
return resp, nil
}
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====