|
@@ -14,7 +14,10 @@ import (
|
|
|
)
|
|
|
|
|
|
// AidedWebService Web转发辅助服务接口
|
|
|
-type AidedWebServiceInterface interface {
|
|
|
+type AidedWebService interface {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// 数据准备辅助函数
|
|
|
PrepareWafData(ctx context.Context, req *v1.WebForwardingRequest) (common.RequireResponse, v1.Website, error)
|
|
|
BuildProxyConfig(ctx context.Context, req *v1.WebForwardingRequest, gatewayIps []string) (v1.TypeJSON, error)
|
|
@@ -28,6 +31,19 @@ type AidedWebServiceInterface interface {
|
|
|
BuildWebForwardingModel(req *v1.WebForwardingDataRequest, ruleId int, require common.RequireResponse) *model.WebForwarding
|
|
|
BuildWebRuleModel(reqData *v1.WebForwardingDataRequest, require common.RequireResponse, localDbId int, cdnOriginIds map[string]int64) *model.WebForwardingRule
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Helper
|
|
|
+ Valid
|
|
|
+ Log
|
|
|
+ Database
|
|
|
+ SSLCert
|
|
|
+ Configure
|
|
|
+ CdnWeb
|
|
|
+ Origin
|
|
|
+ Process
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func NewAidedWebService(
|
|
@@ -42,8 +58,8 @@ func NewAidedWebService(
|
|
|
ccIpList waf2.CcIpListService,
|
|
|
gatewayIp common.GatewayipService,
|
|
|
globalLimitRep waf.GlobalLimitRepository,
|
|
|
-) *AidedWebService {
|
|
|
- return &AidedWebService{
|
|
|
+) AidedWebService {
|
|
|
+ return &aidedWebService{
|
|
|
Service: service,
|
|
|
webForwardingRepository: webForwardingRepository,
|
|
|
wafformatter: wafformatter,
|
|
@@ -58,7 +74,7 @@ func NewAidedWebService(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type AidedWebService struct {
|
|
|
+type aidedWebService struct {
|
|
|
*service.Service
|
|
|
webForwardingRepository waf.WebForwardingRepository
|
|
|
wafformatter common.WafFormatterService
|
|
@@ -88,7 +104,7 @@ const (
|
|
|
|
|
|
// BuildWebForwardingModel 辅助函数,用于构建通用的 WebForwarding 模型
|
|
|
// ruleId 是从 WAF 系统获取的 ID
|
|
|
-func (s *AidedWebService) BuildWebForwardingModel(req *v1.WebForwardingDataRequest, ruleId int, require common.RequireResponse) *model.WebForwarding {
|
|
|
+func (s *aidedWebService) BuildWebForwardingModel(req *v1.WebForwardingDataRequest, ruleId int, require common.RequireResponse) *model.WebForwarding {
|
|
|
return &model.WebForwarding{
|
|
|
HostId: require.HostId,
|
|
|
CdnWebId: ruleId,
|
|
@@ -111,7 +127,7 @@ func (s *AidedWebService) BuildWebForwardingModel(req *v1.WebForwardingDataReque
|
|
|
}
|
|
|
|
|
|
// BuildWebRuleModel 构建WebForwardingRule模型
|
|
|
-func (s *AidedWebService) BuildWebRuleModel(reqData *v1.WebForwardingDataRequest, require common.RequireResponse, localDbId int, cdnOriginIds map[string]int64) *model.WebForwardingRule {
|
|
|
+func (s *aidedWebService) BuildWebRuleModel(reqData *v1.WebForwardingDataRequest, require common.RequireResponse, localDbId int, cdnOriginIds map[string]int64) *model.WebForwardingRule {
|
|
|
return &model.WebForwardingRule{
|
|
|
Uid: require.Uid,
|
|
|
HostId: require.HostId,
|
|
@@ -122,7 +138,7 @@ func (s *AidedWebService) BuildWebRuleModel(reqData *v1.WebForwardingDataRequest
|
|
|
}
|
|
|
|
|
|
// getRequire 获取前置配置
|
|
|
-func (s *AidedWebService) getRequire (ctx context.Context, req *v1.WebForwardingRequest) (common.RequireResponse, error) {
|
|
|
+func (s *aidedWebService) getRequire (ctx context.Context, req *v1.WebForwardingRequest) (common.RequireResponse, error) {
|
|
|
// 1. 获取基础配置
|
|
|
require, err := s.wafformatter.Require(ctx, v1.GlobalRequire{
|
|
|
HostId: req.HostId,
|
|
@@ -142,7 +158,7 @@ func (s *AidedWebService) getRequire (ctx context.Context, req *v1.WebForwarding
|
|
|
|
|
|
// PrepareWafData 准备WAF数据
|
|
|
// 职责:协调整个流程,负责获取前置配置和组装最终的 formData。
|
|
|
-func (s *AidedWebService) PrepareWafData(ctx context.Context, req *v1.WebForwardingRequest) (common.RequireResponse, v1.Website, error) {
|
|
|
+func (s *aidedWebService) PrepareWafData(ctx context.Context, req *v1.WebForwardingRequest) (common.RequireResponse, v1.Website, error) {
|
|
|
|
|
|
// 1. 获取前置配置
|
|
|
require, err := s.getRequire(ctx, req)
|
|
@@ -198,7 +214,7 @@ func (s *AidedWebService) PrepareWafData(ctx context.Context, req *v1.WebForward
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (s *AidedWebService) buildSslPolicy(ctx context.Context, data *v1.WebForwardingDataRequest) (v1.SslPolicyRef, error) {
|
|
|
+func (s *aidedWebService) buildSslPolicy(ctx context.Context, data *v1.WebForwardingDataRequest) (v1.SslPolicyRef, error) {
|
|
|
// 如果不是 HTTPS,直接返回关闭状态的 SSL 策略
|
|
|
if data.IsHttps != isHttps {
|
|
|
return v1.SslPolicyRef{
|
|
@@ -228,7 +244,7 @@ func (s *AidedWebService) buildSslPolicy(ctx context.Context, data *v1.WebForwar
|
|
|
|
|
|
// BuildProxyConfig 构建代理配置
|
|
|
// 职责:专门负责处理 HTTP/HTTPS 的差异,并生成对应的 JSON 配置。
|
|
|
-func (s *AidedWebService) BuildProxyConfig(ctx context.Context, req *v1.WebForwardingRequest, gatewayIps []string) (v1.TypeJSON, error) {
|
|
|
+func (s *aidedWebService) BuildProxyConfig(ctx context.Context, req *v1.WebForwardingRequest, gatewayIps []string) (v1.TypeJSON, error) {
|
|
|
// 第一步:构建 SSL 策略。所有复杂的 if/else 都被封装在辅助函数中
|
|
|
sslPolicy, err := s.buildSslPolicy(ctx, &req.WebForwardingData)
|
|
|
if err != nil {
|
|
@@ -270,7 +286,7 @@ func (s *AidedWebService) BuildProxyConfig(ctx context.Context, req *v1.WebForwa
|
|
|
|
|
|
|
|
|
// BulidFormData 构建表单数据
|
|
|
-func (s *AidedWebService) BulidFormData(ctx context.Context, formData v1.Website) (v1.WebsiteSend, error) {
|
|
|
+func (s *aidedWebService) BulidFormData(ctx context.Context, formData v1.Website) (v1.WebsiteSend, error) {
|
|
|
httpJSON, err := json.Marshal(formData.HttpJSON)
|
|
|
if err != nil {
|
|
|
return v1.WebsiteSend{}, err
|
|
@@ -308,7 +324,7 @@ func (s *AidedWebService) BulidFormData(ctx context.Context, formData v1.Website
|
|
|
|
|
|
|
|
|
// GetProtocolType 获取协议类型字符串
|
|
|
-func (s *AidedWebService) GetProtocolType(isHttps int) string {
|
|
|
+func (s *aidedWebService) GetProtocolType(isHttps int) string {
|
|
|
if s.IsHttpsProtocol(isHttps) {
|
|
|
return protocolHttps
|
|
|
}
|
|
@@ -316,7 +332,7 @@ func (s *AidedWebService) GetProtocolType(isHttps int) string {
|
|
|
}
|
|
|
|
|
|
// IsHttpsProtocol 判断是否为HTTPS协议
|
|
|
-func (s *AidedWebService) IsHttpsProtocol(httpsFlag int) bool {
|
|
|
+func (s *aidedWebService) IsHttpsProtocol(httpsFlag int) bool {
|
|
|
return httpsFlag == isHttps
|
|
|
}
|
|
|
|
|
@@ -333,7 +349,7 @@ func (s *AidedWebService) IsHttpsProtocol(httpsFlag int) bool {
|
|
|
|
|
|
|
|
|
// updateWebsiteProtocolAndCert 更新网站协议和证书
|
|
|
-func (s *AidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, isHttps int, cdnWebId int64, formData v1.Website) error {
|
|
|
+func (s *aidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, isHttps int, cdnWebId int64, formData v1.Website) error {
|
|
|
|
|
|
|
|
|
// 切换协议
|
|
@@ -380,7 +396,7 @@ func (s *AidedWebService) updateWebsiteProtocolAndCert(ctx context.Context, isHt
|
|
|
}
|
|
|
|
|
|
// updateWebsiteDomain 更新网站域名
|
|
|
-func (s *AidedWebService) updateWebsiteDomain(ctx context.Context, domain string, cdnWebId int64) error {
|
|
|
+func (s *aidedWebService) updateWebsiteDomain(ctx context.Context, domain string, cdnWebId int64) error {
|
|
|
type serverName struct {
|
|
|
Name string `json:"name" form:"name"`
|
|
|
Type string `json:"type" form:"type"`
|
|
@@ -406,7 +422,7 @@ func (s *AidedWebService) updateWebsiteDomain(ctx context.Context, domain string
|
|
|
}
|
|
|
|
|
|
// updateWebsiteBasicInfo 更新网站基本信息
|
|
|
-func (s *AidedWebService) updateWebsiteBasicInfo(ctx context.Context, cdnWebId int64, tag string) error {
|
|
|
+func (s *aidedWebService) updateWebsiteBasicInfo(ctx context.Context, cdnWebId int64, tag string) error {
|
|
|
// 通过globalLimitRep获取节点ID,这是项目中现有的方法
|
|
|
nodeId, err := s.globalLimitRep.GetNodeId(ctx, int(cdnWebId))
|
|
|
if err != nil {
|