From 96971cb23c1864200619e646ed091577bb6378a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Mon, 18 Jan 2021 20:40:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=88=9B=E5=BB=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E9=98=B2=E7=81=AB=E5=A2=99=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/service_http_firewall_policy.go | 37 +++++++++++++++++++ internal/rpc/services/service_node_stream.go | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/internal/rpc/services/service_http_firewall_policy.go b/internal/rpc/services/service_http_firewall_policy.go index 26778abe..65dc4c71 100644 --- a/internal/rpc/services/service_http_firewall_policy.go +++ b/internal/rpc/services/service_http_firewall_policy.go @@ -114,6 +114,43 @@ func (this *HTTPFirewallPolicyService) CreateHTTPFirewallPolicy(ctx context.Cont return &pb.CreateHTTPFirewallPolicyResponse{HttpFirewallPolicyId: policyId}, nil } +// 创建空防火墙策略 +func (this *HTTPFirewallPolicyService) CreateEmptyHTTPFirewallPolicy(ctx context.Context, req *pb.CreateEmptyHTTPFirewallPolicyRequest) (*pb.CreateEmptyHTTPFirewallPolicyResponse, error) { + // 校验请求 + _, userId, err := this.ValidateAdminAndUser(ctx, 0, 0) + if err != nil { + return nil, err + } + + tx := this.NullTx() + + policyId, err := models.SharedHTTPFirewallPolicyDAO.CreateFirewallPolicy(tx, userId, req.IsOn, req.Name, req.Description, nil, nil) + if err != nil { + return nil, err + } + + // 初始化 + inboundConfig := &firewallconfigs.HTTPFirewallInboundConfig{IsOn: true} + outboundConfig := &firewallconfigs.HTTPFirewallOutboundConfig{IsOn: true} + + inboundConfigJSON, err := json.Marshal(inboundConfig) + if err != nil { + return nil, err + } + + outboundConfigJSON, err := json.Marshal(outboundConfig) + if err != nil { + return nil, err + } + + err = models.SharedHTTPFirewallPolicyDAO.UpdateFirewallPolicyInboundAndOutbound(tx, policyId, inboundConfigJSON, outboundConfigJSON) + if err != nil { + return nil, err + } + + return &pb.CreateEmptyHTTPFirewallPolicyResponse{HttpFirewallPolicyId: policyId}, nil +} + // 修改防火墙策略 func (this *HTTPFirewallPolicyService) UpdateHTTPFirewallPolicy(ctx context.Context, req *pb.UpdateHTTPFirewallPolicyRequest) (*pb.RPCSuccess, error) { // 校验请求 diff --git a/internal/rpc/services/service_node_stream.go b/internal/rpc/services/service_node_stream.go index 6d8585f7..d7052335 100644 --- a/internal/rpc/services/service_node_stream.go +++ b/internal/rpc/services/service_node_stream.go @@ -135,7 +135,7 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro case <-server.Context().Done(): return case commandRequest := <-requestChan: - logs.Println("[RPC]sending command '" + commandRequest.Code + "' to node '" + strconv.FormatInt(nodeId, 10) + "'") + // logs.Println("[RPC]sending command '" + commandRequest.Code + "' to node '" + strconv.FormatInt(nodeId, 10) + "'") retries := 3 // 错误重试次数 for i := 0; i < retries; i++ { err := server.Send(&pb.NodeStreamMessage{