2020-09-16 20:29:13 +08:00
|
|
|
package headers
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-11-20 15:32:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-16 20:29:13 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CreateDeletePopupAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *CreateDeletePopupAction) Init() {
|
|
|
|
|
this.Nav("", "", "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *CreateDeletePopupAction) RunGet(params struct {
|
|
|
|
|
HeaderPolicyId int64
|
2022-10-24 15:42:18 +08:00
|
|
|
Type string
|
2020-09-16 20:29:13 +08:00
|
|
|
}) {
|
|
|
|
|
this.Data["headerPolicyId"] = params.HeaderPolicyId
|
2022-10-24 15:42:18 +08:00
|
|
|
this.Data["type"] = params.Type
|
2020-09-16 20:29:13 +08:00
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *CreateDeletePopupAction) RunPost(params struct {
|
|
|
|
|
HeaderPolicyId int64
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
2020-11-20 15:32:42 +08:00
|
|
|
// 日志
|
|
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "添加删除的Header HeaderPolicyId: %d, Name: %s", params.HeaderPolicyId, params.Name)
|
|
|
|
|
|
|
|
|
|
params.Must.
|
|
|
|
|
Field("name", params.Name).
|
|
|
|
|
Require("名称不能为空")
|
|
|
|
|
|
2022-12-29 17:16:07 +08:00
|
|
|
policyConfigResp, err := this.RPC().HTTPHeaderPolicyRPC().FindEnabledHTTPHeaderPolicyConfig(this.AdminContext(), &pb.FindEnabledHTTPHeaderPolicyConfigRequest{HttpHeaderPolicyId: params.HeaderPolicyId})
|
2020-09-16 20:29:13 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-05-19 19:52:10 +08:00
|
|
|
var policyConfig = &shared.HTTPHeaderPolicy{}
|
2022-12-29 17:16:07 +08:00
|
|
|
err = json.Unmarshal(policyConfigResp.HttpHeaderPolicyJSON, policyConfig)
|
2020-09-16 20:29:13 +08:00
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 19:52:10 +08:00
|
|
|
var deleteHeaders = policyConfig.DeleteHeaders
|
2020-09-16 20:29:13 +08:00
|
|
|
deleteHeaders = append(deleteHeaders, params.Name)
|
|
|
|
|
_, err = this.RPC().HTTPHeaderPolicyRPC().UpdateHTTPHeaderPolicyDeletingHeaders(this.AdminContext(), &pb.UpdateHTTPHeaderPolicyDeletingHeadersRequest{
|
2022-12-29 17:16:07 +08:00
|
|
|
HttpHeaderPolicyId: params.HeaderPolicyId,
|
|
|
|
|
HeaderNames: deleteHeaders,
|
2020-09-16 20:29:13 +08:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|