From 45f441ccc0e8922cfee11e5a0f2942d1488972ae Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 18 Mar 2024 10:51:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=82=B9SSH=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=92=8C=E7=A7=81=E9=92=A5=E5=9D=87=E4=BB=A5=E6=8E=A9=E7=A0=81?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/rpc/services/service_node_grant.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/rpc/services/service_node_grant.go b/internal/rpc/services/service_node_grant.go index 65891175..ca612c62 100644 --- a/internal/rpc/services/service_node_grant.go +++ b/internal/rpc/services/service_node_grant.go @@ -10,6 +10,8 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "golang.org/x/crypto/ssh" "net" + "regexp" + "strings" "time" ) @@ -48,6 +50,25 @@ func (this *NodeGrantService) UpdateNodeGrant(ctx context.Context, req *pb.Updat var tx = this.NullTx() + // 从掩码中恢复密码和私钥 + grant, err := models.SharedNodeGrantDAO.FindEnabledNodeGrant(tx, req.NodeGrantId) + if err != nil { + return nil, err + } + if grant == nil { + // do nothing here + return this.Success() + } + + var maskReg = regexp.MustCompile(`^\*+$`) + if len(req.Password) > 0 && maskReg.MatchString(req.Password) { + req.Password = grant.Password + } + + if len(req.PrivateKey) > 0 && strings.HasSuffix(req.PrivateKey, "********") { + req.PrivateKey = grant.PrivateKey + } + err = models.SharedNodeGrantDAO.UpdateGrant(tx, req.NodeGrantId, req.Name, req.Method, req.Username, req.Password, req.PrivateKey, req.Passphrase, req.Description, req.NodeId, req.Su) return this.Success() }