增加企业版认证相关API

This commit is contained in:
GoEdgeLab
2021-04-13 20:01:43 +08:00
parent 678724b055
commit d1d50c7860
11 changed files with 204 additions and 9 deletions

View File

@@ -0,0 +1,51 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package server
import (
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
keyResp, err := this.RPC().AuthorityKeyRPC().ReadAuthorityKey(this.AdminContext(), &pb.ReadAuthorityKeyRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var keyMap maps.Map = nil
teaconst.IsPlus = false
if keyResp.AuthorityKey != nil {
if len(keyResp.AuthorityKey.MacAddresses) == 0 {
keyResp.AuthorityKey.MacAddresses = []string{}
}
isActive := len(keyResp.AuthorityKey.DayTo) > 0 && keyResp.AuthorityKey.DayTo >= timeutil.Format("Y-m-d")
if isActive {
teaconst.IsPlus = true
}
keyMap = maps.Map{
"dayFrom": keyResp.AuthorityKey.DayFrom,
"dayTo": keyResp.AuthorityKey.DayTo,
"macAddresses": keyResp.AuthorityKey.MacAddresses,
"hostname": keyResp.AuthorityKey.Hostname,
"isExpired": !isActive,
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", keyResp.AuthorityKey.UpdatedAt),
}
}
this.Data["key"] = keyMap
this.Show()
}

View File

@@ -0,0 +1,19 @@
package server
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeSetting)).
Helper(settingutils.NewAdvancedHelper("authority")).
Prefix("/settings/authority").
Get("", new(IndexAction)).
EndAll()
})
}

View File

@@ -2,6 +2,7 @@ package settingutils
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
)
@@ -34,7 +35,10 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex
tabbar.Add("API节点", "", "/api", "", this.tab == "apiNodes")
tabbar.Add("用户节点", "", "/settings/userNodes", "", this.tab == "userNodes")
tabbar.Add("日志数据库", "", "/db", "", this.tab == "dbNodes")
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
if teaconst.IsPlus {
tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes")
}
tabbar.Add("企业版认证", "", "/settings/authority", "", this.tab == "authority")
//tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup")
}