阶段性提交

This commit is contained in:
GoEdgeLab
2020-07-30 22:41:35 +08:00
parent 16d2dff57a
commit e6266b7dc3
28 changed files with 1879 additions and 153 deletions

View File

@@ -0,0 +1,74 @@
package grants
import (
"github.com/TeaOSLab/EdgeAdmin/internal/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/actions"
"github.com/iwind/TeaGo/maps"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Data["methods"] = grantutils.AllGrantMethods()
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
Method string
Username string
Password string
PrivateKey string
Description string
Must *actions.Must
}) {
params.Must.
Field("name", params.Name).
Require("请输入名称")
switch params.Method {
case "user":
if len(params.Username) == 0 {
this.FailField("username", "请输入SSH登录用户名")
}
case "privateKey":
if len(params.PrivateKey) == 0 {
this.FailField("privateKey", "请输入RSA私钥")
}
default:
this.Fail("请选择正确的认证方式")
}
createResp, err := this.RPC().NodeGrantRPC().CreateNodeGrant(this.AdminContext(), &pb.CreateNodeGrantRequest{
Name: params.Name,
Method: params.Method,
Username: params.Username,
Password: params.Password,
PrivateKey: params.PrivateKey,
Description: params.Description,
NodeId: 0,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["grant"] = maps.Map{
"id": createResp.GrantId,
"name": params.Name,
"method": params.Method,
"methodName": grantutils.FindGrantMethodName(params.Method),
}
this.Success()
}

View File

@@ -0,0 +1,72 @@
package grants
import (
"github.com/TeaOSLab/EdgeAdmin/internal/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/actions"
"github.com/iwind/TeaGo/maps"
)
type SelectPopupAction struct {
actionutils.ParentAction
}
func (this *SelectPopupAction) Init() {
this.Nav("", "", "")
}
func (this *SelectPopupAction) RunGet(params struct{}) {
// 所有的认证
grantsResp, err := this.RPC().NodeGrantRPC().FindAllEnabledNodeGrants(this.AdminContext(), &pb.FindAllEnabledNodeGrantsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
grants := grantsResp.Grants
grantMaps := []maps.Map{}
for _, grant := range grants {
grantMaps = append(grantMaps, maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
})
}
this.Data["grants"] = grantMaps
this.Show()
}
func (this *SelectPopupAction) RunPost(params struct {
GrantId int64
Must *actions.Must
}) {
if params.GrantId <= 0 {
this.Data["grant"] = maps.Map{
"id": params.GrantId,
"name": "",
"method": "",
"methodName": "",
}
this.Success()
}
grantResp, err := this.RPC().NodeGrantRPC().FindEnabledGrant(this.AdminContext(), &pb.FindEnabledGrantRequest{GrantId: params.GrantId})
if err != nil {
this.ErrorPage(err)
return
}
grant := grantResp.Grant
if grant == nil {
this.Fail("找不到要使用的认证")
}
this.Data["grant"] = maps.Map{
"id": grant.Id,
"name": grant.Name,
"method": grant.Method,
"methodName": grantutils.FindGrantMethodName(grant.Method),
}
this.Success()
}