2020-10-25 21:27:28 +08:00
|
|
|
package grants
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
2021-03-28 16:21:46 +08:00
|
|
|
"strings"
|
2020-10-25 21:27:28 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GrantAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *GrantAction) Init() {
|
|
|
|
|
this.Nav("", "grant", "index")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *GrantAction) RunGet(params struct {
|
|
|
|
|
GrantId int64
|
|
|
|
|
}) {
|
2021-04-18 21:19:50 +08:00
|
|
|
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledNodeGrant(this.AdminContext(), &pb.FindEnabledNodeGrantRequest{NodeGrantId: params.GrantId})
|
2020-10-25 21:27:28 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-04-18 21:19:50 +08:00
|
|
|
if grantResp.NodeGrant == nil {
|
2020-10-25 21:27:28 +08:00
|
|
|
this.WriteString("can not find the grant")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO 处理节点专用的认证
|
|
|
|
|
|
2021-04-18 21:19:50 +08:00
|
|
|
grant := grantResp.NodeGrant
|
2020-10-25 21:27:28 +08:00
|
|
|
this.Data["grant"] = maps.Map{
|
|
|
|
|
"id": grant.Id,
|
|
|
|
|
"name": grant.Name,
|
|
|
|
|
"method": grant.Method,
|
2023-06-28 19:07:42 +08:00
|
|
|
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
|
2020-10-25 21:27:28 +08:00
|
|
|
"username": grant.Username,
|
2021-03-28 16:21:46 +08:00
|
|
|
"password": strings.Repeat("*", len(grant.Password)),
|
2020-10-25 21:27:28 +08:00
|
|
|
"privateKey": grant.PrivateKey,
|
2021-11-06 15:31:07 +08:00
|
|
|
"passphrase": strings.Repeat("*", len(grant.Passphrase)),
|
2020-10-25 21:27:28 +08:00
|
|
|
"description": grant.Description,
|
|
|
|
|
"su": grant.Su,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用此认证的集群
|
|
|
|
|
clusterMaps := []maps.Map{}
|
2021-05-25 17:48:51 +08:00
|
|
|
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithNodeGrantId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithNodeGrantIdRequest{NodeGrantId: params.GrantId})
|
2020-10-25 21:27:28 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2020-12-17 17:35:38 +08:00
|
|
|
for _, cluster := range clustersResp.NodeClusters {
|
2020-10-25 21:27:28 +08:00
|
|
|
clusterMaps = append(clusterMaps, maps.Map{
|
|
|
|
|
"id": cluster.Id,
|
|
|
|
|
"name": cluster.Name,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["clusters"] = clusterMaps
|
|
|
|
|
|
|
|
|
|
// 使用此认证的节点
|
|
|
|
|
nodeMaps := []maps.Map{}
|
2021-05-25 17:48:51 +08:00
|
|
|
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesWithNodeGrantId(this.AdminContext(), &pb.FindAllEnabledNodesWithNodeGrantIdRequest{NodeGrantId: params.GrantId})
|
2020-10-25 21:27:28 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, node := range nodesResp.Nodes {
|
2020-12-17 17:35:38 +08:00
|
|
|
if node.NodeCluster == nil {
|
2020-10-25 21:27:28 +08:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clusterMap := maps.Map{
|
2020-12-17 17:35:38 +08:00
|
|
|
"id": node.NodeCluster.Id,
|
|
|
|
|
"name": node.NodeCluster.Name,
|
2020-10-25 21:27:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodeMaps = append(nodeMaps, maps.Map{
|
|
|
|
|
"id": node.Id,
|
|
|
|
|
"name": node.Name,
|
|
|
|
|
"cluster": clusterMap,
|
|
|
|
|
"isOn": node.IsOn,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
this.Data["nodes"] = nodeMaps
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|