mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-04 07:50:25 +08:00
修复用户创建服务时提示resource not found的问题
This commit is contained in:
@@ -38,12 +38,12 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
// Init 初始化
|
||||
func (this *ReverseProxyDAO) Init() {
|
||||
_ = this.DAOObject.Init()
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableReverseProxy 启用条目
|
||||
func (this *ReverseProxyDAO) EnableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -55,7 +55,7 @@ func (this *ReverseProxyDAO) EnableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||
return this.NotifyUpdate(tx, id)
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableReverseProxy 禁用条目
|
||||
func (this *ReverseProxyDAO) DisableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -67,7 +67,7 @@ func (this *ReverseProxyDAO) DisableReverseProxy(tx *dbs.Tx, id int64) error {
|
||||
return this.NotifyUpdate(tx, id)
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledReverseProxy 查找启用中的条目
|
||||
func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*ReverseProxy, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -79,7 +79,7 @@ func (this *ReverseProxyDAO) FindEnabledReverseProxy(tx *dbs.Tx, id int64) (*Rev
|
||||
return result.(*ReverseProxy), err
|
||||
}
|
||||
|
||||
// 根据iD组合配置
|
||||
// ComposeReverseProxyConfig 根据ID组合配置
|
||||
func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyId int64) (*serverconfigs.ReverseProxyConfig, error) {
|
||||
reverseProxy, err := this.FindEnabledReverseProxy(tx, reverseProxyId)
|
||||
if err != nil {
|
||||
@@ -184,7 +184,7 @@ func (this *ReverseProxyDAO) ComposeReverseProxyConfig(tx *dbs.Tx, reverseProxyI
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 创建反向代理
|
||||
// CreateReverseProxy 创建反向代理
|
||||
func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userId int64, schedulingJSON []byte, primaryOriginsJSON []byte, backupOriginsJSON []byte) (int64, error) {
|
||||
op := NewReverseProxyOperator()
|
||||
op.IsOn = true
|
||||
@@ -216,7 +216,7 @@ func (this *ReverseProxyDAO) CreateReverseProxy(tx *dbs.Tx, adminId int64, userI
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改反向代理调度算法
|
||||
// UpdateReverseProxyScheduling 修改反向代理调度算法
|
||||
func (this *ReverseProxyDAO) UpdateReverseProxyScheduling(tx *dbs.Tx, reverseProxyId int64, schedulingJSON []byte) error {
|
||||
if reverseProxyId <= 0 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
@@ -235,7 +235,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyScheduling(tx *dbs.Tx, reversePro
|
||||
return this.NotifyUpdate(tx, reverseProxyId)
|
||||
}
|
||||
|
||||
// 修改主要源站
|
||||
// UpdateReverseProxyPrimaryOrigins 修改主要源站
|
||||
func (this *ReverseProxyDAO) UpdateReverseProxyPrimaryOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
||||
if reverseProxyId <= 0 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
@@ -254,7 +254,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyPrimaryOrigins(tx *dbs.Tx, revers
|
||||
return this.NotifyUpdate(tx, reverseProxyId)
|
||||
}
|
||||
|
||||
// 修改备用源站
|
||||
// UpdateReverseProxyBackupOrigins 修改备用源站
|
||||
func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverseProxyId int64, origins []byte) error {
|
||||
if reverseProxyId <= 0 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
@@ -273,7 +273,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxyBackupOrigins(tx *dbs.Tx, reverse
|
||||
return this.NotifyUpdate(tx, reverseProxyId)
|
||||
}
|
||||
|
||||
// 修改是否启用
|
||||
// UpdateReverseProxy 修改是否启用
|
||||
func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64, requestHostType int8, requestHost string, requestURI string, stripPrefix string, autoFlush bool, addHeaders []string, connTimeout *shared.TimeDuration, readTimeout *shared.TimeDuration, idleTimeout *shared.TimeDuration, maxConns int32, maxIdleConns int32) error {
|
||||
if reverseProxyId <= 0 {
|
||||
return errors.New("invalid reverseProxyId")
|
||||
@@ -340,7 +340,7 @@ func (this *ReverseProxyDAO) UpdateReverseProxy(tx *dbs.Tx, reverseProxyId int64
|
||||
return this.NotifyUpdate(tx, reverseProxyId)
|
||||
}
|
||||
|
||||
// 查找包含某个源站的反向代理ID
|
||||
// FindReverseProxyContainsOriginId 查找包含某个源站的反向代理ID
|
||||
func (this *ReverseProxyDAO) FindReverseProxyContainsOriginId(tx *dbs.Tx, originId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
ResultPk().
|
||||
@@ -351,7 +351,31 @@ func (this *ReverseProxyDAO) FindReverseProxyContainsOriginId(tx *dbs.Tx, origin
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
// CheckUserReverseProxy 检查用户权限
|
||||
func (this *ReverseProxyDAO) CheckUserReverseProxy(tx *dbs.Tx, userId int64, reverseProxyId int64) error {
|
||||
exists, err := this.Query(tx).
|
||||
Pk(reverseProxyId).
|
||||
Attr("userId", userId).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 检查server是否为用户的
|
||||
serverId, err := SharedServerDAO.FindEnabledServerIdWithReverseProxyId(tx, reverseProxyId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if serverId == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *ReverseProxyDAO) NotifyUpdate(tx *dbs.Tx, reverseProxyId int64) error {
|
||||
serverId, err := SharedServerDAO.FindEnabledServerIdWithReverseProxyId(tx, reverseProxyId)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,7 +13,7 @@ type ReverseProxyService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建反向代理
|
||||
// CreateReverseProxy 创建反向代理
|
||||
func (this *ReverseProxyService) CreateReverseProxy(ctx context.Context, req *pb.CreateReverseProxyRequest) (*pb.CreateReverseProxyResponse, error) {
|
||||
// 校验请求
|
||||
adminId, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -35,7 +35,7 @@ func (this *ReverseProxyService) CreateReverseProxy(ctx context.Context, req *pb
|
||||
return &pb.CreateReverseProxyResponse{ReverseProxyId: reverseProxyId}, nil
|
||||
}
|
||||
|
||||
// 查找反向代理
|
||||
// FindEnabledReverseProxy 查找反向代理
|
||||
func (this *ReverseProxyService) FindEnabledReverseProxy(ctx context.Context, req *pb.FindEnabledReverseProxyRequest) (*pb.FindEnabledReverseProxyResponse, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -44,11 +44,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxy(ctx context.Context, re
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,7 +69,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxy(ctx context.Context, re
|
||||
return &pb.FindEnabledReverseProxyResponse{ReverseProxy: result}, nil
|
||||
}
|
||||
|
||||
// 查找反向代理配置
|
||||
// FindEnabledReverseProxyConfig 查找反向代理配置
|
||||
func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Context, req *pb.FindEnabledReverseProxyConfigRequest) (*pb.FindEnabledReverseProxyConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -82,11 +78,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Conte
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -107,7 +99,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Conte
|
||||
return &pb.FindEnabledReverseProxyConfigResponse{ReverseProxyJSON: configData}, nil
|
||||
}
|
||||
|
||||
// 修改反向代理调度算法
|
||||
// UpdateReverseProxyScheduling 修改反向代理调度算法
|
||||
func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Context, req *pb.UpdateReverseProxySchedulingRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -116,11 +108,7 @@ func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Contex
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -136,7 +124,7 @@ func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Contex
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改主要源站信息
|
||||
// UpdateReverseProxyPrimaryOrigins 修改主要源站信息
|
||||
func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Context, req *pb.UpdateReverseProxyPrimaryOriginsRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -145,11 +133,7 @@ func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Co
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -165,7 +149,7 @@ func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Co
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改备用源站信息
|
||||
// UpdateReverseProxyBackupOrigins 修改备用源站信息
|
||||
func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Context, req *pb.UpdateReverseProxyBackupOriginsRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -174,11 +158,7 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -194,7 +174,7 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改是否启用
|
||||
// UpdateReverseProxy 修改是否启用
|
||||
func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb.UpdateReverseProxyRequest) (*pb.RPCSuccess, error) {
|
||||
// 校验请求
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
@@ -203,11 +183,7 @@ func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
serverId, err := models.SharedServerDAO.FindEnabledServerIdWithReverseProxyId(nil, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = models.SharedServerDAO.CheckUserServer(nil, userId, serverId)
|
||||
err = models.SharedReverseProxyDAO.CheckUserReverseProxy(nil, userId, req.ReverseProxyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user