Skip to content

Commit 0b07aff

Browse files
committed
perf: update Makefile
1 parent 40d6f29 commit 0b07aff

9 files changed

Lines changed: 169 additions & 14 deletions

File tree

Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,27 @@ clean:
6565
proto_path=./protos/
6666
proto_files=./protos/*.proto
6767

68-
protobuf_go_dir=./protobuf-go/protobuf
68+
proto_go_dir=./protobuf-go
6969
protobuf_py_dir=./protobuf-py/protobuf
7070

7171
.PHONY: proto
72-
proto: proto-go proto-py
72+
proto: proto-go
7373

7474
.PHONY: proto-go
7575
proto-go:
76-
@mkdir -p ${protobuf_go_dir}
77-
rm -rf ${protobuf_go_dir}/*
78-
protoc --proto_path=${proto_path} --go_out=./protobuf-go/ \
79-
--go-grpc_out=./protobuf-go/ \
76+
@mkdir -p ${proto_go_dir}/protobuf
77+
rm -rf ${proto_go_dir}/protobuf/*
78+
protoc --proto_path=${proto_path} --go_out=${proto_go_dir} \
79+
--go-grpc_out=${proto_go_dir} \
8080
--go_opt=paths=import \
8181
${proto_files}
8282

83+
84+
8385
.PHONY: proto-py
8486
proto-py:
85-
@mkdir -p ${protobuf_py_dir}
86-
rm -rf ${protobuf_py_dir}/*
87-
python -m grpc_tools.protoc --proto_path=${proto_path} --python_out=${protobuf_py_dir} \
88-
--grpc_python_out=${protobuf_py_dir} \
89-
${proto_files}
87+
@mkdir -p ./protobuf-py/protobuf
88+
rm -rf ./protobuf-py/protobuf/*
89+
python -m grpc_tools.protoc --proto_path=${proto_path} --python_out=./protobuf-py/protobuf \
90+
--grpc_python_out=./protobuf-py/protobuf \
91+
${proto_files}

cmd/common/remain_replay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (r *RemainReplay) GetGzFilename() string {
4949
return r.Id + suffixGz
5050
}
5151

52-
func ParseReoplaySessionID(filename string) (string, bool) {
52+
func ParseReplaySessionID(filename string) (string, bool) {
5353
if len(filename) == 36 && modelCommon.IsUUID(filename) {
5454
return filename, true
5555
}

cmd/common/uploader_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func scanRemainReplays(apiClient *service.JMService, replayDir string) map[strin
232232
version model.ReplayVersion
233233
ok bool
234234
)
235-
if sid, ok = ParseReoplaySessionID(info.Name()); !ok {
235+
if sid, ok = ParseReplaySessionID(info.Name()); !ok {
236236
return nil
237237
}
238238
if version, ok = ParseReplayVersion(info.Name()); !ok {

cmd/impl/jms.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (j *JMServer) sendStreamTask(ctx context.Context, stream pb.Service_Dispatc
175175
}
176176
}
177177
}
178+
178179
func (j *JMServer) handleTerminalTask(req *pb.FinishedTaskRequest) {
179180
if err := j.beat.FinishTask(req.TaskId); err != nil {
180181
logger.Errorf("Handle task id %s failed: %s", req.TaskId, err)

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var rootCmd = &cobra.Command{
6969
subProcess := process.New(conf.RootPath, conf.ExecuteProgram)
7070
logger.Infof("start subprocess: %s", conf.ExecuteProgram)
7171
startProcess(ctx, subProcess)
72-
// 子进程突出,srv 结束
72+
// 子进程退出,srv 结束
7373
srv.Stop()
7474
}
7575
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/sirupsen/logrus v1.8.1
1414
github.com/spf13/cobra v1.3.0
1515
github.com/spf13/viper v1.10.1
16+
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
1617
google.golang.org/grpc v1.44.0
1718
google.golang.org/protobuf v1.27.1
1819
gopkg.in/natefinch/lumberjack.v2 v2.0.0

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
430430
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
431431
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
432432
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
433+
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38=
434+
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
433435
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
434436
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
435437
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -612,6 +614,7 @@ golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBc
612614
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
613615
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 h1:nhht2DYV/Sn3qOayu8lM+cU1ii9sTLUeBQwQQfUHtrs=
614616
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
617+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
615618
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
616619
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
617620
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

pkg/sshclient/client.go

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package sshclient
2+
3+
import (
4+
"net"
5+
"strconv"
6+
"time"
7+
8+
"golang.org/x/crypto/ssh"
9+
)
10+
11+
type Option func(conf *Options)
12+
13+
type Options struct {
14+
Host string
15+
Port string
16+
Username string
17+
Password string
18+
PrivateKey string
19+
Passphrase string
20+
keyboardAuth ssh.KeyboardInteractiveChallenge
21+
PrivateAuth ssh.Signer
22+
timeout int // 秒单位
23+
}
24+
25+
func (cfg *Options) AuthMethods() []ssh.AuthMethod {
26+
authMethods := make([]ssh.AuthMethod, 0, 3)
27+
if cfg.PrivateAuth != nil {
28+
authMethods = append(authMethods, ssh.PublicKeys(cfg.PrivateAuth))
29+
}
30+
31+
if cfg.PrivateKey != "" {
32+
var (
33+
signer ssh.Signer
34+
err error
35+
)
36+
if cfg.Passphrase != "" {
37+
// 先使用 passphrase 解析 PrivateKey
38+
if signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(cfg.PrivateKey),
39+
[]byte(cfg.Passphrase)); err == nil {
40+
authMethods = append(authMethods, ssh.PublicKeys(signer))
41+
}
42+
}
43+
if err != nil || cfg.Passphrase == "" {
44+
// 1. 如果之前使用解析失败,则去掉 passphrase,则尝试直接解析 PrivateKey 防止错误的passphrase
45+
// 2. 如果没有 Passphrase 则直接解析 PrivateKey
46+
if signer, err = ssh.ParsePrivateKey([]byte(cfg.PrivateKey)); err == nil {
47+
authMethods = append(authMethods, ssh.PublicKeys(signer))
48+
}
49+
}
50+
}
51+
if cfg.Password != "" {
52+
authMethods = append(authMethods, ssh.Password(cfg.Password))
53+
}
54+
if cfg.keyboardAuth == nil {
55+
cfg.keyboardAuth = func(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
56+
if len(questions) == 0 {
57+
return []string{}, nil
58+
}
59+
return []string{cfg.Password}, nil
60+
}
61+
}
62+
authMethods = append(authMethods, ssh.KeyboardInteractive(cfg.keyboardAuth))
63+
64+
return authMethods
65+
}
66+
67+
func Username(username string) Option {
68+
return func(args *Options) {
69+
args.Username = username
70+
}
71+
}
72+
73+
func Password(password string) Option {
74+
return func(args *Options) {
75+
args.Password = password
76+
}
77+
}
78+
79+
func PrivateKey(privateKey string) Option {
80+
return func(args *Options) {
81+
args.PrivateKey = privateKey
82+
}
83+
}
84+
85+
func Passphrase(passphrase string) Option {
86+
return func(args *Options) {
87+
args.Passphrase = passphrase
88+
}
89+
}
90+
91+
func Host(host string) Option {
92+
return func(args *Options) {
93+
args.Host = host
94+
}
95+
}
96+
97+
func Port(port int) Option {
98+
return func(args *Options) {
99+
args.Port = strconv.Itoa(port)
100+
}
101+
}
102+
103+
func Timeout(timeout int) Option {
104+
return func(args *Options) {
105+
args.timeout = timeout
106+
}
107+
}
108+
109+
func PrivateAuth(privateAuth ssh.Signer) Option {
110+
return func(args *Options) {
111+
args.PrivateAuth = privateAuth
112+
}
113+
}
114+
115+
func KeyboardAuth(keyboardAuth ssh.KeyboardInteractiveChallenge) Option {
116+
return func(conf *Options) {
117+
conf.keyboardAuth = keyboardAuth
118+
}
119+
}
120+
121+
const defaultTimeout = 15
122+
123+
func New(opts ...Option) (*ssh.Client, error) {
124+
cfg := &Options{
125+
Host: "127.0.0.1",
126+
Port: "22",
127+
timeout: defaultTimeout,
128+
}
129+
for _, setter := range opts {
130+
setter(cfg)
131+
}
132+
return NewWithCfg(cfg)
133+
}
134+
135+
func NewWithCfg(cfg *Options) (*ssh.Client, error) {
136+
sshCfg := ssh.ClientConfig{
137+
User: cfg.Username,
138+
Auth: cfg.AuthMethods(),
139+
Timeout: time.Duration(cfg.timeout) * time.Second,
140+
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
141+
}
142+
destAddr := net.JoinHostPort(cfg.Host, cfg.Port)
143+
sshClient, err := ssh.Dial("tcp", destAddr, &sshCfg)
144+
if err != nil {
145+
return nil, err
146+
}
147+
return sshClient, nil
148+
}

protobuf-java/pom.xml

Whitespace-only changes.

0 commit comments

Comments
 (0)