2020-11-24 17:36:42 +08:00
|
|
|
|
package certs
|
2020-09-30 17:46:38 +08:00
|
|
|
|
|
|
|
|
|
|
import (
|
2020-11-10 21:37:48 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
|
2020-09-30 17:46:38 +08:00
|
|
|
|
"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 {
|
|
|
|
|
|
CertId int64
|
|
|
|
|
|
}) {
|
2020-11-10 21:37:48 +08:00
|
|
|
|
// 创建日志
|
2020-11-20 15:32:42 +08:00
|
|
|
|
defer this.CreateLog(oplogs.LevelInfo, "删除SSL证书 %d", params.CertId)
|
2020-11-10 21:37:48 +08:00
|
|
|
|
|
2021-11-05 17:56:17 +08:00
|
|
|
|
// 是否正在被服务使用
|
2020-12-18 21:18:35 +08:00
|
|
|
|
countResp, err := this.RPC().ServerRPC().CountAllEnabledServersWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledServersWithSSLCertIdRequest{SslCertId: params.CertId})
|
2020-09-30 17:46:38 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if countResp.Count > 0 {
|
|
|
|
|
|
this.Fail("此证书正在被某些服务引用,请先修改服务后再删除。")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-05 17:56:17 +08:00
|
|
|
|
// 是否正在被API节点使用
|
|
|
|
|
|
countResp, err = this.RPC().APINodeRPC().CountAllEnabledAPINodesWithSSLCertId(this.AdminContext(), &pb.CountAllEnabledAPINodesWithSSLCertIdRequest{SslCertId: params.CertId})
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if countResp.Count > 0 {
|
|
|
|
|
|
this.Fail("此证书正在被某些API节点引用,请先修改API节点后再删除")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-05 14:38:56 +08:00
|
|
|
|
err = this.filterDelete(params.CertId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
2021-11-05 17:56:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 21:18:35 +08:00
|
|
|
|
_, err = this.RPC().SSLCertRPC().DeleteSSLCert(this.AdminContext(), &pb.DeleteSSLCertRequest{SslCertId: params.CertId})
|
2020-09-30 17:46:38 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
this.ErrorPage(err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.Success()
|
|
|
|
|
|
}
|