2020-08-21 12:32:16 +08:00
|
|
|
package serverutils
|
|
|
|
|
|
|
|
|
|
import (
|
2020-09-13 20:37:07 +08:00
|
|
|
"errors"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
|
|
|
|
"strconv"
|
2020-08-21 12:32:16 +08:00
|
|
|
)
|
|
|
|
|
|
2022-12-31 17:12:49 +08:00
|
|
|
// FindServer 查找服务信息
|
2020-09-13 20:37:07 +08:00
|
|
|
func FindServer(p *actionutils.ParentAction, serverId int64) (*pb.Server, *serverconfigs.ServerConfig, bool) {
|
2022-12-31 17:12:49 +08:00
|
|
|
serverResp, err := p.RPC().ServerRPC().FindEnabledServer(p.AdminContext(), &pb.FindEnabledServerRequest{
|
|
|
|
|
ServerId: serverId,
|
|
|
|
|
IgnoreSSLCertData: true,
|
|
|
|
|
})
|
2020-09-13 20:37:07 +08:00
|
|
|
if err != nil {
|
|
|
|
|
p.ErrorPage(err)
|
|
|
|
|
return nil, nil, false
|
2020-08-21 12:32:16 +08:00
|
|
|
}
|
2022-12-31 17:12:49 +08:00
|
|
|
var server = serverResp.Server
|
2020-09-13 20:37:07 +08:00
|
|
|
if server == nil {
|
|
|
|
|
p.ErrorPage(errors.New("not found server with id '" + strconv.FormatInt(serverId, 10) + "'"))
|
|
|
|
|
return nil, nil, false
|
2020-08-21 12:32:16 +08:00
|
|
|
}
|
2020-09-13 20:37:07 +08:00
|
|
|
config, err := serverconfigs.NewServerConfigFromJSON(server.Config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
p.ErrorPage(err)
|
|
|
|
|
return nil, nil, false
|
2020-08-21 12:32:16 +08:00
|
|
|
}
|
|
|
|
|
|
2020-09-13 20:37:07 +08:00
|
|
|
return server, config, true
|
2020-08-21 12:32:16 +08:00
|
|
|
}
|