Skip to content

Commit

Permalink
Merge branch 'feature/wangzhen_LYAPI_2140_params' into 'master'
Browse files Browse the repository at this point in the history
Feature/wangzhen lyapi 2140 params

See merge request leyanapi/leyanapi-backend!403
  • Loading branch information
wangzhen committed Jul 29, 2024
2 parents 8826e92 + e068a67 commit 78b2196
Show file tree
Hide file tree
Showing 123 changed files with 4,868 additions and 1,905 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: demo site deploy
on:
workflow_dispatch
# pull_request:
# branches: [ "main" ]
# branches: [ "main" ]
# push:
# branches: [ "main" ]

Expand All @@ -12,14 +12,14 @@ jobs:
runs-on: self-hosted
defaults:
run:
working-directory: /home/ubuntu/rd/project/deeptest
working-directory: /rd/project/deeptest
steps:
- name: checkout backend codes
run: git pull

- name: checkout frontend codes
run: git pull
working-directory: /home/ubuntu/rd/project/deeptest-ui
working-directory: /rd/project/deeptest-ui

- name: make server
run: ENV=dp make compile_server_linux
Expand All @@ -32,15 +32,16 @@ jobs:

- name: copy files
run: |
cp -f bin/linux/deeptest-server /home/ubuntu/rd/server/
cp -f client/bin/linux/deeptest-agent /home/ubuntu/rd/server/
mkdir -p /rd/server
cp -f bin/linux/deeptest-server /rd/server/
cp -f client/bin/linux/deeptest-agent /rd/server/
rm -rf /home/ubuntu/rd/server/deeptest-ui
cp -fr client/ui /home/ubuntu/rd/server/deeptest-ui
rm -rf /rd/server/deeptest-ui
cp -fr client/ui /rd/server/deeptest-ui
- name: start service
run: |
ps -ef | grep 'deeptest-' | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9
cd /home/ubuntu/rd/server
cd /rd/server
RUNNER_TRACKING_ID="" && nohup ./deeptest-server > server.log 2>&1 &
RUNNER_TRACKING_ID="" && nohup ./deeptest-agent > agent.log 2>&1 &
90 changes: 81 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,31 @@ GIT_HASH=`git show -s --format=%H`
BUILD_CMD_UNIX=go build -ldflags "-X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"
BUILD_CMD_WIN=go build -ldflags "-s -w -X 'main.AppVersion=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.GoVersion=${GO_VERSION}' -X 'main.GitHash=${GIT_HASH}'"

default: win64 win32 linux mac
default: compile_ui_web win64 win32 linux mac

win64: prepare build_gui_win64 compile_launcher_win64 compile_server_win64 copy_files_win64 zip_win64 zip_win64_upgrade
win32: prepare build_gui_win32 compile_launcher_win32 compile_server_win32 copy_files_win32 zip_win32 zip_win32_upgrade
linux: prepare build_gui_linux compile_server_linux copy_files_linux zip_linux zip_linux_upgrade
mac: prepare build_gui_mac compile_server_mac copy_files_mac zip_mac zip_mac_upgrade
# 非客户端版本打包
win64: prepare compile_agent_win64 compile_server_win64 zip_web_win64
win32: prepare compile_agent_win32 compile_server_win32 zip_web_win32
linux: prepare compile_agent_linux compile_server_linux zip_web_linux
mac: prepare compile_agent_mac compile_server_mac zip_web_mac

# 客户端版本打包
dp-win64: prepare build_gui_win64 compile_launcher_win64 compile_server_win64 copy_files_win64 zip_win64 zip_win64_upgrade
dp-win32: prepare build_gui_win32 compile_launcher_win32 compile_server_win32 copy_files_win32 zip_win32 zip_win32_upgrade
dp-linux: prepare build_gui_linux compile_server_linux copy_files_linux zip_linux zip_linux_upgrade
dp-mac: prepare build_gui_mac compile_server_mac copy_files_mac zip_mac zip_mac_upgrade

# 乐研 打包
ly-win64: prepare compile_ly_ui_client build_gui_win64 compile_ly_launcher_win64 compile_server_win64 copy_files_win64 zip_win64 zip_win64_upgrade
ly-win32: prepare compile_ly_ui_client build_gui_win32 compile_ly_launcher_win32 compile_server_win32 copy_files_win32 zip_win32 zip_win32_upgrade
ly-linux: prepare compile_ly_ui_client build_gui_linux compile_server_linux copy_files_linux zip_linux zip_linux_upgrade
ly-mac: prepare compile_ly_ui_client build_gui_mac compile_server_mac copy_files_mac zip_mac zip_mac_upgrade

build_agent: compile_agent_win64 compile_agent_win32 compile_agent_linux compile_agent_mac

prepare: init_client_project update_version

# 初始化客户端项目
init_client_project:
@sh ./init.project.sh
@sh ./init.project.sh && yarn config set ignore-engines true

update_version: gen_version_file

Expand All @@ -78,6 +83,8 @@ gen_version_file:

compile_ui:
@cd ui && yarn build --dest ../client/ui && cd ..
compile_ui_web:
@cd ../leyanapi-frontend && yarn build:web --dest ../leyanapi-backend/client/ui && cd ../leyanapi-backend
compile_ui_demo:
@cd ../deeptest-ui && yarn build:demo --dest ../deeptest/client/ui && cd ../deeptest
compile_ui_client:
Expand Down Expand Up @@ -233,7 +240,72 @@ copy_files_linux:
copy_files_mac:
@echo 'start copy files darwin'

# zip files
# zip web files
zip_web_win64:
@echo 'start zip win64'
@find . -name .DS_Store -print0 | xargs -0 rm -f
@mkdir -p ${QINIU_DIST_DIR}win64 && rm -rf ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip

@cp -rf config ${BIN_DIR}win64/
@cp -rf ${CLIENT_BIN_DIR}win32/deeptest-agent.exe ${BIN_DIR}win64/
@rm -rf ${BIN_DIR}win64/deeptest-ui && mkdir ${BIN_DIR}win64/deeptest-ui
@cp -rf client/ui/* ${BIN_DIR}win64/deeptest-ui

@cd ${BIN_DIR}win64/ && \
zip -ry ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip ./* && \
md5sum ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip | awk '{print $$1}' | \
xargs echo > ${QINIU_DIST_DIR}win64/${PROJECT}-web.zip.md5 && \
cd ../..; \

zip_web_win32:
@echo 'start zip win32'
@find . -name .DS_Store -print0 | xargs -0 rm -f
@mkdir -p ${QINIU_DIST_DIR}win32 && rm -rf ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip

@cp -rf config ${BIN_DIR}win32/
@cp -rf ${CLIENT_BIN_DIR}win32/deeptest-agent.exe ${BIN_DIR}win32/
@rm -rf ${BIN_DIR}win32/deeptest-ui && mkdir ${BIN_DIR}win32/deeptest-ui
@cp -rf client/ui/* ${BIN_DIR}win32/deeptest-ui

@cd ${BIN_DIR}win32/ && \
zip -ry ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip ./* && \
md5sum ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip | awk '{print $$1}' | \
xargs echo > ${QINIU_DIST_DIR}win32/${PROJECT}-web.zip.md5 && \
cd ../..; \

zip_web_linux:
@echo 'start zip linux'
@find . -name .DS_Store -print0 | xargs -0 rm -f
@mkdir -p ${QINIU_DIST_DIR}linux && rm -rf ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip

@cp -rf config ${BIN_DIR}linux/
@cp -rf ${CLIENT_BIN_DIR}linux/deeptest-agent ${BIN_DIR}linux/
@rm -rf ${BIN_DIR}linux/deeptest-ui && mkdir ${BIN_DIR}linux/deeptest-ui
@cp -rf client/ui/* ${BIN_DIR}linux/deeptest-ui

@cd ${BIN_DIR}linux/ && \
zip -ry ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip ./* && \
md5sum ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip | awk '{print $$1}' | \
xargs echo > ${QINIU_DIST_DIR}linux/${PROJECT}-web.zip.md5 && \
cd ../..; \

zip_web_mac:
@echo 'start zip darwin'
@find . -name .DS_Store -print0 | xargs -0 rm -f
@mkdir -p ${QINIU_DIST_DIR}darwin && rm -rf ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip

@cp -rf config ${BIN_DIR}darwin/
@cp -rf ${CLIENT_BIN_DIR}darwin/deeptest-agent ${BIN_DIR}darwin/
@rm -rf ${BIN_DIR}darwin/deeptest-ui && mkdir ${BIN_DIR}darwin/deeptest-ui
@cp -rf client/ui/* ${BIN_DIR}darwin/deeptest-ui

@cd ${BIN_DIR}darwin/ && \
zip -ry ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip ./* && \
md5sum ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip | awk '{print $$1}' | \
xargs echo > ${QINIU_DIST_DIR}darwin/${PROJECT}-web.zip.md5 && \
cd ../..; \

# zip client files
zip_win64:
@echo 'start zip win64'
@find . -name .DS_Store -print0 | xargs -0 rm -f
Expand Down
2 changes: 1 addition & 1 deletion backend-config
Submodule backend-config updated from 188cd2 to e39b7c
11 changes: 0 additions & 11 deletions cmd/agent/v1/domain/invocation.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
package agentDomain

import (
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
"github.com/kataras/iris/v12"
)

type InterfaceCall struct {
ExecUuid string `json:"execUuid"`
ServerUrl string `json:"serverUrl"`
Token string `json:"token"`
TenantId consts.TenantId `json:"tenantId"`
Data domain.DebugData `json:"data"`
LocalVarsCache iris.Map `json:"localVarsCache"`
}

type InvokeRequest struct {
ServerUrl string `json:"serverUrl"`
Token string `json:"token"`
Expand Down
18 changes: 0 additions & 18 deletions cmd/agent/v1/domain/webscoket.go
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
package agentDomain

import (
agentExec "github.com/aaronchen2k/deeptest/internal/agent/exec"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/kataras/iris/v12"
)

type WsReq struct {
Act consts.ExecType `json:"act"`

ScenarioExecReq agentExec.ScenarioExecReq `json:"scenarioExecReq"`
PlanExecReq agentExec.PlanExecReq `json:"planExecReq"`
CasesExecReq agentExec.CasesExecReq `json:"casesExecReq"`

MessageReq agentExec.MessageExecReq `json:"messageReq"`
LocalVarsCache iris.Map `json:"localVarsCache"`
TenantId consts.TenantId `json:"tenantId"`
}
4 changes: 2 additions & 2 deletions cmd/agent/v1/handler/exec-by-websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package handler

import (
"encoding/json"
agentDomain "github.com/aaronchen2k/deeptest/cmd/agent/v1/domain"
agentExec "github.com/aaronchen2k/deeptest/internal/agent/exec"
execUtils "github.com/aaronchen2k/deeptest/internal/agent/exec/utils/exec"
"github.com/aaronchen2k/deeptest/internal/agent/service"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *ExecByWebSocketCtrl) OnChat(wsMsg websocket.Message) (err error) {
ctx := websocket.GetContext(c.Conn)
_logUtils.Infof("WebSocket OnChat: remote address=%s, room=%s, msg=%s", ctx.RemoteAddr(), wsMsg.Room, string(wsMsg.Body))

req := agentDomain.WsReq{}
req := agentExec.WsReq{}
err = json.Unmarshal(wsMsg.Body, &req)
if err != nil {
execUtils.SendErrorMsg(err, consts.Processor, &wsMsg)
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/v1/handler/exec-interface.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package handler

import (
"github.com/aaronchen2k/deeptest/cmd/agent/v1/domain"
"github.com/aaronchen2k/deeptest/internal/agent/service"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/pkg/domain"
"github.com/aaronchen2k/deeptest/pkg/domain"
"github.com/aaronchen2k/deeptest/saas/common"
"github.com/kataras/iris/v12"
Expand All @@ -14,7 +14,7 @@ type ExecInterfaceCtrl struct {

// Call
func (c *ExecInterfaceCtrl) Call(ctx iris.Context) {
req := agentDomain.InterfaceCall{}
req := domain.InterfaceCall{}
req.TenantId = c.getTenantId(ctx)
err := ctx.ReadJSON(&req)
if err != nil {
Expand Down
49 changes: 22 additions & 27 deletions cmd/command/action/run.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
package action

import (
agentExec "github.com/aaronchen2k/deeptest/internal/agent/exec"
"github.com/aaronchen2k/deeptest/internal/agent/service"
)

func Run(scenario, plan, env int, server, token string) {
//s.ExecScenarioService.ExecScenario(scenarioId, nil)

if scenario > 0 {
req := agentExec.ScenarioExecReq{
ServerUrl: server,
Token: token,
ScenarioId: scenario,
EnvironmentId: env,
}

service.RunScenario(&req, nil)

} else if plan > 0 {
req := agentExec.PlanExecReq{
ServerUrl: server,
Token: token,
PlanId: plan,
EnvironmentId: env,
}

service.RunPlan(&req, nil)

}
//
//if scenario > 0 {
// req := agentExec.ScenarioExecReq{
// ServerUrl: server,
// Token: token,
// ScenarioId: scenario,
// EnvironmentId: env,
// }
//
// service.RunScenario(nil, nil, &req, nil)
//
//} else if plan > 0 {
// req := agentExec.PlanExecReq{
// ServerUrl: server,
// Token: token,
// PlanId: plan,
// EnvironmentId: env,
// }
//
// service.RunPlan(nil, nil, &req, nil)
//
//}
}
2 changes: 1 addition & 1 deletion cmd/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {

err := cmd.Run()
if err != nil {
fmt.Printf("Failed to start ztf gui, path %s, err %s", pth, err.Error())
fmt.Printf("Failed to start gui, path %s, err %s", pth, err.Error())
}
}

Expand Down
28 changes: 24 additions & 4 deletions cmd/server/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"github.com/aaronchen2k/deeptest/internal/pkg/core/module"
"github.com/aaronchen2k/deeptest/internal/server/middleware"
logUtils "github.com/aaronchen2k/deeptest/pkg/lib/log"
"github.com/snowlyg/helper/arr"
"strings"
"sync"

"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/core/router"
"github.com/kataras/iris/v12/middleware/pprof"
"github.com/snowlyg/helper/arr"
)

// WebServer 服务器
Expand Down Expand Up @@ -70,12 +70,15 @@ func (webServer *WebServer) GetSources() []map[string]string {

r := r
// 去除非接口路径
handerNames := context.HandlersNames(r.Handlers)
if !arr.InArrayS([]string{"GET", "POST", "PUT", "DELETE"}, r.Method) ||
!arr.InArrayS(strings.Split(handerNames, ","), "github.com/snowlyg/multi.(*Verifier).Verify.func1") {
handlerNames := context.HandlersNames(r.Handlers)

if !isApiMethod(r.Method) || !hasPerm(handlerNames) {
logUtils.Infof("NoPerm NAME: %s, PATH: %s, METHOD: %s, NAMES: %s ", r.Name, r.Path, r.Method, handlerNames)

routeLen--
continue
}

go func(r *router.Route) {
route := map[string]string{
"path": r.Path,
Expand Down Expand Up @@ -124,3 +127,20 @@ func DebugParty() module.WebModule {
}
return module.NewModule("/debug", handler)
}

func isApiMethod(method string) bool {
return arr.InArrayS([]string{"GET", "POST", "PUT", "DELETE"}, method)
}
func hasPerm(handlerNames string) bool {
names := strings.Split(handlerNames, ",")

hasPerm := false
for _, name := range names {
if strings.Index(name, ".Casbin") > -1 {
hasPerm = true
break
}
}

return hasPerm
}
Loading

0 comments on commit 78b2196

Please sign in to comment.