mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-14 22:56:35 +08:00
DNS节点可以自动升级
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
stringutil "github.com/iwind/TeaGo/utils/string"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// NSNodeService 域名服务器节点服务
|
||||
@@ -369,7 +370,7 @@ func (this *NSNodeService) FindCurrentNSNodeConfig(ctx context.Context, req *pb.
|
||||
|
||||
// CheckNSNodeLatestVersion 检查新版本
|
||||
func (this *NSNodeService) CheckNSNodeLatestVersion(ctx context.Context, req *pb.CheckNSNodeLatestVersionRequest) (*pb.CheckNSNodeLatestVersionResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
_, _, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin, rpcutils.UserTypeDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -385,3 +386,31 @@ func (this *NSNodeService) CheckNSNodeLatestVersion(ctx context.Context, req *pb
|
||||
}
|
||||
return &pb.CheckNSNodeLatestVersionResponse{HasNewVersion: false}, nil
|
||||
}
|
||||
|
||||
// DownloadNSNodeInstallationFile 下载最新DNS节点安装文件
|
||||
func (this *NSNodeService) DownloadNSNodeInstallationFile(ctx context.Context, req *pb.DownloadNSNodeInstallationFileRequest) (*pb.DownloadNSNodeInstallationFileResponse, error) {
|
||||
_, err := this.ValidateNSNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file := installers.SharedDeployManager.FindNSNodeFile(req.Os, req.Arch)
|
||||
if file == nil {
|
||||
return &pb.DownloadNSNodeInstallationFileResponse{}, nil
|
||||
}
|
||||
|
||||
sum, err := file.Sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, offset, err := file.Read(req.ChunkOffset)
|
||||
|
||||
return &pb.DownloadNSNodeInstallationFileResponse{
|
||||
Sum: sum,
|
||||
Offset: offset,
|
||||
ChunkData: data,
|
||||
Version: file.Version,
|
||||
Filename: filepath.Base(file.Path),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/authority"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
plusutils "github.com/TeaOSLab/EdgePlus/pkg/utils"
|
||||
)
|
||||
|
||||
// AuthorityKeyService 版本认证
|
||||
@@ -44,6 +45,15 @@ func (this *AuthorityKeyService) ReadAuthorityKey(ctx context.Context, req *pb.R
|
||||
return &pb.ReadAuthorityKeyResponse{AuthorityKey: nil}, nil
|
||||
}
|
||||
|
||||
if len(key.Value) == 0 {
|
||||
return &pb.ReadAuthorityKeyResponse{AuthorityKey: nil}, nil
|
||||
}
|
||||
|
||||
m, err := plusutils.Decode([]byte(key.Value))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
macAddresses := []string{}
|
||||
if len(key.MacAddresses) > 0 {
|
||||
err = json.Unmarshal([]byte(key.MacAddresses), &macAddresses)
|
||||
@@ -54,8 +64,8 @@ func (this *AuthorityKeyService) ReadAuthorityKey(ctx context.Context, req *pb.R
|
||||
|
||||
return &pb.ReadAuthorityKeyResponse{AuthorityKey: &pb.AuthorityKey{
|
||||
Value: key.Value,
|
||||
DayFrom: key.DayFrom,
|
||||
DayTo: key.DayTo,
|
||||
DayFrom: m.GetString("dayFrom"),
|
||||
DayTo: m.GetString("dayTo"),
|
||||
Hostname: key.Hostname,
|
||||
MacAddresses: macAddresses,
|
||||
Company: key.Company,
|
||||
|
||||
@@ -171,7 +171,7 @@ func (this *AuthorityNodeService) FindEnabledAuthorityNode(ctx context.Context,
|
||||
|
||||
// FindCurrentAuthorityNode 获取当前认证节点的版本
|
||||
func (this *AuthorityNodeService) FindCurrentAuthorityNode(ctx context.Context, req *pb.FindCurrentAuthorityNodeRequest) (*pb.FindCurrentAuthorityNodeResponse, error) {
|
||||
_, err := this.ValidateAuthority(ctx)
|
||||
_, err := this.ValidateAuthorityNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -78,20 +78,26 @@ func (this *BaseService) ValidateNode(ctx context.Context) (nodeId int64, err er
|
||||
return
|
||||
}
|
||||
|
||||
// ValidateUser 校验用户节点
|
||||
func (this *BaseService) ValidateUser(ctx context.Context) (userId int64, err error) {
|
||||
// ValidateNSNode 校验DNS节点
|
||||
func (this *BaseService) ValidateNSNode(ctx context.Context) (nodeId int64, err error) {
|
||||
_, _, nodeId, err = rpcutils.ValidateRequest(ctx, rpcutils.UserTypeDNS)
|
||||
return
|
||||
}
|
||||
|
||||
// ValidateUserNode 校验用户节点
|
||||
func (this *BaseService) ValidateUserNode(ctx context.Context) (userId int64, err error) {
|
||||
_, _, userId, err = rpcutils.ValidateRequest(ctx, rpcutils.UserTypeUser)
|
||||
return
|
||||
}
|
||||
|
||||
// ValidateMonitor 校验监控节点
|
||||
func (this *BaseService) ValidateMonitor(ctx context.Context) (nodeId int64, err error) {
|
||||
// ValidateMonitorNode 校验监控节点
|
||||
func (this *BaseService) ValidateMonitorNode(ctx context.Context) (nodeId int64, err error) {
|
||||
_, _, nodeId, err = rpcutils.ValidateRequest(ctx, rpcutils.UserTypeMonitor)
|
||||
return
|
||||
}
|
||||
|
||||
// ValidateAuthority 校验认证节点
|
||||
func (this *BaseService) ValidateAuthority(ctx context.Context) (nodeId int64, err error) {
|
||||
// ValidateAuthorityNode 校验认证节点
|
||||
func (this *BaseService) ValidateAuthorityNode(ctx context.Context) (nodeId int64, err error) {
|
||||
_, _, nodeId, err = rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAuthority)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// 消息媒介服务
|
||||
// MessageMediaService 消息媒介服务
|
||||
type MessageMediaService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 获取所有支持的媒介
|
||||
// FindAllMessageMedias 获取所有支持的媒介
|
||||
func (this *MessageMediaService) FindAllMessageMedias(ctx context.Context, req *pb.FindAllMessageMediasRequest) (*pb.FindAllMessageMediasResponse, error) {
|
||||
_, err := this.ValidateAdmin(ctx, 0)
|
||||
if err != nil {
|
||||
@@ -37,9 +37,9 @@ func (this *MessageMediaService) FindAllMessageMedias(ctx context.Context, req *
|
||||
return &pb.FindAllMessageMediasResponse{MessageMedias: pbMedias}, nil
|
||||
}
|
||||
|
||||
// 设置所有支持的媒介
|
||||
// UpdateMessageMedias 设置所有支持的媒介
|
||||
func (this *MessageMediaService) UpdateMessageMedias(ctx context.Context, req *pb.UpdateMessageMediasRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateMonitor(ctx)
|
||||
_, err := this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func (this *MessageTaskService) CreateMessageTask(ctx context.Context, req *pb.C
|
||||
|
||||
// FindSendingMessageTasks 查找要发送的任务
|
||||
func (this *MessageTaskService) FindSendingMessageTasks(ctx context.Context, req *pb.FindSendingMessageTasksRequest) (*pb.FindSendingMessageTasksResponse, error) {
|
||||
_, err := this.ValidateMonitor(ctx)
|
||||
_, err := this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (this *MessageTaskService) FindSendingMessageTasks(ctx context.Context, req
|
||||
|
||||
// UpdateMessageTaskStatus 修改任务状态
|
||||
func (this *MessageTaskService) UpdateMessageTaskStatus(ctx context.Context, req *pb.UpdateMessageTaskStatusRequest) (*pb.RPCSuccess, error) {
|
||||
_, err := this.ValidateMonitor(ctx)
|
||||
_, err := this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func (this *MonitorNodeService) FindEnabledMonitorNode(ctx context.Context, req
|
||||
|
||||
// FindCurrentMonitorNode 获取当前监控节点的版本
|
||||
func (this *MonitorNodeService) FindCurrentMonitorNode(ctx context.Context, req *pb.FindCurrentMonitorNodeRequest) (*pb.FindCurrentMonitorNodeResponse, error) {
|
||||
_, err := this.ValidateMonitor(ctx)
|
||||
_, err := this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1080,7 +1080,7 @@ func (this *ServerService) FindEnabledServerDNS(ctx context.Context, req *pb.Fin
|
||||
|
||||
// CheckUserServer 检查服务是否属于某个用户
|
||||
func (this *ServerService) CheckUserServer(ctx context.Context, req *pb.CheckUserServerRequest) (*pb.RPCSuccess, error) {
|
||||
userId, err := this.ValidateUser(ctx)
|
||||
userId, err := this.ValidateUserNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
// 互斥锁管理
|
||||
// SysLockerService 互斥锁管理
|
||||
type SysLockerService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 获得锁
|
||||
// SysLockerLock 获得锁
|
||||
func (this *SysLockerService) SysLockerLock(ctx context.Context, req *pb.SysLockerLockRequest) (*pb.SysLockerLockResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
_, err = this.ValidateMonitor(ctx)
|
||||
_, err = this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -41,11 +41,11 @@ func (this *SysLockerService) SysLockerLock(ctx context.Context, req *pb.SysLock
|
||||
return &pb.SysLockerLockResponse{Ok: ok}, nil
|
||||
}
|
||||
|
||||
// 释放锁
|
||||
// SysLockerUnlock 释放锁
|
||||
func (this *SysLockerService) SysLockerUnlock(ctx context.Context, req *pb.SysLockerUnlockRequest) (*pb.RPCSuccess, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
|
||||
if err != nil {
|
||||
_, err = this.ValidateMonitor(ctx)
|
||||
_, err = this.ValidateMonitorNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ func (this *UserService) LoginUser(ctx context.Context, req *pb.LoginUserRequest
|
||||
|
||||
// UpdateUserInfo 修改用户基本信息
|
||||
func (this *UserService) UpdateUserInfo(ctx context.Context, req *pb.UpdateUserInfoRequest) (*pb.RPCSuccess, error) {
|
||||
userId, err := this.ValidateUser(ctx)
|
||||
userId, err := this.ValidateUserNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (this *UserService) UpdateUserInfo(ctx context.Context, req *pb.UpdateUserI
|
||||
|
||||
// UpdateUserLogin 修改用户登录信息
|
||||
func (this *UserService) UpdateUserLogin(ctx context.Context, req *pb.UpdateUserLoginRequest) (*pb.RPCSuccess, error) {
|
||||
userId, err := this.ValidateUser(ctx)
|
||||
userId, err := this.ValidateUserNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func (this *UserService) UpdateUserLogin(ctx context.Context, req *pb.UpdateUser
|
||||
|
||||
// ComposeUserDashboard 取得用户Dashboard数据
|
||||
func (this *UserService) ComposeUserDashboard(ctx context.Context, req *pb.ComposeUserDashboardRequest) (*pb.ComposeUserDashboardResponse, error) {
|
||||
userId, err := this.ValidateUser(ctx)
|
||||
userId, err := this.ValidateUserNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ func (this *UserNodeService) FindEnabledUserNode(ctx context.Context, req *pb.Fi
|
||||
|
||||
// FindCurrentUserNode 获取当前用户节点的版本
|
||||
func (this *UserNodeService) FindCurrentUserNode(ctx context.Context, req *pb.FindCurrentUserNodeRequest) (*pb.FindCurrentUserNodeResponse, error) {
|
||||
_, err := this.ValidateUser(ctx)
|
||||
_, err := this.ValidateUserNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user