mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
实现路径规则部分功能
This commit is contained in:
@@ -68,6 +68,7 @@ func (this *APINode) listenRPC() error {
|
||||
pb.RegisterHTTPAccessLogPolicyServiceServer(rpcServer, &services.HTTPAccessLogPolicyService{})
|
||||
pb.RegisterHTTPCachePolicyServiceServer(rpcServer, &services.HTTPCachePolicyService{})
|
||||
pb.RegisterHTTPFirewallPolicyServiceServer(rpcServer, &services.HTTPFirewallPolicyService{})
|
||||
pb.RegisterHTTPLocationServiceServer(rpcServer, &services.HTTPLocationService{})
|
||||
err = rpcServer.Serve(listener)
|
||||
if err != nil {
|
||||
return errors.New("[API]start rpc failed: " + err.Error())
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -27,7 +31,7 @@ func NewHTTPLocationDAO() *HTTPLocationDAO {
|
||||
var SharedHTTPLocationDAO = NewHTTPLocationDAO()
|
||||
|
||||
// 启用条目
|
||||
func (this *HTTPLocationDAO) EnableHTTPLocation(id uint32) error {
|
||||
func (this *HTTPLocationDAO) EnableHTTPLocation(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", HTTPLocationStateEnabled).
|
||||
@@ -36,7 +40,7 @@ func (this *HTTPLocationDAO) EnableHTTPLocation(id uint32) error {
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *HTTPLocationDAO) DisableHTTPLocation(id uint32) error {
|
||||
func (this *HTTPLocationDAO) DisableHTTPLocation(id int64) error {
|
||||
_, err := this.Query().
|
||||
Pk(id).
|
||||
Set("state", HTTPLocationStateDisabled).
|
||||
@@ -45,7 +49,7 @@ func (this *HTTPLocationDAO) DisableHTTPLocation(id uint32) error {
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *HTTPLocationDAO) FindEnabledHTTPLocation(id uint32) (*HTTPLocation, error) {
|
||||
func (this *HTTPLocationDAO) FindEnabledHTTPLocation(id int64) (*HTTPLocation, error) {
|
||||
result, err := this.Query().
|
||||
Pk(id).
|
||||
Attr("state", HTTPLocationStateEnabled).
|
||||
@@ -57,9 +61,160 @@ func (this *HTTPLocationDAO) FindEnabledHTTPLocation(id uint32) (*HTTPLocation,
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
func (this *HTTPLocationDAO) FindHTTPLocationName(id uint32) (string, error) {
|
||||
func (this *HTTPLocationDAO) FindHTTPLocationName(id int64) (string, error) {
|
||||
return this.Query().
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 创建路径规则
|
||||
func (this *HTTPLocationDAO) CreateLocation(parentId int64, name string, pattern string, description string, isBreak bool) (int64, error) {
|
||||
op := NewHTTPLocationOperator()
|
||||
op.IsOn = true
|
||||
op.State = HTTPLocationStateEnabled
|
||||
op.ParentId = parentId
|
||||
op.Name = name
|
||||
op.Pattern = pattern
|
||||
op.Description = description
|
||||
op.IsBreak = isBreak
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改路径规则
|
||||
func (this *HTTPLocationDAO) UpdateLocation(locationId int64, name string, pattern string, description string, isOn bool, isBreak bool) error {
|
||||
if locationId <= 0 {
|
||||
return errors.New("invalid locationId")
|
||||
}
|
||||
op := NewHTTPLocationOperator()
|
||||
op.Id = locationId
|
||||
op.Name = name
|
||||
op.Pattern = pattern
|
||||
op.Description = description
|
||||
op.IsOn = isOn
|
||||
op.IsBreak = isBreak
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 组合配置
|
||||
func (this *HTTPLocationDAO) ComposeLocationConfig(locationId int64) (*serverconfigs.HTTPLocationConfig, error) {
|
||||
location, err := this.FindEnabledHTTPLocation(locationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if location == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
config := &serverconfigs.HTTPLocationConfig{}
|
||||
config.Id = int64(location.Id)
|
||||
config.IsOn = location.IsOn == 1
|
||||
config.Description = location.Description
|
||||
config.Name = location.Name
|
||||
config.Pattern = location.Pattern
|
||||
config.URLPrefix = location.UrlPrefix
|
||||
|
||||
// web
|
||||
if location.WebId > 0 {
|
||||
webConfig, err := SharedHTTPWebDAO.ComposeWebConfig(int64(location.WebId))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Web = webConfig
|
||||
}
|
||||
|
||||
// reverse proxy
|
||||
if IsNotNull(location.ReverseProxy) {
|
||||
ref := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal([]byte(location.ReverseProxy), ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.ReverseProxyRef = ref
|
||||
if ref.ReverseProxyId > 0 {
|
||||
reverseProxyConfig, err := SharedReverseProxyDAO.ComposeReverseProxyConfig(ref.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.ReverseProxy = reverseProxyConfig
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 查找反向代理设置
|
||||
func (this *HTTPLocationDAO) FindLocationReverseProxy(locationId int64) (*serverconfigs.ReverseProxyRef, error) {
|
||||
refString, err := this.Query().
|
||||
Pk(locationId).
|
||||
Result("reverseProxy").
|
||||
FindStringCol("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if IsNotNull(refString) {
|
||||
ref := &serverconfigs.ReverseProxyRef{}
|
||||
err = json.Unmarshal([]byte(refString), ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ref, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 更改反向代理设置
|
||||
func (this *HTTPLocationDAO) UpdateLocationReverseProxy(locationId int64, reverseProxyJSON []byte) error {
|
||||
if locationId <= 0 {
|
||||
return errors.New("invalid locationId")
|
||||
}
|
||||
op := NewHTTPLocationOperator()
|
||||
op.Id = locationId
|
||||
op.ReverseProxy = JSONBytes(reverseProxyJSON)
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找WebId
|
||||
func (this *HTTPLocationDAO) FindLocationWebId(locationId int64) (int64, error) {
|
||||
webId, err := this.Query().
|
||||
Pk(locationId).
|
||||
Result("webId").
|
||||
FindIntCol(0)
|
||||
return int64(webId), err
|
||||
}
|
||||
|
||||
// 更改Web设置
|
||||
func (this *HTTPLocationDAO) UpdateLocationWeb(locationId int64, webId int64) error {
|
||||
if locationId <= 0 {
|
||||
return errors.New("invalid locationId")
|
||||
}
|
||||
op := NewHTTPLocationOperator()
|
||||
op.Id = locationId
|
||||
op.WebId = webId
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 转换引用为配置
|
||||
func (this *HTTPLocationDAO) ConvertLocationRefs(refs []*serverconfigs.HTTPLocationRef) (locations []*serverconfigs.HTTPLocationConfig, err error) {
|
||||
for _, ref := range refs {
|
||||
config, err := this.ComposeLocationConfig(ref.LocationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
children, err := this.ConvertLocationRefs(ref.Children)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Children = children
|
||||
locations = append(locations, config)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ type HTTPLocation struct {
|
||||
Description string `field:"description"` // 描述
|
||||
WebId uint32 `field:"webId"` // Web配置ID
|
||||
ReverseProxy string `field:"reverseProxy"` // 反向代理
|
||||
UrlPrefix string `field:"urlPrefix"` // URL前缀
|
||||
IsBreak uint8 `field:"isBreak"` // 是否终止匹配
|
||||
}
|
||||
|
||||
type HTTPLocationOperator struct {
|
||||
@@ -31,6 +33,8 @@ type HTTPLocationOperator struct {
|
||||
Description interface{} // 描述
|
||||
WebId interface{} // Web配置ID
|
||||
ReverseProxy interface{} // 反向代理
|
||||
UrlPrefix interface{} // URL前缀
|
||||
IsBreak interface{} // 是否终止匹配
|
||||
}
|
||||
|
||||
func NewHTTPLocationOperator() *HTTPLocationOperator {
|
||||
|
||||
@@ -184,6 +184,24 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
config.FirewallRef = firewallRef
|
||||
}
|
||||
|
||||
// 路径规则
|
||||
if IsNotNull(web.Locations) {
|
||||
refs := []*serverconfigs.HTTPLocationRef{}
|
||||
err = json.Unmarshal([]byte(web.Locations), &refs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(refs) > 0 {
|
||||
config.LocationRefs = refs
|
||||
|
||||
locations, err := SharedHTTPLocationDAO.ConvertLocationRefs(refs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Locations = locations
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 更多配置
|
||||
|
||||
return config, nil
|
||||
@@ -377,6 +395,22 @@ func (this *HTTPWebDAO) UpdateWebFirewall(webId int64, firewallJSON []byte) erro
|
||||
return this.NotifyUpdating(webId)
|
||||
}
|
||||
|
||||
// 更改路径规则配置
|
||||
func (this *HTTPWebDAO) UpdateWebLocations(webId int64, locationsJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.Locations = JSONBytes(locationsJSON)
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.NotifyUpdating(webId)
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
func (this *HTTPWebDAO) NotifyUpdating(webId int64) error {
|
||||
err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
|
||||
|
||||
@@ -23,6 +23,7 @@ type HTTPWeb struct {
|
||||
Gzip string `field:"gzip"` // Gzip配置
|
||||
Cache string `field:"cache"` // 缓存配置
|
||||
Firewall string `field:"firewall"` // 防火墙设置
|
||||
Locations string `field:"locations"` // 路径规则配置
|
||||
}
|
||||
|
||||
type HTTPWebOperator struct {
|
||||
@@ -47,6 +48,7 @@ type HTTPWebOperator struct {
|
||||
Gzip interface{} // Gzip配置
|
||||
Cache interface{} // 缓存配置
|
||||
Firewall interface{} // 防火墙设置
|
||||
Locations interface{} // 路径规则配置
|
||||
}
|
||||
|
||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||
|
||||
@@ -41,7 +41,7 @@ func (this *APINodeService) UpdateAPINode(ctx context.Context, req *pb.UpdateAPI
|
||||
}
|
||||
|
||||
// 删除API节点
|
||||
func (this *APINodeService) DeleteAPINode(ctx context.Context, req *pb.DeleteAPINodeRequest) (*pb.DeleteAPINodeResponse, error) {
|
||||
func (this *APINodeService) DeleteAPINode(ctx context.Context, req *pb.DeleteAPINodeRequest) (*pb.RPCDeleteSuccess, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -52,7 +52,7 @@ func (this *APINodeService) DeleteAPINode(ctx context.Context, req *pb.DeleteAPI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.DeleteAPINodeResponse{}, nil
|
||||
return &pb.RPCDeleteSuccess{}, nil
|
||||
}
|
||||
|
||||
// 列出所有可用API节点
|
||||
|
||||
@@ -57,5 +57,5 @@ func (this *HTTPHeaderService) FindEnabledHTTPHeaderConfig(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindEnabledHTTPHeaderConfigResponse{Config: configData}, nil
|
||||
return &pb.FindEnabledHTTPHeaderConfigResponse{HeaderJSON: configData}, nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (this *HTTPHeaderPolicyService) FindEnabledHTTPHeaderPolicyConfig(ctx conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindEnabledHTTPHeaderPolicyConfigResponse{Config: configData}, nil
|
||||
return &pb.FindEnabledHTTPHeaderPolicyConfigResponse{HeaderPolicyJSON: configData}, nil
|
||||
}
|
||||
|
||||
// 创建策略
|
||||
|
||||
155
internal/rpc/services/service_http_location.go
Normal file
155
internal/rpc/services/service_http_location.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
type HTTPLocationService struct {
|
||||
}
|
||||
|
||||
// 创建路径规则
|
||||
func (this *HTTPLocationService) CreateHTTPLocation(ctx context.Context, req *pb.CreateHTTPLocationRequest) (*pb.CreateHTTPLocationResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
locationId, err := models.SharedHTTPLocationDAO.CreateLocation(req.ParentId, req.Name, req.Pattern, req.Description, req.IsBreak)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CreateHTTPLocationResponse{LocationId: locationId}, nil
|
||||
}
|
||||
|
||||
// 修改路径规则
|
||||
func (this *HTTPLocationService) UpdateHTTPLocation(ctx context.Context, req *pb.UpdateHTTPLocationRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPLocationDAO.UpdateLocation(req.LocationId, req.Name, req.Pattern, req.Description, req.IsOn, req.IsBreak)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
// 查找路径规则配置
|
||||
func (this *HTTPLocationService) FindEnabledHTTPLocationConfig(ctx context.Context, req *pb.FindEnabledHTTPLocationConfigRequest) (*pb.FindEnabledHTTPLocationConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := models.SharedHTTPLocationDAO.ComposeLocationConfig(req.LocationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledHTTPLocationConfigResponse{LocationJSON: configJSON}, nil
|
||||
}
|
||||
|
||||
// 删除路径规则
|
||||
func (this *HTTPLocationService) DeleteHTTPLocation(ctx context.Context, req *pb.DeleteHTTPLocationRequest) (*pb.RPCDeleteSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPLocationDAO.DisableHTTPLocation(req.LocationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rpcutils.RPCDeleteSuccess()
|
||||
}
|
||||
|
||||
// 查找反向代理设置
|
||||
func (this *HTTPLocationService) FindAndInitHTTPLocationReverseProxyConfig(ctx context.Context, req *pb.FindAndInitHTTPLocationReverseProxyConfigRequest) (*pb.FindAndInitHTTPLocationReverseProxyConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reverseProxyRef, err := models.SharedHTTPLocationDAO.FindLocationReverseProxy(req.LocationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reverseProxyRef == nil || reverseProxyRef.ReverseProxyId <= 0 {
|
||||
reverseProxyId, err := models.SharedReverseProxyDAO.CreateReverseProxy(nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reverseProxyRef = &serverconfigs.ReverseProxyRef{
|
||||
IsOn: false,
|
||||
ReverseProxyId: reverseProxyId,
|
||||
}
|
||||
}
|
||||
|
||||
reverseProxyConfig, err := models.SharedReverseProxyDAO.ComposeReverseProxyConfig(reverseProxyRef.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
refJSON, err := json.Marshal(reverseProxyRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configJSON, err := json.Marshal(reverseProxyConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindAndInitHTTPLocationReverseProxyConfigResponse{
|
||||
ReverseProxyJSON: configJSON,
|
||||
ReverseProxyRefJSON: refJSON,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 初始化Web设置
|
||||
func (this *HTTPLocationService) FindAndInitHTTPLocationWebConfig(ctx context.Context, req *pb.FindAndInitHTTPLocationWebConfigRequest) (*pb.FindAndInitHTTPLocationWebConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webId, err := models.SharedHTTPLocationDAO.FindLocationWebId(req.LocationId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if webId <= 0 {
|
||||
webId, err = models.SharedHTTPWebDAO.CreateWeb("")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(webId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindAndInitHTTPLocationWebConfigResponse{
|
||||
WebJSON: configJSON,
|
||||
}, nil
|
||||
}
|
||||
@@ -62,6 +62,6 @@ func (this *HTTPPageService) FindEnabledHTTPPageConfig(ctx context.Context, req
|
||||
}
|
||||
|
||||
return &pb.FindEnabledHTTPPageConfigResponse{
|
||||
Config: configJSON,
|
||||
PageJSON: configJSON,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -53,6 +54,26 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||
}
|
||||
|
||||
// 查找Web配置
|
||||
func (this *HTTPWebService) FindEnabledHTTPWebConfig(ctx context.Context, req *pb.FindEnabledHTTPWebConfigRequest) (*pb.FindEnabledHTTPWebConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := models.SharedHTTPWebDAO.ComposeWebConfig(req.WebId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledHTTPWebConfigResponse{WebJSON: configJSON}, nil
|
||||
}
|
||||
|
||||
// 修改Web配置
|
||||
func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTTPWebRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
@@ -163,7 +184,7 @@ func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.Upda
|
||||
}
|
||||
|
||||
// 更改访问日志配置
|
||||
func (this *HTTPWebService) UpdateHTTPAccessLog(ctx context.Context, req *pb.UpdateHTTPAccessLogRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
func (this *HTTPWebService) UpdateHTTPWebAccessLog(ctx context.Context, req *pb.UpdateHTTPWebAccessLogRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -178,7 +199,7 @@ func (this *HTTPWebService) UpdateHTTPAccessLog(ctx context.Context, req *pb.Upd
|
||||
}
|
||||
|
||||
// 更改统计配置
|
||||
func (this *HTTPWebService) UpdateHTTPStat(ctx context.Context, req *pb.UpdateHTTPStatRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
func (this *HTTPWebService) UpdateHTTPWebStat(ctx context.Context, req *pb.UpdateHTTPWebStatRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -193,7 +214,7 @@ func (this *HTTPWebService) UpdateHTTPStat(ctx context.Context, req *pb.UpdateHT
|
||||
}
|
||||
|
||||
// 更改缓存配置
|
||||
func (this *HTTPWebService) UpdateHTTPCache(ctx context.Context, req *pb.UpdateHTTPCacheRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
func (this *HTTPWebService) UpdateHTTPWebCache(ctx context.Context, req *pb.UpdateHTTPWebCacheRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -208,9 +229,8 @@ func (this *HTTPWebService) UpdateHTTPCache(ctx context.Context, req *pb.UpdateH
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
|
||||
// 更改防火墙设置
|
||||
func (this *HTTPWebService) UpdateHTTPFirewall(ctx context.Context, req *pb.UpdateHTTPFirewallRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
func (this *HTTPWebService) UpdateHTTPWebFirewall(ctx context.Context, req *pb.UpdateHTTPWebFirewallRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
@@ -223,4 +243,20 @@ func (this *HTTPWebService) UpdateHTTPFirewall(ctx context.Context, req *pb.Upda
|
||||
}
|
||||
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
}
|
||||
|
||||
// 更改路径规则设置
|
||||
func (this *HTTPWebService) UpdateHTTPWebLocations(ctx context.Context, req *pb.UpdateHTTPWebLocationsRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebLocations(req.WebId, req.LocationsJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func (this *NodeService) ComposeNodeConfig(ctx context.Context, req *pb.ComposeN
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.ComposeNodeConfigResponse{ConfigJSON: data}, nil
|
||||
return &pb.ComposeNodeConfigResponse{NodeJSON: data}, nil
|
||||
}
|
||||
|
||||
// 节点stream
|
||||
|
||||
@@ -112,5 +112,5 @@ func (this *OriginServerService) FindEnabledOriginServerConfig(ctx context.Conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindEnabledOriginServerConfigResponse{Config: configData}, nil
|
||||
return &pb.FindEnabledOriginServerConfigResponse{OriginJSON: configData}, nil
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindEnabledReverseProxyConfigResponse{Config: configData}, nil
|
||||
return &pb.FindEnabledReverseProxyConfigResponse{ReverseProxyJSON: configData}, nil
|
||||
}
|
||||
|
||||
// 修改反向代理调度算法
|
||||
|
||||
@@ -586,11 +586,11 @@ func (this *ServerService) FindAndInitServerReverseProxyConfig(ctx context.Conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindAndInitServerReverseProxyConfigResponse{ReverseProxy: configJSON, ReverseProxyRef: refJSON}, nil
|
||||
return &pb.FindAndInitServerReverseProxyConfigResponse{ReverseProxyJSON: configJSON, ReverseProxyRefJSON: refJSON}, nil
|
||||
}
|
||||
|
||||
// 初始化Web设置
|
||||
func (this *ServerService) FindAndInitServerWebConfig(ctx context.Context, req *pb.FindAndInitServerWebRequest) (*pb.FindAndInitServerWebResponse, error) {
|
||||
func (this *ServerService) FindAndInitServerWebConfig(ctx context.Context, req *pb.FindAndInitServerWebConfigRequest) (*pb.FindAndInitServerWebConfigResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -617,5 +617,5 @@ func (this *ServerService) FindAndInitServerWebConfig(ctx context.Context, req *
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindAndInitServerWebResponse{Config: configJSON}, nil
|
||||
return &pb.FindAndInitServerWebConfigResponse{WebJSON: configJSON}, nil
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledGzipConfigResponse{Config: configData}, nil
|
||||
return &pb.FindEnabledGzipConfigResponse{GzipJSON: configData}, nil
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
|
||||
@@ -118,7 +118,12 @@ func ValidateRequest(ctx context.Context, userTypes ...UserType) (userType UserT
|
||||
}
|
||||
}
|
||||
|
||||
// 返回Update信息
|
||||
// 返回Update成功信息
|
||||
func RPCUpdateSuccess() (*pb.RPCUpdateSuccess, error) {
|
||||
return &pb.RPCUpdateSuccess{}, nil
|
||||
}
|
||||
|
||||
// 返回Delete成功信息
|
||||
func RPCDeleteSuccess() (*pb.RPCDeleteSuccess, error) {
|
||||
return &pb.RPCDeleteSuccess{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user