域名服务集群创建时可以选择开启访问日志

This commit is contained in:
刘祥超
2021-06-05 15:38:57 +08:00
parent 6df50d97e9
commit 0909164a06
5 changed files with 73 additions and 30 deletions

View File

@@ -3,7 +3,9 @@
package clusters package clusters
import ( import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/actions"
) )
@@ -17,24 +19,44 @@ func (this *CreateAction) Init() {
} }
func (this *CreateAction) RunGet(params struct{}) { func (this *CreateAction) RunGet(params struct{}) {
// 默认的访问日志设置
this.Data["accessLogRef"] = &dnsconfigs.AccessLogRef{
IsOn: true,
}
this.Show() this.Show()
} }
func (this *CreateAction) RunPost(params struct { func (this *CreateAction) RunPost(params struct {
Name string Name string
AccessLogJSON []byte
Must *actions.Must Must *actions.Must
CSRF *actionutils.CSRF CSRF *actionutils.CSRF
}) { }) {
var clusterId int64 var clusterId int64
defer this.CreateLogInfo("创建域名服务集群 %d", clusterId) defer func() {
this.CreateLogInfo("创建域名服务集群 %d", clusterId)
}()
params.Must. params.Must.
Field("name", params.Name). Field("name", params.Name).
Require("请输入集群名称") Require("请输入集群名称")
// 校验访问日志设置
ref := &dnsconfigs.AccessLogRef{}
err := json.Unmarshal(params.AccessLogJSON, ref)
if err != nil {
this.Fail("数据格式错误:" + err.Error())
}
err = ref.Init()
if err != nil {
this.Fail("数据格式错误:" + err.Error())
}
resp, err := this.RPC().NSClusterRPC().CreateNSCluster(this.AdminContext(), &pb.CreateNSClusterRequest{ resp, err := this.RPC().NSClusterRPC().CreateNSCluster(this.AdminContext(), &pb.CreateNSClusterRequest{
Name: params.Name, Name: params.Name,
AccessLogJSON: params.AccessLogJSON,
}) })
if err != nil { if err != nil {
this.ErrorPage(err) this.ErrorPage(err)

View File

@@ -19,6 +19,14 @@ func (this *CreateAction) Init() {
} }
func (this *CreateAction) RunGet(params struct{}) { func (this *CreateAction) RunGet(params struct{}) {
// 集群数量
countClustersResp, err := this.RPC().NSClusterRPC().CountAllEnabledNSClusters(this.AdminContext(), &pb.CountAllEnabledNSClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countClusters"] = countClustersResp.Count
this.Show() this.Show()
} }

View File

@@ -12,5 +12,9 @@
</td> </td>
</tr> </tr>
</table> </table>
<h3>访问日志设置</h3>
<ns-access-log-ref-box :v-access-log-ref="accessLogRef"></ns-access-log-ref-box>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>

View File

@@ -1,6 +1,14 @@
{$layout} {$layout}
{$template "../menu"} {$template "../menu"}
<div v-if="countClusters == 0">
<not-found-box>
暂时还没有集群,请先 <a href="/ns/clusters/create">创建集群</a>
</not-found-box>
</div>
<div v-show="countClusters > 0">
<form class="ui form" data-tea-action="$" data-tea-success="success"> <form class="ui form" data-tea-action="$" data-tea-success="success">
<csrf-token></csrf-token> <csrf-token></csrf-token>
<table class="ui table definition selectable"> <table class="ui table definition selectable">
@@ -27,3 +35,4 @@
</table> </table>
<submit-btn></submit-btn> <submit-btn></submit-btn>
</form> </form>
</div>

View File

@@ -3,7 +3,7 @@
<div v-if="countClusters == 0"> <div v-if="countClusters == 0">
<not-found-box> <not-found-box>
暂时还没有集群,请先 <a href="/ns/clusters">创建集群</a> 暂时还没有集群,请先 <a href="/ns/clusters/create">创建集群</a>
</not-found-box> </not-found-box>
</div> </div>