显示SSH认证相关集群、节点

This commit is contained in:
刘祥超
2020-10-25 21:27:28 +08:00
parent b8e95c1ad1
commit 30b79f613c
40 changed files with 297 additions and 163 deletions

View File

@@ -3,7 +3,7 @@ package node
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)

View File

@@ -3,7 +3,7 @@ package node
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"

View File

@@ -1,9 +1,9 @@
package settings
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)

View File

@@ -1,4 +1,4 @@
package clusters
package clusterutils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"

View File

@@ -1,23 +1,29 @@
package clusters
package clusterutils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"net/http"
)
type Helper struct {
type ClustersHelper struct {
}
func NewHelper() *Helper {
return &Helper{}
func NewClustersHelper() *ClustersHelper {
return &ClustersHelper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) {
func (this *ClustersHelper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
action.Data["teaMenu"] = "clusters"
selectedTabbar, _ := action.Data["mainTab"]
tabbar := actionutils.NewTabbar()
tabbar.Add("集群", "", "/clusters", "", selectedTabbar == "cluster")
tabbar.Add("SSH认证", "", "/clusters/grants", "", selectedTabbar == "grant")
actionutils.SetTabbar(action, tabbar)
}

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)

View File

@@ -0,0 +1,44 @@
package grants
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
GrantId int64
}) {
// 检查是否有别的集群或节点正在使用
countResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithGrantIdRequest{
GrantId: params.GrantId,
})
if err != nil {
this.ErrorPage(err)
return
}
if countResp.Count > 0 {
this.Fail("有集群正在使用此服务,请修改后再删除")
}
countResp2, err := this.RPC().NodeRPC().CountAllEnabledNodesWithGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithGrantIdRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
if countResp2.Count > 0 {
this.Fail("有节点正在使用此服务,请修改后再删除")
}
// 删除
_, err = this.RPC().NodeGrantRPC().DisableNodeGrant(this.AdminContext(), &pb.DisableNodeGrantRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,88 @@
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"
)
type GrantAction struct {
actionutils.ParentAction
}
func (this *GrantAction) Init() {
this.Nav("", "grant", "index")
}
func (this *GrantAction) RunGet(params struct {
GrantId int64
}) {
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
if grantResp.Grant == nil {
this.WriteString("can not find the grant")
return
}
// TODO 处理节点专用的认证
grant := grantResp.Grant
this.Data["grant"] = maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"username": grant.Username,
"password": grant.Password,
"privateKey": grant.PrivateKey,
"description": grant.Description,
"su": grant.Su,
}
// 使用此认证的集群
clusterMaps := []maps.Map{}
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClustersWithGrantId(this.AdminContext(), &pb.FindAllEnabledNodeClustersWithGrantIdRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
for _, cluster := range clustersResp.Clusters {
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = clusterMaps
// 使用此认证的节点
nodeMaps := []maps.Map{}
nodesResp, err := this.RPC().NodeRPC().FindAllEnabledNodesWithGrantId(this.AdminContext(), &pb.FindAllEnabledNodesWithGrantIdRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
for _, node := range nodesResp.Nodes {
if node.Cluster == nil {
continue
}
clusterMap := maps.Map{
"id": node.Cluster.Id,
"name": node.Cluster.Name,
}
nodeMaps = append(nodeMaps, maps.Map{
"id": node.Id,
"name": node.Name,
"cluster": clusterMap,
"isOn": node.IsOn,
})
}
this.Data["nodes"] = nodeMaps
this.Show()
}

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
@@ -34,6 +34,22 @@ func (this *IndexAction) RunGet(params struct{}) {
}
grantMaps := []maps.Map{}
for _, grant := range grantsResp.Grants {
// 集群数
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithGrantIdRequest{GrantId: grant.Id})
if err != nil {
this.ErrorPage(err)
return
}
countClusters := countClustersResp.Count
// 节点数
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithGrantIdRequest{GrantId: grant.Id})
if err != nil {
this.ErrorPage(err)
return
}
countNodes := countNodesResp.Count
grantMaps = append(grantMaps, maps.Map{
"id": grant.Id,
"name": grant.Name,
@@ -41,6 +57,8 @@ func (this *IndexAction) RunGet(params struct{}) {
"type": grant.Method,
"name": grantutils.FindGrantMethodName(grant.Method),
},
"countClusters": countClusters,
"countNodes": countNodes,
})
}
this.Data["grants"] = grantMaps

View File

@@ -0,0 +1,27 @@
package grants
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(clusterutils.NewClustersHelper()).
Prefix("/clusters/grants").
// 授权管理
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
GetPost("/update", new(UpdateAction)).
Post("/delete", new(DeleteAction)).
Get("/grant", new(GrantAction)).
GetPost("/selectPopup", new(SelectPopupAction)).
GetPost("/createPopup", new(CreatePopupAction)).
GetPost("/updatePopup", new(UpdatePopupAction)).
EndAll()
})
}

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
@@ -13,7 +13,7 @@ type UpdateAction struct {
}
func (this *UpdateAction) Init() {
this.Nav("", "", "")
this.Nav("", "grant", "update")
}
func (this *UpdateAction) RunGet(params struct {

View File

@@ -1,9 +1,9 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)

View File

@@ -1,6 +1,7 @@
package clusters
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -9,7 +10,7 @@ func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(clusterutils.NewClustersHelper()).
Prefix("/clusters").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).

View File

@@ -1,22 +0,0 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
GrantId int64
}) {
_, err := this.RPC().NodeGrantRPC().DisableNodeGrant(this.AdminContext(), &pb.DisableNodeGrantRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,47 +0,0 @@
package grants
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants/grantutils"
"github.com/iwind/TeaGo/maps"
)
type GrantAction struct {
actionutils.ParentAction
}
func (this *GrantAction) Init() {
this.Nav("", "grant", "index")
}
func (this *GrantAction) RunGet(params struct {
GrantId int64
}) {
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
if grantResp.Grant == nil {
this.WriteString("can not find the grant")
return
}
// TODO 处理节点专用的认证
grant := grantResp.Grant
this.Data["grant"] = maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
"username": grant.Username,
"password": grant.Password,
"privateKey": grant.PrivateKey,
"description": grant.Description,
"su": grant.Su,
}
this.Show()
}

View File

@@ -1,7 +1,6 @@
package nodes
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/grants"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
@@ -19,15 +18,6 @@ func init() {
GetPost("/ipAddresses/createPopup", new(ipAddresses.CreatePopupAction)).
GetPost("/ipAddresses/updatePopup", new(ipAddresses.UpdatePopupAction)).
// 授权管理
Get("/grants", new(grants.IndexAction)).
GetPost("/grants/create", new(grants.CreateAction)).
GetPost("/grants/update", new(grants.UpdateAction)).
Post("/grants/delete", new(grants.DeleteAction)).
Get("/grants/grant", new(grants.GrantAction)).
GetPost("/grants/selectPopup", new(grants.SelectPopupAction)).
GetPost("/grants/createPopup", new(grants.CreatePopupAction)).
GetPost("/grants/updatePopup", new(grants.UpdatePopupAction)).
EndAll()
})
}