mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-15 09:10:24 +08:00
优化服务配置组合
This commit is contained in:
@@ -150,7 +150,7 @@ func (this *HTTPLocationDAO) UpdateLocation(tx *dbs.Tx, locationId int64, name s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ComposeLocationConfig 组合配置
|
// ComposeLocationConfig 组合配置
|
||||||
func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64, cacheMap *utils.CacheMap) (*serverconfigs.HTTPLocationConfig, error) {
|
func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64, forNode bool, cacheMap *utils.CacheMap) (*serverconfigs.HTTPLocationConfig, error) {
|
||||||
if cacheMap == nil {
|
if cacheMap == nil {
|
||||||
cacheMap = utils.NewCacheMap()
|
cacheMap = utils.NewCacheMap()
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64,
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &serverconfigs.HTTPLocationConfig{}
|
var config = &serverconfigs.HTTPLocationConfig{}
|
||||||
config.Id = int64(location.Id)
|
config.Id = int64(location.Id)
|
||||||
config.IsOn = location.IsOn
|
config.IsOn = location.IsOn
|
||||||
config.Description = location.Description
|
config.Description = location.Description
|
||||||
@@ -179,7 +179,7 @@ func (this *HTTPLocationDAO) ComposeLocationConfig(tx *dbs.Tx, locationId int64,
|
|||||||
|
|
||||||
// web
|
// web
|
||||||
if location.WebId > 0 {
|
if location.WebId > 0 {
|
||||||
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(location.WebId), cacheMap)
|
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(location.WebId), true, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -292,13 +292,13 @@ func (this *HTTPLocationDAO) UpdateLocationWeb(tx *dbs.Tx, locationId int64, web
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConvertLocationRefs 转换引用为配置
|
// ConvertLocationRefs 转换引用为配置
|
||||||
func (this *HTTPLocationDAO) ConvertLocationRefs(tx *dbs.Tx, refs []*serverconfigs.HTTPLocationRef, cacheMap *utils.CacheMap) (locations []*serverconfigs.HTTPLocationConfig, err error) {
|
func (this *HTTPLocationDAO) ConvertLocationRefs(tx *dbs.Tx, refs []*serverconfigs.HTTPLocationRef, forNode bool, cacheMap *utils.CacheMap) (locations []*serverconfigs.HTTPLocationConfig, err error) {
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
config, err := this.ComposeLocationConfig(tx, ref.LocationId, cacheMap)
|
config, err := this.ComposeLocationConfig(tx, ref.LocationId, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
children, err := this.ConvertLocationRefs(tx, ref.Children, cacheMap)
|
children, err := this.ConvertLocationRefs(tx, ref.Children, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ComposeWebConfig 组合配置
|
// ComposeWebConfig 组合配置
|
||||||
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *utils.CacheMap) (*serverconfigs.HTTPWebConfig, error) {
|
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, isLocationOrGroup bool, forNode bool, cacheMap *utils.CacheMap) (*serverconfigs.HTTPWebConfig, error) {
|
||||||
if cacheMap == nil {
|
if cacheMap == nil {
|
||||||
cacheMap = utils.NewCacheMap()
|
cacheMap = utils.NewCacheMap()
|
||||||
}
|
}
|
||||||
@@ -101,68 +101,76 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
|
|
||||||
// root
|
// root
|
||||||
if IsNotNull(web.Root) {
|
if IsNotNull(web.Root) {
|
||||||
rootConfig := &serverconfigs.HTTPRootConfig{}
|
var rootConfig = &serverconfigs.HTTPRootConfig{}
|
||||||
err = json.Unmarshal(web.Root, rootConfig)
|
err = json.Unmarshal(web.Root, rootConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, rootConfig.IsPrior, rootConfig.IsOn) {
|
||||||
config.Root = rootConfig
|
config.Root = rootConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// compression
|
// compression
|
||||||
if IsNotNull(web.Compression) {
|
if IsNotNull(web.Compression) {
|
||||||
compression := &serverconfigs.HTTPCompressionConfig{}
|
var compressionConfig = &serverconfigs.HTTPCompressionConfig{}
|
||||||
err = json.Unmarshal(web.Compression, compression)
|
err = json.Unmarshal(web.Compression, compressionConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.Compression = compression
|
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, compressionConfig.IsPrior, compressionConfig.IsOn) {
|
||||||
|
config.Compression = compressionConfig
|
||||||
|
|
||||||
// gzip
|
// gzip
|
||||||
if compression.GzipRef != nil && compression.GzipRef.Id > 0 {
|
if compressionConfig.GzipRef != nil && compressionConfig.GzipRef.Id > 0 {
|
||||||
gzipConfig, err := SharedHTTPGzipDAO.ComposeGzipConfig(tx, compression.GzipRef.Id)
|
gzipConfig, err := SharedHTTPGzipDAO.ComposeGzipConfig(tx, compressionConfig.GzipRef.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
compression.Gzip = gzipConfig
|
compressionConfig.Gzip = gzipConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// brotli
|
// brotli
|
||||||
if compression.BrotliRef != nil && compression.BrotliRef.Id > 0 {
|
if compressionConfig.BrotliRef != nil && compressionConfig.BrotliRef.Id > 0 {
|
||||||
brotliConfig, err := SharedHTTPBrotliPolicyDAO.ComposeBrotliConfig(tx, compression.BrotliRef.Id)
|
brotliConfig, err := SharedHTTPBrotliPolicyDAO.ComposeBrotliConfig(tx, compressionConfig.BrotliRef.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
compression.Brotli = brotliConfig
|
compressionConfig.Brotli = brotliConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// deflate
|
// deflate
|
||||||
if compression.DeflateRef != nil && compression.DeflateRef.Id > 0 {
|
if compressionConfig.DeflateRef != nil && compressionConfig.DeflateRef.Id > 0 {
|
||||||
deflateConfig, err := SharedHTTPDeflatePolicyDAO.ComposeDeflateConfig(tx, compression.DeflateRef.Id)
|
deflateConfig, err := SharedHTTPDeflatePolicyDAO.ComposeDeflateConfig(tx, compressionConfig.DeflateRef.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
compression.Deflate = deflateConfig
|
compressionConfig.Deflate = deflateConfig
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// charset
|
// charset
|
||||||
if IsNotNull(web.Charset) {
|
if IsNotNull(web.Charset) {
|
||||||
charsetConfig := &serverconfigs.HTTPCharsetConfig{}
|
var charsetConfig = &serverconfigs.HTTPCharsetConfig{}
|
||||||
err = json.Unmarshal(web.Charset, charsetConfig)
|
err = json.Unmarshal(web.Charset, charsetConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, charsetConfig.IsPrior, charsetConfig.IsOn) {
|
||||||
config.Charset = charsetConfig
|
config.Charset = charsetConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// headers
|
// headers
|
||||||
if IsNotNull(web.RequestHeader) {
|
if IsNotNull(web.RequestHeader) {
|
||||||
ref := &shared.HTTPHeaderPolicyRef{}
|
var ref = &shared.HTTPHeaderPolicyRef{}
|
||||||
err = json.Unmarshal(web.RequestHeader, ref)
|
err = json.Unmarshal(web.RequestHeader, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, ref.IsPrior, ref.IsOn) {
|
||||||
config.RequestHeaderPolicyRef = ref
|
config.RequestHeaderPolicyRef = ref
|
||||||
|
|
||||||
if ref.HeaderPolicyId > 0 {
|
if ref.HeaderPolicyId > 0 {
|
||||||
@@ -175,13 +183,15 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if IsNotNull(web.ResponseHeader) {
|
if IsNotNull(web.ResponseHeader) {
|
||||||
ref := &shared.HTTPHeaderPolicyRef{}
|
var ref = &shared.HTTPHeaderPolicyRef{}
|
||||||
err = json.Unmarshal(web.ResponseHeader, ref)
|
err = json.Unmarshal(web.ResponseHeader, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, ref.IsPrior, ref.IsOn) {
|
||||||
config.ResponseHeaderPolicyRef = ref
|
config.ResponseHeaderPolicyRef = ref
|
||||||
|
|
||||||
if ref.HeaderPolicyId > 0 {
|
if ref.HeaderPolicyId > 0 {
|
||||||
@@ -194,20 +204,24 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
if IsNotNull(web.Shutdown) {
|
if IsNotNull(web.Shutdown) {
|
||||||
shutdownConfig := &serverconfigs.HTTPShutdownConfig{}
|
var shutdownConfig = &serverconfigs.HTTPShutdownConfig{}
|
||||||
err = json.Unmarshal(web.Shutdown, shutdownConfig)
|
err = json.Unmarshal(web.Shutdown, shutdownConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, shutdownConfig.IsPrior, shutdownConfig.IsOn) {
|
||||||
config.Shutdown = shutdownConfig
|
config.Shutdown = shutdownConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// pages
|
// pages
|
||||||
|
// TODO 检查forNode参数
|
||||||
if IsNotNull(web.Pages) {
|
if IsNotNull(web.Pages) {
|
||||||
pages := []*serverconfigs.HTTPPageConfig{}
|
var pages = []*serverconfigs.HTTPPageConfig{}
|
||||||
err = json.Unmarshal(web.Pages, &pages)
|
err = json.Unmarshal(web.Pages, &pages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -226,43 +240,51 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
|
|
||||||
// 访问日志
|
// 访问日志
|
||||||
if IsNotNull(web.AccessLog) {
|
if IsNotNull(web.AccessLog) {
|
||||||
accessLogConfig := &serverconfigs.HTTPAccessLogRef{}
|
var accessLogConfig = &serverconfigs.HTTPAccessLogRef{}
|
||||||
err = json.Unmarshal(web.AccessLog, accessLogConfig)
|
err = json.Unmarshal(web.AccessLog, accessLogConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, accessLogConfig.IsPrior, accessLogConfig.IsOn) {
|
||||||
config.AccessLogRef = accessLogConfig
|
config.AccessLogRef = accessLogConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 统计配置
|
// 统计配置
|
||||||
if IsNotNull(web.Stat) {
|
if IsNotNull(web.Stat) {
|
||||||
statRef := &serverconfigs.HTTPStatRef{}
|
var statRef = &serverconfigs.HTTPStatRef{}
|
||||||
err = json.Unmarshal(web.Stat, statRef)
|
err = json.Unmarshal(web.Stat, statRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, statRef.IsPrior, statRef.IsOn) {
|
||||||
config.StatRef = statRef
|
config.StatRef = statRef
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 缓存配置
|
// 缓存配置
|
||||||
if IsNotNull(web.Cache) {
|
if IsNotNull(web.Cache) {
|
||||||
cacheConfig := &serverconfigs.HTTPCacheConfig{}
|
var cacheConfig = &serverconfigs.HTTPCacheConfig{}
|
||||||
err = json.Unmarshal(web.Cache, &cacheConfig)
|
err = json.Unmarshal(web.Cache, &cacheConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, cacheConfig.IsPrior, cacheConfig.IsOn) {
|
||||||
config.Cache = cacheConfig
|
config.Cache = cacheConfig
|
||||||
|
}
|
||||||
|
|
||||||
// 暂不支持自定义缓存策略设置,因为同一个集群下的服务需要集中管理
|
// 暂不支持自定义缓存策略设置,因为同一个集群下的服务需要集中管理
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防火墙配置
|
// 防火墙配置
|
||||||
if IsNotNull(web.Firewall) {
|
if IsNotNull(web.Firewall) {
|
||||||
firewallRef := &firewallconfigs.HTTPFirewallRef{}
|
var firewallRef = &firewallconfigs.HTTPFirewallRef{}
|
||||||
err = json.Unmarshal(web.Firewall, firewallRef)
|
err = json.Unmarshal(web.Firewall, firewallRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, firewallRef.IsPrior, firewallRef.IsOn) {
|
||||||
config.FirewallRef = firewallRef
|
config.FirewallRef = firewallRef
|
||||||
|
|
||||||
// 自定义防火墙设置
|
// 自定义防火墙设置
|
||||||
@@ -278,10 +300,12 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 路由规则
|
// 路由规则
|
||||||
|
// TODO 检查forNode参数
|
||||||
if IsNotNull(web.Locations) {
|
if IsNotNull(web.Locations) {
|
||||||
refs := []*serverconfigs.HTTPLocationRef{}
|
var refs = []*serverconfigs.HTTPLocationRef{}
|
||||||
err = json.Unmarshal(web.Locations, &refs)
|
err = json.Unmarshal(web.Locations, &refs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -289,7 +313,7 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if len(refs) > 0 {
|
if len(refs) > 0 {
|
||||||
config.LocationRefs = refs
|
config.LocationRefs = refs
|
||||||
|
|
||||||
locations, err := SharedHTTPLocationDAO.ConvertLocationRefs(tx, refs, cacheMap)
|
locations, err := SharedHTTPLocationDAO.ConvertLocationRefs(tx, refs, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -299,21 +323,24 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
|
|
||||||
// 跳转
|
// 跳转
|
||||||
if IsNotNull(web.RedirectToHttps) {
|
if IsNotNull(web.RedirectToHttps) {
|
||||||
redirectToHTTPSConfig := &serverconfigs.HTTPRedirectToHTTPSConfig{}
|
var redirectToHTTPSConfig = &serverconfigs.HTTPRedirectToHTTPSConfig{}
|
||||||
err = json.Unmarshal(web.RedirectToHttps, redirectToHTTPSConfig)
|
err = json.Unmarshal(web.RedirectToHttps, redirectToHTTPSConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, redirectToHTTPSConfig.IsPrior, redirectToHTTPSConfig.IsOn) {
|
||||||
config.RedirectToHttps = redirectToHTTPSConfig
|
config.RedirectToHttps = redirectToHTTPSConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Websocket
|
// Websocket
|
||||||
if IsNotNull(web.Websocket) {
|
if IsNotNull(web.Websocket) {
|
||||||
ref := &serverconfigs.HTTPWebsocketRef{}
|
var ref = &serverconfigs.HTTPWebsocketRef{}
|
||||||
err = json.Unmarshal(web.Websocket, ref)
|
err = json.Unmarshal(web.Websocket, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, ref.IsPrior, ref.IsOn) {
|
||||||
config.WebsocketRef = ref
|
config.WebsocketRef = ref
|
||||||
if ref.WebsocketId > 0 {
|
if ref.WebsocketId > 0 {
|
||||||
websocketConfig, err := SharedHTTPWebsocketDAO.ComposeWebsocketConfig(tx, ref.WebsocketId)
|
websocketConfig, err := SharedHTTPWebsocketDAO.ComposeWebsocketConfig(tx, ref.WebsocketId)
|
||||||
@@ -325,10 +352,12 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 重写规则
|
// 重写规则
|
||||||
|
// TODO 检查forNode参数
|
||||||
if IsNotNull(web.RewriteRules) {
|
if IsNotNull(web.RewriteRules) {
|
||||||
refs := []*serverconfigs.HTTPRewriteRef{}
|
var refs = []*serverconfigs.HTTPRewriteRef{}
|
||||||
err = json.Unmarshal(web.RewriteRules, &refs)
|
err = json.Unmarshal(web.RewriteRules, &refs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -346,8 +375,9 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 主机跳转
|
// 主机跳转
|
||||||
|
// TODO 检查forNode参数
|
||||||
if IsNotNull(web.HostRedirects) {
|
if IsNotNull(web.HostRedirects) {
|
||||||
redirects := []*serverconfigs.HTTPHostRedirectConfig{}
|
var redirects = []*serverconfigs.HTTPHostRedirectConfig{}
|
||||||
err = json.Unmarshal(web.HostRedirects, &redirects)
|
err = json.Unmarshal(web.HostRedirects, &redirects)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -357,11 +387,13 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
|
|
||||||
// Fastcgi
|
// Fastcgi
|
||||||
if IsNotNull(web.Fastcgi) {
|
if IsNotNull(web.Fastcgi) {
|
||||||
ref := &serverconfigs.HTTPFastcgiRef{}
|
var ref = &serverconfigs.HTTPFastcgiRef{}
|
||||||
err = json.Unmarshal(web.Fastcgi, ref)
|
err = json.Unmarshal(web.Fastcgi, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, ref.IsPrior, ref.IsOn) {
|
||||||
config.FastcgiRef = ref
|
config.FastcgiRef = ref
|
||||||
|
|
||||||
if len(ref.FastcgiIds) > 0 {
|
if len(ref.FastcgiIds) > 0 {
|
||||||
@@ -378,6 +410,7 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
config.FastcgiList = list
|
config.FastcgiList = list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 认证
|
// 认证
|
||||||
if IsNotNull(web.Auth) {
|
if IsNotNull(web.Auth) {
|
||||||
@@ -386,6 +419,7 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, authConfig.IsPrior, authConfig.IsOn) {
|
||||||
var newRefs []*serverconfigs.HTTPAuthPolicyRef
|
var newRefs []*serverconfigs.HTTPAuthPolicyRef
|
||||||
for _, ref := range authConfig.PolicyRefs {
|
for _, ref := range authConfig.PolicyRefs {
|
||||||
policyConfig, err := SharedHTTPAuthPolicyDAO.ComposePolicyConfig(tx, ref.AuthPolicyId, cacheMap)
|
policyConfig, err := SharedHTTPAuthPolicyDAO.ComposePolicyConfig(tx, ref.AuthPolicyId, cacheMap)
|
||||||
@@ -400,6 +434,7 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
}
|
}
|
||||||
config.Auth = authConfig
|
config.Auth = authConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WebP
|
// WebP
|
||||||
if IsNotNull(web.Webp) {
|
if IsNotNull(web.Webp) {
|
||||||
@@ -408,8 +443,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, webpConfig.IsPrior, webpConfig.IsOn) {
|
||||||
config.WebP = webpConfig
|
config.WebP = webpConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RemoteAddr
|
// RemoteAddr
|
||||||
if IsNotNull(web.RemoteAddr) {
|
if IsNotNull(web.RemoteAddr) {
|
||||||
@@ -418,8 +455,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, remoteAddrConfig.IsPrior, remoteAddrConfig.IsOn) {
|
||||||
config.RemoteAddr = remoteAddrConfig
|
config.RemoteAddr = remoteAddrConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mergeSlashes
|
// mergeSlashes
|
||||||
config.MergeSlashes = web.MergeSlashes == 1
|
config.MergeSlashes = web.MergeSlashes == 1
|
||||||
@@ -427,26 +466,25 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
// 请求限制
|
// 请求限制
|
||||||
if len(web.RequestLimit) > 0 {
|
if len(web.RequestLimit) > 0 {
|
||||||
var requestLimitConfig = &serverconfigs.HTTPRequestLimitConfig{}
|
var requestLimitConfig = &serverconfigs.HTTPRequestLimitConfig{}
|
||||||
if len(web.RequestLimit) > 0 {
|
|
||||||
err = json.Unmarshal(web.RequestLimit, requestLimitConfig)
|
err = json.Unmarshal(web.RequestLimit, requestLimitConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, requestLimitConfig.IsPrior, requestLimitConfig.IsOn) {
|
||||||
config.RequestLimit = requestLimitConfig
|
config.RequestLimit = requestLimitConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求脚本
|
// 请求脚本
|
||||||
|
// TODO 检查forNode设置
|
||||||
if len(web.RequestScripts) > 0 {
|
if len(web.RequestScripts) > 0 {
|
||||||
var requestScriptsConfig = &serverconfigs.HTTPRequestScriptsConfig{}
|
var requestScriptsConfig = &serverconfigs.HTTPRequestScriptsConfig{}
|
||||||
if len(web.RequestScripts) > 0 {
|
|
||||||
err = json.Unmarshal(web.RequestScripts, requestScriptsConfig)
|
err = json.Unmarshal(web.RequestScripts, requestScriptsConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.RequestScripts = requestScriptsConfig
|
config.RequestScripts = requestScriptsConfig
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// UAM
|
// UAM
|
||||||
if teaconst.IsPlus && IsNotNull(web.Uam) {
|
if teaconst.IsPlus && IsNotNull(web.Uam) {
|
||||||
@@ -455,8 +493,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, uamConfig.IsPrior, uamConfig.IsOn) {
|
||||||
config.UAM = uamConfig
|
config.UAM = uamConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CC
|
// CC
|
||||||
if teaconst.IsPlus && IsNotNull(web.Cc) {
|
if teaconst.IsPlus && IsNotNull(web.Cc) {
|
||||||
@@ -465,8 +505,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, ccConfig.IsPrior, ccConfig.IsOn) {
|
||||||
config.CC = ccConfig
|
config.CC = ccConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Referers
|
// Referers
|
||||||
if IsNotNull(web.Referers) {
|
if IsNotNull(web.Referers) {
|
||||||
@@ -475,8 +517,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, referersConfig.IsPrior, referersConfig.IsOn) {
|
||||||
config.Referers = referersConfig
|
config.Referers = referersConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// User-Agent
|
// User-Agent
|
||||||
if IsNotNull(web.UserAgent) {
|
if IsNotNull(web.UserAgent) {
|
||||||
@@ -485,8 +529,10 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *util
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if this.shouldCompose(isLocationOrGroup, forNode, userAgentConfig.IsPrior, userAgentConfig.IsOn) {
|
||||||
config.UserAgent = userAgentConfig
|
config.UserAgent = userAgentConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cacheMap != nil {
|
if cacheMap != nil {
|
||||||
cacheMap.Put(cacheKey, config)
|
cacheMap.Put(cacheKey, config)
|
||||||
@@ -1352,3 +1398,11 @@ func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否应该组合配置
|
||||||
|
func (this *HTTPWebDAO) shouldCompose(isLocationOrGroup bool, forNode bool, isPrior bool, isOn bool) bool {
|
||||||
|
if !forNode {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return (!isLocationOrGroup && isOn) || (isLocationOrGroup && isPrior)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1039,7 +1039,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
|
|
||||||
var groupConfig *serverconfigs.ServerGroupConfig
|
var groupConfig *serverconfigs.ServerGroupConfig
|
||||||
for _, groupId := range server.DecodeGroupIds() {
|
for _, groupId := range server.DecodeGroupIds() {
|
||||||
groupConfig1, err := SharedServerGroupDAO.ComposeGroupConfig(tx, groupId, forList, cacheMap)
|
groupConfig1, err := SharedServerGroupDAO.ComposeGroupConfig(tx, groupId, forNode, forList, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1098,8 +1098,10 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !forNode || httpConfig.IsOn {
|
||||||
config.HTTP = httpConfig
|
config.HTTP = httpConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HTTPS
|
// HTTPS
|
||||||
if IsNotNull(server.Https) {
|
if IsNotNull(server.Https) {
|
||||||
@@ -1109,6 +1111,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !forNode || httpsConfig.IsOn {
|
||||||
// SSL
|
// SSL
|
||||||
if httpsConfig.SSLPolicyRef != nil && httpsConfig.SSLPolicyRef.SSLPolicyId > 0 && !ignoreCerts {
|
if httpsConfig.SSLPolicyRef != nil && httpsConfig.SSLPolicyRef.SSLPolicyId > 0 && !ignoreCerts {
|
||||||
sslPolicyConfig, err := SharedSSLPolicyDAO.ComposePolicyConfig(tx, httpsConfig.SSLPolicyRef.SSLPolicyId, false, cacheMap)
|
sslPolicyConfig, err := SharedSSLPolicyDAO.ComposePolicyConfig(tx, httpsConfig.SSLPolicyRef.SSLPolicyId, false, cacheMap)
|
||||||
@@ -1122,6 +1125,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
|
|
||||||
config.HTTPS = httpsConfig
|
config.HTTPS = httpsConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TCP
|
// TCP
|
||||||
if IsNotNull(server.Tcp) {
|
if IsNotNull(server.Tcp) {
|
||||||
@@ -1130,8 +1134,10 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !forNode || tcpConfig.IsOn {
|
||||||
config.TCP = tcpConfig
|
config.TCP = tcpConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TLS
|
// TLS
|
||||||
if IsNotNull(server.Tls) {
|
if IsNotNull(server.Tls) {
|
||||||
@@ -1141,6 +1147,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !forNode || tlsConfig.IsOn {
|
||||||
// SSL
|
// SSL
|
||||||
if tlsConfig.SSLPolicyRef != nil && !ignoreCerts {
|
if tlsConfig.SSLPolicyRef != nil && !ignoreCerts {
|
||||||
sslPolicyConfig, err := SharedSSLPolicyDAO.ComposePolicyConfig(tx, tlsConfig.SSLPolicyRef.SSLPolicyId, false, cacheMap)
|
sslPolicyConfig, err := SharedSSLPolicyDAO.ComposePolicyConfig(tx, tlsConfig.SSLPolicyRef.SSLPolicyId, false, cacheMap)
|
||||||
@@ -1154,6 +1161,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
|
|
||||||
config.TLS = tlsConfig
|
config.TLS = tlsConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Unix
|
// Unix
|
||||||
if IsNotNull(server.Unix) {
|
if IsNotNull(server.Unix) {
|
||||||
@@ -1162,8 +1170,10 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !forNode || unixConfig.IsOn {
|
||||||
config.Unix = unixConfig
|
config.Unix = unixConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UDP
|
// UDP
|
||||||
if IsNotNull(server.Udp) {
|
if IsNotNull(server.Udp) {
|
||||||
@@ -1172,13 +1182,15 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !forNode || udpConfig.IsOn {
|
||||||
config.UDP = udpConfig
|
config.UDP = udpConfig
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Web
|
// Web
|
||||||
if !forList {
|
if !forList {
|
||||||
if server.WebId > 0 {
|
if server.WebId > 0 {
|
||||||
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(server.WebId), cacheMap)
|
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(server.WebId), false, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1196,6 +1208,7 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if !forNode || reverseProxyRef.IsOn {
|
||||||
config.ReverseProxyRef = reverseProxyRef
|
config.ReverseProxyRef = reverseProxyRef
|
||||||
|
|
||||||
reverseProxyConfig, err := SharedReverseProxyDAO.ComposeReverseProxyConfig(tx, reverseProxyRef.ReverseProxyId, cacheMap)
|
reverseProxyConfig, err := SharedReverseProxyDAO.ComposeReverseProxyConfig(tx, reverseProxyRef.ReverseProxyId, cacheMap)
|
||||||
@@ -1203,10 +1216,13 @@ func (this *ServerDAO) ComposeServerConfig(tx *dbs.Tx, server *Server, ignoreCer
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if reverseProxyConfig != nil {
|
if reverseProxyConfig != nil {
|
||||||
|
if !forNode || reverseProxyConfig.IsOn {
|
||||||
config.ReverseProxy = reverseProxyConfig
|
config.ReverseProxy = reverseProxyConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WAF策略
|
// WAF策略
|
||||||
var clusterId = int64(server.ClusterId)
|
var clusterId = int64(server.ClusterId)
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ func (this *ServerGroupDAO) InitGroupWeb(tx *dbs.Tx, groupId int64) (int64, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ComposeGroupConfig 组合配置
|
// ComposeGroupConfig 组合配置
|
||||||
func (this *ServerGroupDAO) ComposeGroupConfig(tx *dbs.Tx, groupId int64, forList bool, cacheMap *utils.CacheMap) (*serverconfigs.ServerGroupConfig, error) {
|
func (this *ServerGroupDAO) ComposeGroupConfig(tx *dbs.Tx, groupId int64, forNode bool, forList bool, cacheMap *utils.CacheMap) (*serverconfigs.ServerGroupConfig, error) {
|
||||||
if cacheMap == nil {
|
if cacheMap == nil {
|
||||||
cacheMap = utils.NewCacheMap()
|
cacheMap = utils.NewCacheMap()
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ func (this *ServerGroupDAO) ComposeGroupConfig(tx *dbs.Tx, groupId int64, forLis
|
|||||||
|
|
||||||
// web
|
// web
|
||||||
if group.WebId > 0 {
|
if group.WebId > 0 {
|
||||||
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(group.WebId), cacheMap)
|
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(tx, int64(group.WebId), true, forNode, cacheMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func (this *HTTPLocationService) FindEnabledHTTPLocationConfig(ctx context.Conte
|
|||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
|
|
||||||
config, err := models.SharedHTTPLocationDAO.ComposeLocationConfig(tx, req.LocationId, nil)
|
config, err := models.SharedHTTPLocationDAO.ComposeLocationConfig(tx, req.LocationId, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -167,7 +167,7 @@ func (this *HTTPLocationService) FindAndInitHTTPLocationWebConfig(ctx context.Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, nil)
|
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, true, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, rpcutils.Wrap("ComposeWebConfig()", err)
|
return nil, rpcutils.Wrap("ComposeWebConfig()", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func (this *HTTPWebService) FindEnabledHTTPWebConfig(ctx context.Context, req *p
|
|||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
|
|
||||||
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, req.HttpWebId, nil)
|
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, req.HttpWebId, false, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1191,7 +1191,7 @@ func (this *ServerService) FindAndInitServerWebConfig(ctx context.Context, req *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, nil)
|
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, false, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -463,7 +463,7 @@ func (this *ServerGroupService) FindEnabledServerGroupConfigInfo(ctx context.Con
|
|||||||
result.HasUDPReverseProxy = ref.IsPrior
|
result.HasUDPReverseProxy = ref.IsPrior
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := models.SharedServerGroupDAO.ComposeGroupConfig(tx, int64(group.Id), false, nil)
|
config, err := models.SharedServerGroupDAO.ComposeGroupConfig(tx, int64(group.Id), false, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -510,7 +510,7 @@ func (this *ServerGroupService) FindAndInitServerGroupWebConfig(ctx context.Cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webConfig, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, nil)
|
webConfig, err := models.SharedHTTPWebDAO.ComposeWebConfig(tx, webId, true, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user