Initial commit (code only without large binaries)
This commit is contained in:
72
EdgeAPI/internal/rpc/services/service_server_plus.go
Normal file
72
EdgeAPI/internal/rpc/services/service_server_plus.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
// +build plus
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
// UpdateServerUAM 修改服务UAM设置
|
||||
func (this *ServerService) UpdateServerUAM(ctx context.Context, req *pb.UpdateServerUAMRequest) (*pb.RPCSuccess, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx *dbs.Tx
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var config = &serverconfigs.UAMConfig{}
|
||||
err = json.Unmarshal(req.UamJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = config.Init()
|
||||
if err != nil {
|
||||
return nil, errors.New("valid uam config failed: " + err.Error())
|
||||
}
|
||||
|
||||
err = models.SharedServerDAO.UpdateServerUAM(tx, req.ServerId, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// FindEnabledServerUAM 查找服务UAM设置
|
||||
func (this *ServerService) FindEnabledServerUAM(ctx context.Context, req *pb.FindEnabledServerUAMRequest) (*pb.FindEnabledServerUAMResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx *dbs.Tx
|
||||
if userId > 0 {
|
||||
err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
uamJSON, err := models.SharedServerDAO.FindServerUAM(tx, req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledServerUAMResponse{
|
||||
UamJSON: uamJSON,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user