Skip to content

Commit afd5b33

Browse files
authored
Merge pull request #155 from jumpserver/dev
v3.7.0
2 parents 17660c3 + 99691d2 commit afd5b33

6 files changed

Lines changed: 133 additions & 17 deletions

File tree

.github/workflows/release-drafter.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,25 @@ jobs:
3030
with:
3131
config-name: release-config.yml
3232
version: ${{ steps.get_version.outputs.TAG }}
33-
tag: ${{ steps.get_version.outputs.TAG }}
33+
tag: ${{ steps.get_version.outputs.TAG }}
34+
- uses: actions/setup-node@v2
35+
with:
36+
node-version: '20.1'
37+
- uses: actions/setup-go@v2
38+
with:
39+
go-version: '1.20.x' # The Go version to download (if necessary) and use.
40+
- name: Make Build
41+
id: make_build
42+
env:
43+
VERSION: ${{ steps.get_version.outputs.TAG }}
44+
run: |
45+
make -s && ls build
46+
- name: Release Upload Assets
47+
uses: softprops/action-gh-release@v1
48+
if: startsWith(github.ref, 'refs/tags/')
49+
with:
50+
draft: true
51+
files: |
52+
build/*.gz
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
NAME=kael
2+
BUILDDIR=build
3+
4+
BASEPATH := $(shell pwd)
5+
BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
6+
BUILD := $(shell git rev-parse --short HEAD)
7+
KAELSRCFILE := $(BASEPATH)/cmd/kael/
8+
9+
VERSION ?= $(BRANCH)-$(BUILD)
10+
BuildTime:= $(shell date -u '+%Y-%m-%d %I:%M:%S%p')
11+
COMMIT:= $(shell git rev-parse HEAD)
12+
GOVERSION:= $(shell go version)
13+
TARGETARCH ?= amd64
14+
15+
UIDIR=ui
16+
YARNINSTALL=yarn install
17+
YARNBUILD=yarn build
18+
19+
LDFLAGS=-w -s
20+
21+
KAELLDFLAGS+=-X 'main.Buildstamp=$(BuildTime)'
22+
KAELLDFLAGS+=-X 'main.Githash=$(COMMIT)'
23+
KAELLDFLAGS+=-X 'main.Goversion=$(GOVERSION)'
24+
25+
KAELBUILD=CGO_ENABLED=0 go build -trimpath -ldflags "$(KAELLDFLAGS) ${LDFLAGS}"
26+
27+
PLATFORM_LIST = \
28+
darwin-amd64 \
29+
darwin-arm64 \
30+
linux-amd64 \
31+
linux-arm64
32+
33+
all-arch: $(PLATFORM_LIST)
34+
35+
darwin-amd64:kael-ui
36+
GOARCH=amd64 GOOS=darwin $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$@ $(KAELSRCFILE)
37+
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
38+
39+
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
40+
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
41+
42+
darwin-arm64:kael-ui
43+
GOARCH=arm64 GOOS=darwin $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$@ $(KAELSRCFILE)
44+
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
45+
46+
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
47+
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
48+
49+
linux-amd64:kael-ui
50+
GOARCH=amd64 GOOS=linux $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$@ $(KAELSRCFILE)
51+
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
52+
53+
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
54+
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
55+
56+
linux-arm64:kael-ui
57+
GOARCH=arm64 GOOS=linux $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$@ $(KAELSRCFILE)
58+
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
59+
60+
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
61+
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
62+
63+
linux-loong64:kael-ui
64+
GOARCH=loong64 GOOS=linux $(KAELBUILD) -o $(BUILDDIR)/$(NAME)-$@ $(KAELSRCFILE)
65+
mkdir -p $(BUILDDIR)/$(NAME)-$(VERSION)-$@
66+
67+
cp $(BUILDDIR)/$(NAME)-$@ $(BUILDDIR)/$(NAME)-$(VERSION)-$@/$(NAME)
68+
cd $(BUILDDIR) && tar -czvf $(NAME)-$(VERSION)-$@.tar.gz $(NAME)-$(VERSION)-$@
69+
70+
kael-ui:
71+
@echo "build ui"
72+
@cd $(UIDIR) && $(YARNINSTALL) && $(YARNBUILD)
73+
74+
.PHONY: docker
75+
docker:
76+
@echo "build docker images"
77+
docker buildx build --build-arg VERSION=$(VERSION) -t jumpserver/kael .
78+
79+
.PHONY: clean
80+
clean:
81+
-rm -rf $(BUILDDIR)
82+
-rm -rf $(UIDIR)/dist/*

pkg/config/config.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"log"
66
"os"
77
"path/filepath"
8+
"strings"
89
)
910

1011
type Config struct {
1112
Host string `mapstructure:"Host"`
1213
Port string `mapstructure:"Port"`
14+
WispPort string `mapstructure:"WISP_PORT"`
1315
LogLevel string `mapstructure:"LOG_LEVEL"`
1416
LogDirPath string
1517
DataFolderPath string
@@ -40,12 +42,12 @@ func getDefaultConfig() Config {
4042
return Config{
4143
Host: "0.0.0.0",
4244
Port: "8083",
45+
WispPort: "9090",
4346
LogLevel: "INFO",
4447
LogDirPath: logDirPath,
4548
DataFolderPath: dataFolderPath,
4649
ReplayFolderPath: replayFolderPath,
4750
}
48-
4951
}
5052

5153
func EnsureDirExist(path string) error {
@@ -76,7 +78,14 @@ func getPwdDirPath() string {
7678

7779
func loadConfigFromEnv(conf *Config) {
7880
viper.AutomaticEnv()
79-
if err := viper.Unmarshal(conf); err == nil {
81+
envViper := viper.New()
82+
for _, item := range os.Environ() {
83+
envItem := strings.SplitN(item, "=", 2)
84+
if len(envItem) == 2 {
85+
envViper.Set(envItem[0], viper.Get(envItem[0]))
86+
}
87+
}
88+
if err := envViper.Unmarshal(conf); err == nil {
8089
log.Println("Load config from env")
8190
}
8291
}

pkg/httpd/grpc/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package grpc
22

33
import (
4+
"fmt"
5+
"github.com/jumpserver/kael/pkg/config"
46
"github.com/jumpserver/kael/pkg/logger"
57
pb "github.com/jumpserver/wisp/protobuf-go/protobuf"
68
"go.uber.org/zap"
@@ -17,7 +19,7 @@ type Client struct {
1719

1820
func (c *Client) Start() {
1921
conn, err := grpc.Dial(
20-
"localhost:9090",
22+
fmt.Sprintf("localhost:%s", config.GlobalConfig.WispPort),
2123
grpc.WithTransportCredentials(insecure.NewCredentials()),
2224
)
2325
if err != nil {

pkg/jms/poll.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/jumpserver/kael/pkg/schemas"
1212
"github.com/jumpserver/wisp/protobuf-go/protobuf"
1313
"go.uber.org/zap"
14-
"io"
1514
)
1615

1716
type PollJMSEvent struct{}
@@ -29,8 +28,6 @@ func (p *PollJMSEvent) clearZombieSession() {
2928
resp, err := grpc.GlobalGrpcClient.Client.ScanRemainReplays(ctx, req)
3029
if err != nil || !resp.Status.Ok {
3130
logger.GlobalLogger.Error("Failed to scan remain replay")
32-
} else {
33-
logger.GlobalLogger.Info("Scan remain replay success")
3431
}
3532
}
3633

@@ -40,18 +37,17 @@ func (p *PollJMSEvent) waitForKillSessionMessage() {
4037
logger.GlobalLogger.Error("dispatch task err", zap.Error(err))
4138
return
4239
}
43-
waitChan := make(chan struct{})
40+
logger.GlobalLogger.Info("start dispatch task success")
41+
42+
closeStreamChan := make(chan struct{})
4443
for {
4544
taskResponse, err := stream.Recv()
46-
if err == io.EOF {
45+
46+
if err != nil {
4747
_ = stream.CloseSend()
48-
close(waitChan)
48+
close(closeStreamChan)
4949
break
5050
}
51-
if err != nil {
52-
logger.GlobalLogger.Error("Failed to receive a note", zap.Error(err))
53-
continue
54-
}
5551

5652
task := taskResponse.Task
5753
sessionId := task.SessionId
@@ -75,7 +71,8 @@ func (p *PollJMSEvent) waitForKillSessionMessage() {
7571
}
7672
}
7773
}
78-
<-waitChan
74+
<-closeStreamChan
75+
p.waitForKillSessionMessage()
7976
}
8077
func (p *PollJMSEvent) sendFinishTask(stream protobuf.Service_DispatchTaskClient, TaskId string) {
8178
req := &protobuf.FinishedTaskRequest{
@@ -101,7 +98,7 @@ func (p *PollJMSEvent) sendSessionState(jmss *JMSSession, state schemas.SessionS
10198
response := &schemas.AskResponse{
10299
Type: schemas.Waiting,
103100
ConversationID: jmss.Session.Id,
104-
SystemMessage: msg,
101+
SystemMessage: msg,
105102
Meta: schemas.ResponseMeta{SessionState: state},
106103
}
107104

pkg/jms/replay.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ func (rh *ReplayHandler) WriteOutput(outputStr string) {
7575
func (rh *ReplayHandler) Upload() {
7676
defer rh.FileWriter.Close()
7777

78+
replayFilePath := rh.File.Name()
79+
if _, err := os.Stat(replayFilePath); os.IsNotExist(err) {
80+
return
81+
}
82+
7883
ctx := context.Background()
7984
replayRequest := &protobuf.ReplayRequest{
8085
SessionId: rh.Session.Id,
81-
ReplayFilePath: rh.File.Name(),
86+
ReplayFilePath: replayFilePath,
8287
}
8388
resp, _ := grpc.GlobalGrpcClient.Client.UploadReplayFile(ctx, replayRequest)
8489
if !resp.Status.Ok {

0 commit comments

Comments
 (0)