From 43204244cbc455ddc58de29f24e3de5930f6eb7d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 12 Aug 2021 11:04:28 +0800 Subject: [PATCH] =?UTF-8?q?DNS=E8=8A=82=E7=82=B9=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9SSH=E7=99=BB=E5=BD=95=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/build-all.sh | 12 ++++ go.mod | 2 +- .../ns/clusters/cluster/node/update.go | 60 ++++++++++++++++++- .../ns/clusters/cluster/node/update.html | 21 +++++++ .../ns/clusters/cluster/node/update.js | 28 ++++++++- 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/build/build-all.sh b/build/build-all.sh index b8f0e7b6..ad11dad0 100755 --- a/build/build-all.sh +++ b/build/build-all.sh @@ -1,5 +1,17 @@ #!/usr/bin/env bash +ROOT=$(dirname $0) + +# build all nodes +if [ -f $ROOT"/../../EdgeNode/build/build-all-plus.sh" ]; then + echo "==============================" + echo "build all edge-node" + echo "==============================" + cd $ROOT"/../../EdgeNode/build" + ./build-all-plus.sh + cd - +fi + ./build.sh linux amd64 ./build.sh linux 386 ./build.sh linux arm64 diff --git a/go.mod b/go.mod index 70cc6b08..dc8d1cc5 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/TeaOSLab/EdgeAdmin -go 1.15 +go 1.16 replace github.com/TeaOSLab/EdgeCommon => ../EdgeCommon diff --git a/internal/web/actions/default/ns/clusters/cluster/node/update.go b/internal/web/actions/default/ns/clusters/cluster/node/update.go index 3116ab90..47b111c7 100644 --- a/internal/web/actions/default/ns/clusters/cluster/node/update.go +++ b/internal/web/actions/default/ns/clusters/cluster/node/update.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/oplogs" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils" "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" @@ -63,12 +64,52 @@ func (this *UpdateAction) RunGet(params struct { }) } + // 登录信息 + var loginMap maps.Map = nil + if node.NodeLogin != nil { + loginParams := maps.Map{} + if len(node.NodeLogin.Params) > 0 { + err = json.Unmarshal(node.NodeLogin.Params, &loginParams) + if err != nil { + this.ErrorPage(err) + return + } + } + + grantMap := maps.Map{} + grantId := loginParams.GetInt64("grantId") + if grantId > 0 { + grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: grantId}) + if err != nil { + this.ErrorPage(err) + return + } + if grantResp.NodeGrant != nil { + grantMap = maps.Map{ + "id": grantResp.NodeGrant.Id, + "name": grantResp.NodeGrant.Name, + "method": grantResp.NodeGrant.Method, + "methodName": grantutils.FindGrantMethodName(grantResp.NodeGrant.Method), + } + } + } + + loginMap = maps.Map{ + "id": node.NodeLogin.Id, + "name": node.NodeLogin.Name, + "type": node.NodeLogin.Type, + "params": loginParams, + "grant": grantMap, + } + } + this.Data["node"] = maps.Map{ "id": node.Id, "name": node.Name, "ipAddresses": ipAddressMaps, "cluster": clusterMap, "isOn": node.IsOn, + "login": loginMap, } // 所有集群 @@ -93,7 +134,11 @@ func (this *UpdateAction) RunGet(params struct { } func (this *UpdateAction) RunPost(params struct { - LoginId int64 + LoginId int64 + GrantId int64 + SshHost string + SshPort int + NodeId int64 Name string IPAddressesJSON []byte `alias:"ipAddressesJSON"` @@ -139,12 +184,25 @@ func (this *UpdateAction) RunPost(params struct { this.Fail("请至少输入一个IP地址") } + // TODO 检查登录授权 + loginInfo := &pb.NodeLogin{ + Id: params.LoginId, + Name: "SSH", + Type: "ssh", + Params: maps.Map{ + "grantId": params.GrantId, + "host": params.SshHost, + "port": params.SshPort, + }.AsJSON(), + } + // 保存 _, err = this.RPC().NSNodeRPC().UpdateNSNode(this.AdminContext(), &pb.UpdateNSNodeRequest{ NsNodeId: params.NodeId, Name: params.Name, NsClusterId: params.ClusterId, IsOn: params.IsOn, + NodeLogin: loginInfo, }) if err != nil { this.ErrorPage(err) diff --git a/web/views/@default/ns/clusters/cluster/node/update.html b/web/views/@default/ns/clusters/cluster/node/update.html index e8e9410b..d0a9fc48 100644 --- a/web/views/@default/ns/clusters/cluster/node/update.html +++ b/web/views/@default/ns/clusters/cluster/node/update.html @@ -5,6 +5,7 @@

修改节点

+ @@ -31,6 +32,26 @@ + + + + + + + + + + + +
节点名称 *
SSH主机地址 + +

比如192.168.1.100

+
SSH主机端口 + +

比如22。

+
SSH登录认证 + +
是否启用 diff --git a/web/views/@default/ns/clusters/cluster/node/update.js b/web/views/@default/ns/clusters/cluster/node/update.js index 8e1adb9d..ad5aa90e 100644 --- a/web/views/@default/ns/clusters/cluster/node/update.js +++ b/web/views/@default/ns/clusters/cluster/node/update.js @@ -5,4 +5,30 @@ Tea.context(function () { } this.success = NotifySuccess("保存成功", "/ns/clusters/cluster/node?clusterId=" + this.clusterId + "&nodeId=" + this.node.id); -}); \ No newline at end of file + + // 认证相关 + this.grant = null + + this.sshHost = "" + this.sshPort = "" + this.loginId = 0 + if (this.node.login != null) { + this.loginId = this.node.login.id + + if (this.node.login.params != null) { + this.sshHost = this.node.login.params.host + if (this.node.login.params.port > 0) { + this.sshPort = this.node.login.params.port + } + } + + if (this.node.login.grant != null && typeof this.node.login.grant.id != "undefined") { + this.grant = { + id: this.node.login.grant.id, + name: this.node.login.grant.name, + method: this.node.login.grant.method, + methodName: this.node.login.grant.methodName + } + } + } +}) \ No newline at end of file