实现集群自定义页面

This commit is contained in:
刘祥超
2023-05-22 17:30:08 +08:00
parent 2af8e6c7f8
commit 47c0ade078
8 changed files with 1720 additions and 987 deletions

View File

@@ -2881,7 +2881,10 @@
"responseMessageName": "RPCSuccess",
"code": "rpc updateHTTPHeaderPolicyNonStandardHeaders(UpdateHTTPHeaderPolicyNonStandardHeadersRequest) returns (RPCSuccess);",
"doc": "修改非标的Headers",
"roles": [],
"roles": [
"admin",
"user"
],
"isDeprecated": false
},
{
@@ -5586,6 +5589,15 @@
],
"isDeprecated": false
},
{
"name": "findNodeHTTPPagesPolicies",
"requestMessageName": "FindNodeHTTPPagesPoliciesRequest",
"responseMessageName": "FindNodeHTTPPagesPoliciesResponse",
"code": "rpc findNodeHTTPPagesPolicies(FindNodeHTTPPagesPoliciesRequest) returns (FindNodeHTTPPagesPoliciesResponse);",
"doc": "查找节点的自定义页面策略",
"roles": [],
"isDeprecated": false
},
{
"name": "findNodeScheduleInfo",
"requestMessageName": "FindNodeScheduleInfoRequest",
@@ -6194,6 +6206,28 @@
"admin"
],
"isDeprecated": false
},
{
"name": "findNodeClusterHTTPPagesPolicy",
"requestMessageName": "FindNodeClusterHTTPPagesPolicyRequest",
"responseMessageName": "FindNodeClusterHTTPPagesPolicyResponse",
"code": "rpc findNodeClusterHTTPPagesPolicy(FindNodeClusterHTTPPagesPolicyRequest) returns (FindNodeClusterHTTPPagesPolicyResponse);",
"doc": "获取集群的自定义页面设置",
"roles": [
"admin"
],
"isDeprecated": false
},
{
"name": "updateNodeClusterHTTPPagesPolicy",
"requestMessageName": "UpdateNodeClusterHTTPPagesPolicyRequest",
"responseMessageName": "RPCSuccess",
"code": "rpc updateNodeClusterHTTPPagesPolicy(UpdateNodeClusterHTTPPagesPolicyRequest) returns (RPCSuccess);",
"doc": "修改集群的自定义页面设置",
"roles": [
"admin"
],
"isDeprecated": false
}
],
"filename": "service_node_cluster.proto",
@@ -17782,7 +17816,7 @@
},
{
"name": "FindEnabledNodeClusterConfigInfoResponse",
"code": "message FindEnabledNodeClusterConfigInfoResponse {\n\tbool healthCheckIsOn = 1;\n\tbool hasFirewallActions = 2;\n\tbool hasThresholds = 3;\n\tbool hasMessageReceivers = 4;\n\tbool isTOAEnabled = 5;\n\tbool hasMetricItems = 6;\n\tbool webpIsOn = 7;\n\tbool uamIsOn = 10;\n\tbool hasSystemServices = 8;\n\tbool hasDDoSProtection = 9;\n}",
"code": "message FindEnabledNodeClusterConfigInfoResponse {\n\tbool healthCheckIsOn = 1;\n\tbool hasFirewallActions = 2;\n\tbool hasThresholds = 3;\n\tbool hasMessageReceivers = 4;\n\tbool isTOAEnabled = 5;\n\tbool hasMetricItems = 6;\n\tbool webpIsOn = 7; // 是否定义了WebP策略\n\tbool uamIsOn = 10; // 是否定义了UAM策略\n\tbool hasSystemServices = 8;\n\tbool hasDDoSProtection = 9;\n\tbool hasHTTPPagesPolicy = 11; // 是否设置了自定义页面策略\n}",
"doc": ""
},
{
@@ -18935,6 +18969,16 @@
"code": "message FindNodeClusterGlobalServerConfigResponse {\n\tbytes globalServerConfigJSON = 1;\n}",
"doc": ""
},
{
"name": "FindNodeClusterHTTPPagesPolicyRequest",
"code": "message FindNodeClusterHTTPPagesPolicyRequest {\n\tint64 nodeClusterId = 1;\n}",
"doc": "获取集群的自定义页面设置"
},
{
"name": "FindNodeClusterHTTPPagesPolicyResponse",
"code": "message FindNodeClusterHTTPPagesPolicyResponse {\n\tbytes httpPagesPolicyJSON = 1; // HTTP自定义页面策略配置\n}",
"doc": ""
},
{
"name": "FindNodeClusterHealthCheckConfigRequest",
"code": "message FindNodeClusterHealthCheckConfigRequest {\n\tint64 nodeClusterId = 1;\n}",
@@ -18995,6 +19039,16 @@
"code": "message FindNodeGlobalServerConfigResponse {\n\tbytes globalServerConfigJSON = 1;\n}",
"doc": ""
},
{
"name": "FindNodeHTTPPagesPoliciesRequest",
"code": "message FindNodeHTTPPagesPoliciesRequest {\n\tint64 nodeId = 1; // 节点ID\n}",
"doc": "查找节点的自定义页面策略"
},
{
"name": "FindNodeHTTPPagesPoliciesResponse",
"code": "message FindNodeHTTPPagesPoliciesResponse {\n\trepeated HTTPPagesPolicy httpPagesPolicies = 1; // 自定义页面策略列表\n\n\n\tmessage HTTPPagesPolicy {\n\t\tint64 nodeClusterId = 1; // 集群ID\n\t\tbytes httpPagesPolicyJSON = 2; // 自定义页面策略配置\n\t}\n}",
"doc": ""
},
{
"name": "FindNodeInstallStatusRequest",
"code": "message FindNodeInstallStatusRequest {\n\tint64 nodeId = 1;\n}",
@@ -21885,6 +21939,11 @@
"code": "message UpdateNodeClusterHTTPFirewallPolicyIdRequest {\n\tint64 nodeClusterId = 1;\n\tint64 httpFirewallPolicyId = 2;\n}",
"doc": "修改集群的WAF策略"
},
{
"name": "UpdateNodeClusterHTTPPagesPolicyRequest",
"code": "message UpdateNodeClusterHTTPPagesPolicyRequest {\n\tint64 nodeClusterId = 1;\n\tbytes httpPagesPolicyJSON = 2; // HTTP自定义页面策略配置\n}",
"doc": "修改集群的自定义页面设置"
},
{
"name": "UpdateNodeClusterHealthCheckRequest",
"code": "message UpdateNodeClusterHealthCheckRequest {\n\tint64 nodeClusterId = 1;\n\tbytes healthCheckJSON = 2;\n}",

View File

@@ -0,0 +1,28 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package nodeconfigs
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
// HTTPPagesPolicy 全局的HTTP自定义页面设置
type HTTPPagesPolicy struct {
IsOn bool `json:"isOn" yaml:"isOn"` // 是否启用
Pages []*serverconfigs.HTTPPageConfig `json:"pages" yaml:"pages"` // 自定义页面
}
func NewHTTPPagesPolicy() *HTTPPagesPolicy {
return &HTTPPagesPolicy{}
}
func (this *HTTPPagesPolicy) Init() error {
if len(this.Pages) > 0 {
for _, page := range this.Pages {
err := page.Init()
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -24,6 +24,7 @@ import (
var sharedNodeConfig *NodeConfig = nil
var uamPolicyLocker = &sync.RWMutex{}
var httpPagesPolicyLocker = &sync.RWMutex{}
type ServerError struct {
Id int64
@@ -98,7 +99,10 @@ type NodeConfig struct {
WebPImagePolicies map[int64]*WebPImagePolicy `yaml:"webpImagePolicies" json:"webpImagePolicies"` // clusterId => *WebPImagePolicy
// UAM相关配置
UAMPolicies map[int64]*UAMPolicy `yaml:"uamPolicies" yaml:"uamPolicies" json:"uamPolicies"` // clusterId => *UAMPolicy
UAMPolicies map[int64]*UAMPolicy `yaml:"uamPolicies" json:"uamPolicies"` // clusterId => *UAMPolicy
// 自定义页面
HTTPPagesPolicies map[int64]*HTTPPagesPolicy `yaml:"httpPagesPolicies" json:"httpPagesPolicies"` // clusterId => *HTTPPagesPolicy
// DNS
DNSResolver *DNSResolverConfig `yaml:"dnsResolver" json:"dnsResolver"`
@@ -196,6 +200,9 @@ func CloneNodeConfig(nodeConfig *NodeConfig) (*NodeConfig, error) {
uamPolicyLocker.RLock()
defer uamPolicyLocker.RUnlock()
httpPagesPolicyLocker.RLock()
defer httpPagesPolicyLocker.RUnlock()
var newConfigValue = reflect.Indirect(reflect.ValueOf(&NodeConfig{}))
var oldValue = reflect.Indirect(reflect.ValueOf(nodeConfig))
var valueType = oldValue.Type()
@@ -381,7 +388,7 @@ func (this *NodeConfig) Init(ctx context.Context) (err error, serverErrors []*Se
// uam policy
uamPolicyLocker.RLock()
if this.UAMPolicies != nil {
if len(this.UAMPolicies) > 0 {
for _, policy := range this.UAMPolicies {
err = policy.Init()
if err != nil {
@@ -392,6 +399,19 @@ func (this *NodeConfig) Init(ctx context.Context) (err error, serverErrors []*Se
}
uamPolicyLocker.RUnlock()
// http pages
httpPagesPolicyLocker.RLock()
if len(this.HTTPPagesPolicies) > 0 {
for _, policy := range this.HTTPPagesPolicies {
err = policy.Init()
if err != nil {
httpPagesPolicyLocker.RUnlock()
return
}
}
}
httpPagesPolicyLocker.RUnlock()
// dns resolver
if this.DNSResolver != nil {
err = this.DNSResolver.Init()
@@ -632,6 +652,23 @@ func (this *NodeConfig) UpdateUAMPolicies(policies map[int64]*UAMPolicy) {
this.UAMPolicies = policies
}
// UpdateHTTPPagesPolicies 修改集群自定义页面策略
func (this *NodeConfig) UpdateHTTPPagesPolicies(policies map[int64]*HTTPPagesPolicy) {
httpPagesPolicyLocker.Lock()
defer httpPagesPolicyLocker.Unlock()
this.HTTPPagesPolicies = policies
}
// FindHTTPPagesPolicyWithClusterId 使用集群ID查找自定义页面策略
func (this *NodeConfig) FindHTTPPagesPolicyWithClusterId(clusterId int64) *HTTPPagesPolicy {
httpPagesPolicyLocker.RLock()
defer httpPagesPolicyLocker.RUnlock()
if this.HTTPPagesPolicies == nil {
return nil
}
return this.HTTPPagesPolicies[clusterId]
}
// SecretHash 对Id和Secret的Hash计算
func (this *NodeConfig) SecretHash() string {
return this.secretHash

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -173,6 +173,9 @@ service NodeService {
// 查找节点的UAM策略
rpc findNodeUAMPolicies(FindNodeUAMPoliciesRequest) returns (FindNodeUAMPoliciesResponse);
// 查找节点的自定义页面策略
rpc findNodeHTTPPagesPolicies(FindNodeHTTPPagesPoliciesRequest) returns (FindNodeHTTPPagesPoliciesResponse);
// 查找节点调度信息
rpc findNodeScheduleInfo(FindNodeScheduleInfoRequest) returns (FindNodeScheduleInfoResponse);
@@ -698,6 +701,20 @@ message FindNodeUAMPoliciesResponse {
}
}
// 查找节点的自定义页面策略
message FindNodeHTTPPagesPoliciesRequest {
int64 nodeId = 1; // 节点ID
}
message FindNodeHTTPPagesPoliciesResponse {
repeated HTTPPagesPolicy httpPagesPolicies = 1; // 自定义页面策略列表
message HTTPPagesPolicy {
int64 nodeClusterId = 1; // 集群ID
bytes httpPagesPolicyJSON = 2; // 自定义页面策略配置
}
}
// 查找节点调度信息
message FindNodeScheduleInfoRequest {
int64 nodeId = 1; // 节点ID

View File

@@ -140,6 +140,12 @@ service NodeClusterService {
// 修改集群的全局服务设置
rpc updateNodeClusterGlobalServerConfig(UpdateNodeClusterGlobalServerConfigRequest) returns (RPCSuccess);
// 获取集群的自定义页面设置
rpc findNodeClusterHTTPPagesPolicy(FindNodeClusterHTTPPagesPolicyRequest) returns (FindNodeClusterHTTPPagesPolicyResponse);
// 修改集群的自定义页面设置
rpc updateNodeClusterHTTPPagesPolicy(UpdateNodeClusterHTTPPagesPolicyRequest) returns (RPCSuccess);
}
// 获取所有集群的信息
@@ -456,10 +462,11 @@ message FindEnabledNodeClusterConfigInfoResponse {
bool hasMessageReceivers = 4;
bool isTOAEnabled = 5;
bool hasMetricItems = 6;
bool webpIsOn = 7;
bool uamIsOn = 10;
bool webpIsOn = 7; // 是否定义了WebP策略
bool uamIsOn = 10; // 是否定义了UAM策略
bool hasSystemServices = 8;
bool hasDDoSProtection = 9;
bool hasHTTPPagesPolicy = 11; // 是否设置了自定义页面策略
}
// 设置集群是否置顶
@@ -526,4 +533,19 @@ message FindNodeClusterGlobalServerConfigResponse {
message UpdateNodeClusterGlobalServerConfigRequest {
int64 nodeClusterId = 1;
bytes globalServerConfigJSON = 2;
}
// 获取集群的自定义页面设置
message FindNodeClusterHTTPPagesPolicyRequest {
int64 nodeClusterId = 1;
}
message FindNodeClusterHTTPPagesPolicyResponse {
bytes httpPagesPolicyJSON = 1; // HTTP自定义页面策略配置
}
// 修改集群的自定义页面设置
message UpdateNodeClusterHTTPPagesPolicyRequest {
int64 nodeClusterId = 1;
bytes httpPagesPolicyJSON = 2; // HTTP自定义页面策略配置
}

View File

@@ -11,13 +11,13 @@ const (
func FindAllBodyTypes() []*Definition {
return []*Definition{
{
Name: "读取URL",
Code: BodyTypeURL,
},
{
Name: "HTML",
Code: BodyTypeHTML,
},
{
Name: "读取URL",
Code: BodyTypeURL,
},
}
}