mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 06:40:26 +08:00
实现对ACME用户的增删改
This commit is contained in:
@@ -159,5 +159,7 @@ func (this *ACMEUserDAO) CheckACMEUser(acmeUserId int64, adminId int64, userId i
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return query.Exist()
|
||||
return query.
|
||||
State(ACMEUserStateEnabled).
|
||||
Exist()
|
||||
}
|
||||
|
||||
@@ -90,8 +90,10 @@ func (this *SSLCertDAO) FindSSLCertName(id int64) (string, error) {
|
||||
}
|
||||
|
||||
// 创建证书
|
||||
func (this *SSLCertDAO) CreateCert(isOn bool, name string, description string, serverName string, isCA bool, certData []byte, keyData []byte, timeBeginAt int64, timeEndAt int64, dnsNames []string, commonNames []string) (int64, error) {
|
||||
func (this *SSLCertDAO) CreateCert(adminId int64, userId int64, isOn bool, name string, description string, serverName string, isCA bool, certData []byte, keyData []byte, timeBeginAt int64, timeEndAt int64, dnsNames []string, commonNames []string) (int64, error) {
|
||||
op := NewSSLCertOperator()
|
||||
op.AdminId = adminId
|
||||
op.UserId = userId
|
||||
op.State = SSLCertStateEnabled
|
||||
op.IsOn = isOn
|
||||
op.Name = name
|
||||
@@ -267,3 +269,49 @@ func (this *SSLCertDAO) ListCertIds(isCA bool, isAvailable bool, isExpired bool,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 计算所有某个管理员/用户下所有的ACME用户生成的证书数量
|
||||
func (this *SSLCertDAO) CountAllSSLCertsWithACME(adminId int64, userId int64) (int64, error) {
|
||||
query := this.Query()
|
||||
if adminId > 0 {
|
||||
query.Attr("adminId", adminId)
|
||||
}
|
||||
if userId > 0 {
|
||||
query.Attr("userId", userId)
|
||||
}
|
||||
return query.
|
||||
State(SSLCertStateEnabled).
|
||||
Where("acmeUserId>0").
|
||||
Count()
|
||||
}
|
||||
|
||||
// 列出某个管理员/用户下所有的ACME用户生成的证书Ids
|
||||
func (this *SSLCertDAO) ListSSLCertIdsWithACME(adminId int64, userId int64, offset int64, size int64) (certIds []int64, err error) {
|
||||
query := this.Query()
|
||||
if adminId > 0 {
|
||||
query.Attr("adminId", adminId)
|
||||
}
|
||||
if userId > 0 {
|
||||
query.Attr("userId", userId)
|
||||
}
|
||||
ones, err := query.
|
||||
ResultPk().
|
||||
State(SSLCertStateEnabled).
|
||||
Where("acmeUserId>0").
|
||||
Offset(offset).
|
||||
Limit(size).
|
||||
DescPk().
|
||||
FindAll()
|
||||
for _, one := range ones {
|
||||
certIds = append(certIds, int64(one.(*SSLCert).Id))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 计算某个ACME用户生成的证书数量
|
||||
func (this *SSLCertDAO) CountSSLCertsWithACMEUserId(acmeUserId int64) (int64, error) {
|
||||
return this.Query().
|
||||
State(SSLCertStateEnabled).
|
||||
Attr("acmeUserId", acmeUserId).
|
||||
Count()
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (this *ACMEUserService) CountACMEUsers(ctx context.Context, req *pb.CountAc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.ResponseCount(count)
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页用户
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type APINodeService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建API节点
|
||||
@@ -38,7 +39,7 @@ func (this *APINodeService) UpdateAPINode(ctx context.Context, req *pb.UpdateAPI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 删除API节点
|
||||
@@ -53,7 +54,7 @@ func (this *APINodeService) DeleteAPINode(ctx context.Context, req *pb.DeleteAPI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 列出所有可用API节点
|
||||
@@ -105,7 +106,7 @@ func (this *APINodeService) CountAllEnabledAPINodes(ctx context.Context, req *pb
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的API节点
|
||||
|
||||
@@ -30,11 +30,11 @@ func (this *BaseService) ValidateAdminAndUser(ctx context.Context) (adminId int6
|
||||
|
||||
// 返回成功
|
||||
func (this *BaseService) Success() (*pb.RPCSuccess, error) {
|
||||
return rpcutils.Success()
|
||||
return &pb.RPCSuccess{}, nil
|
||||
}
|
||||
|
||||
// 返回数字
|
||||
func (this *BaseService) ResponseCount(count int64) (*pb.RPCCountResponse, error) {
|
||||
func (this *BaseService) SuccessCount(count int64) (*pb.RPCCountResponse, error) {
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ func (this *DBNodeService) CountAllEnabledDBNodes(ctx context.Context, req *pb.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的数据库节点
|
||||
|
||||
@@ -173,7 +173,7 @@ func (this *DNSDomainService) CountAllEnabledDNSDomainsWithDNSProviderId(ctx con
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出服务商下的所有域名
|
||||
|
||||
@@ -56,7 +56,7 @@ func (this *DNSProviderService) CountAllEnabledDNSProviders(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页服务商信息
|
||||
|
||||
@@ -94,7 +94,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的缓存策略
|
||||
|
||||
@@ -280,7 +280,7 @@ func (this *HTTPFirewallPolicyService) CountAllEnabledFirewallPolicies(ctx conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的防火墙策略
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type HTTPHeaderService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建Header
|
||||
@@ -38,7 +39,7 @@ func (this *HTTPHeaderService) UpdateHTTPHeader(ctx context.Context, req *pb.Upd
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 查找配置
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type HTTPHeaderPolicyService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 查找策略配置
|
||||
@@ -58,7 +59,7 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingHeaders(ctx con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改SetHeaders
|
||||
@@ -73,7 +74,7 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicySettingHeaders(ctx co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改AddTrailers
|
||||
@@ -88,7 +89,7 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingTrailers(ctx co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改ReplaceHeaders
|
||||
@@ -103,7 +104,7 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyReplacingHeaders(ctx
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改删除的Headers
|
||||
@@ -118,5 +119,5 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyDeletingHeaders(ctx c
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTT
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
@@ -100,7 +100,7 @@ func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.Updat
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改字符集配置
|
||||
@@ -115,7 +115,7 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改请求Header策略
|
||||
@@ -131,7 +131,7 @@ func (this *HTTPWebService) UpdateHTTPWebRequestHeader(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改响应Header策略
|
||||
@@ -147,7 +147,7 @@ func (this *HTTPWebService) UpdateHTTPWebResponseHeader(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 更改Shutdown
|
||||
|
||||
@@ -72,7 +72,7 @@ func (this *IPItemService) CountIPItemsWithListId(ctx context.Context, req *pb.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的IP
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
// 管理员、用户或者其他系统用户日志
|
||||
type LogService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建日志
|
||||
@@ -38,7 +39,7 @@ func (this *LogService) CountLogs(ctx context.Context, req *pb.CountLogRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页日志
|
||||
|
||||
@@ -24,7 +24,7 @@ func (this *MessageService) CountUnreadMessages(ctx context.Context, req *pb.Cou
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页未读消息
|
||||
|
||||
@@ -130,7 +130,7 @@ func (this *NodeService) CountAllEnabledNodes(ctx context.Context, req *pb.Count
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 计算匹配的节点数量
|
||||
@@ -143,7 +143,7 @@ func (this *NodeService) CountAllEnabledNodesMatch(ctx context.Context, req *pb.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页的节点
|
||||
@@ -359,7 +359,7 @@ func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeReque
|
||||
}
|
||||
}()
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 列出单个节点
|
||||
@@ -494,7 +494,7 @@ func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNod
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 同步集群中的节点版本
|
||||
@@ -524,7 +524,7 @@ func (this *NodeService) UpdateNodeIsInstalled(ctx context.Context, req *pb.Upda
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 安装节点
|
||||
@@ -665,7 +665,7 @@ func (this *NodeService) CountAllEnabledNodesWithGrantId(ctx context.Context, re
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 查找使用某个认证的所有节点
|
||||
@@ -950,7 +950,7 @@ func (this *NodeService) CountAllEnabledNodesWithGroupId(ctx context.Context, re
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 取得某个集群下的所有节点
|
||||
|
||||
@@ -44,7 +44,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 禁用集群
|
||||
@@ -218,7 +218,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClusters(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页集群
|
||||
@@ -326,7 +326,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithGrantId(ctx conte
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 查找使用某个认证的所有集群
|
||||
@@ -443,7 +443,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSProviderId(ctx
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 计算使用某个DNS域名的集群数量
|
||||
@@ -458,7 +458,7 @@ func (this *NodeClusterService) CountAllEnabledNodeClustersWithDNSDomainId(ctx c
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 检查集群域名是否已经被使用
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type NodeGrantService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (this *NodeGrantService) CreateNodeGrant(ctx context.Context, req *pb.CreateNodeGrantRequest) (*pb.CreateNodeGrantResponse, error) {
|
||||
@@ -37,7 +38,7 @@ func (this *NodeGrantService) UpdateNodeGrant(ctx context.Context, req *pb.Updat
|
||||
}
|
||||
|
||||
err = models.SharedNodeGrantDAO.UpdateGrant(req.GrantId, req.Name, req.Method, req.Username, req.Password, req.PrivateKey, req.Description, req.NodeId)
|
||||
return &pb.RPCSuccess{}, err
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
func (this *NodeGrantService) DisableNodeGrant(ctx context.Context, req *pb.DisableNodeGrantRequest) (*pb.DisableNodeGrantResponse, error) {
|
||||
@@ -59,7 +60,7 @@ func (this *NodeGrantService) CountAllEnabledNodeGrants(ctx context.Context, req
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
func (this *NodeGrantService) ListEnabledNodeGrants(ctx context.Context, req *pb.ListEnabledNodeGrantsRequest) (*pb.ListEnabledNodeGrantsResponse, error) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type NodeIPAddressService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建IP地址
|
||||
@@ -39,7 +40,7 @@ func (this *NodeIPAddressService) UpdateNodeIPAddress(ctx context.Context, req *
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改IP地址所属节点
|
||||
@@ -55,7 +56,7 @@ func (this *NodeIPAddressService) UpdateNodeIPAddressNodeId(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 禁用单个IP地址
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
// 节点日志相关服务
|
||||
type NodeLogService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建日志
|
||||
@@ -38,7 +39,7 @@ func (this *NodeLogService) CountNodeLogs(ctx context.Context, req *pb.CountNode
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页日志
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
// 源站相关管理
|
||||
type OriginService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建源站
|
||||
@@ -57,7 +58,7 @@ func (this *OriginService) UpdateOrigin(ctx context.Context, req *pb.UpdateOrigi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 查找单个源站信息
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type ReverseProxyService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建反向代理
|
||||
@@ -86,7 +87,7 @@ func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Contex
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改主要源站信息
|
||||
@@ -102,7 +103,7 @@ func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Co
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改备用源站信息
|
||||
@@ -118,7 +119,7 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改是否启用
|
||||
@@ -134,5 +135,5 @@ func (this *ReverseProxyService) UpdateReverseProxy(ctx context.Context, req *pb
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
)
|
||||
|
||||
type ServerService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建服务
|
||||
@@ -86,7 +87,7 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改HTTP服务
|
||||
@@ -116,7 +117,7 @@ func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改HTTPS服务
|
||||
@@ -146,7 +147,7 @@ func (this *ServerService) UpdateServerHTTPS(ctx context.Context, req *pb.Update
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改TCP服务
|
||||
@@ -176,7 +177,7 @@ func (this *ServerService) UpdateServerTCP(ctx context.Context, req *pb.UpdateSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改TLS服务
|
||||
@@ -206,7 +207,7 @@ func (this *ServerService) UpdateServerTLS(ctx context.Context, req *pb.UpdateSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改Unix服务
|
||||
@@ -236,7 +237,7 @@ func (this *ServerService) UpdateServerUnix(ctx context.Context, req *pb.UpdateS
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改UDP服务
|
||||
@@ -266,7 +267,7 @@ func (this *ServerService) UpdateServerUDP(ctx context.Context, req *pb.UpdateSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改Web服务
|
||||
@@ -296,7 +297,7 @@ func (this *ServerService) UpdateServerWeb(ctx context.Context, req *pb.UpdateSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改反向代理服务
|
||||
@@ -326,7 +327,7 @@ func (this *ServerService) UpdateServerReverseProxy(ctx context.Context, req *pb
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 修改域名服务
|
||||
@@ -356,7 +357,7 @@ func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.Update
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
// 计算服务数量
|
||||
@@ -371,7 +372,7 @@ func (this *ServerService) CountAllEnabledServersMatch(ctx context.Context, req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页服务
|
||||
@@ -664,7 +665,7 @@ func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Conte
|
||||
}
|
||||
|
||||
if len(policyIds) == 0 {
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
return this.SuccessCount(0)
|
||||
}
|
||||
|
||||
count, err := models.SharedServerDAO.CountAllEnabledServersWithSSLPolicyIds(policyIds)
|
||||
@@ -672,7 +673,7 @@ func (this *ServerService) CountAllEnabledServersWithSSLCertId(ctx context.Conte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 查找使用某个SSL证书的所有服务
|
||||
@@ -720,14 +721,14 @@ func (this *ServerService) CountAllEnabledServersWithCachePolicyId(ctx context.C
|
||||
return nil, err
|
||||
}
|
||||
if len(webIds) == 0 {
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
return this.SuccessCount(0)
|
||||
}
|
||||
|
||||
countServers, err := models.SharedServerDAO.CountEnabledServersWithWebIds(webIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: countServers}, nil
|
||||
return this.SuccessCount(countServers)
|
||||
}
|
||||
|
||||
// 查找使用某个缓存策略的所有服务
|
||||
@@ -777,14 +778,14 @@ func (this *ServerService) CountAllEnabledServersWithHTTPFirewallPolicyId(ctx co
|
||||
}
|
||||
|
||||
if len(webIds) == 0 {
|
||||
return &pb.RPCCountResponse{Count: 0}, nil
|
||||
return this.SuccessCount(0)
|
||||
}
|
||||
|
||||
countServers, err := models.SharedServerDAO.CountEnabledServersWithWebIds(webIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: countServers}, nil
|
||||
return this.SuccessCount(countServers)
|
||||
}
|
||||
|
||||
// 查找使用某个WAF策略的所有服务
|
||||
@@ -833,7 +834,7 @@ func (this *ServerService) CountAllEnabledServersWithNodeClusterId(ctx context.C
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 计算使用某个分组的服务数量
|
||||
@@ -848,9 +849,7 @@ func (this *ServerService) CountAllEnabledServersWithGroupId(ctx context.Context
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.RPCCountResponse{
|
||||
Count: count,
|
||||
}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
|
||||
@@ -17,12 +17,12 @@ type SSLCertService struct {
|
||||
// 创建Cert
|
||||
func (this *SSLCertService) CreateSSLCert(ctx context.Context, req *pb.CreateSSLCertRequest) (*pb.CreateSSLCertResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
adminId, userId, err := this.ValidateAdminAndUser(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
certId, err := models.SharedSSLCertDAO.CreateCert(req.IsOn, req.Name, req.Description, req.ServerName, req.IsCA, req.CertData, req.KeyData, req.TimeBeginAt, req.TimeEndAt, req.DnsNames, req.CommonNames)
|
||||
certId, err := models.SharedSSLCertDAO.CreateCert(adminId, userId, req.IsOn, req.Name, req.Description, req.ServerName, req.IsCA, req.CertData, req.KeyData, req.TimeBeginAt, req.TimeEndAt, req.DnsNames, req.CommonNames)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,9 +95,7 @@ func (this *SSLCertService) CountSSLCerts(ctx context.Context, req *pb.CountSSLC
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCCountResponse{
|
||||
Count: count,
|
||||
}, nil
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单页匹配的Cert
|
||||
@@ -132,3 +130,72 @@ func (this *SSLCertService) ListSSLCerts(ctx context.Context, req *pb.ListSSLCer
|
||||
}
|
||||
return &pb.ListSSLCertsResponse{CertsJSON: certConfigsJSON}, nil
|
||||
}
|
||||
|
||||
// 计算某个ACME用户生成的证书数量
|
||||
func (this *SSLCertService) CountSSLCertsWithACMEUserId(ctx context.Context, req *pb.CountSSLCertsWithACMEUserIdRequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 检查用户权限
|
||||
|
||||
count, err := models.SharedSSLCertDAO.CountSSLCertsWithACMEUserId(req.AcmeUserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 计算所有某个管理员/用户下所有的ACME用户生成的证书
|
||||
func (this *SSLCertService) CountAllSSLCertsWithACME(ctx context.Context, req *pb.CountAllSSLCertsWithACMERequest) (*pb.RPCCountResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateAdminAndUser(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 校验用户
|
||||
|
||||
count, err := models.SharedSSLCertDAO.CountAllSSLCertsWithACME(req.AdminId, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return this.SuccessCount(count)
|
||||
}
|
||||
|
||||
// 列出单个管理员/用户下所有的ACME用户生成的证书
|
||||
func (this *SSLCertService) ListSSLCertsWithACME(ctx context.Context, req *pb.ListSSLCertsWithACMERequest) (*pb.ListSSLCertsWithACMEResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := this.ValidateAdminAndUser(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO 校验用户
|
||||
|
||||
certIds, err := models.SharedSSLCertDAO.ListSSLCertIdsWithACME(req.AdminId, req.UserId, req.Offset, req.Size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
certConfigs := []*sslconfigs.SSLCertConfig{}
|
||||
for _, certId := range certIds {
|
||||
certConfig, err := models.SharedSSLCertDAO.ComposeCertConfig(certId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 这里不需要数据内容
|
||||
certConfig.CertData = nil
|
||||
certConfig.KeyData = nil
|
||||
|
||||
certConfigs = append(certConfigs, certConfig)
|
||||
}
|
||||
certConfigsJSON, err := json.Marshal(certConfigs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.ListSSLCertsWithACMEResponse{CertsJSON: certConfigsJSON}, nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type HTTPGzipService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
// 创建Gzip配置
|
||||
@@ -105,5 +106,5 @@ func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateH
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.RPCSuccess{}, nil
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/encrypt"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@@ -125,16 +124,6 @@ func ValidateRequest(ctx context.Context, userTypes ...UserType) (userType UserT
|
||||
}
|
||||
}
|
||||
|
||||
// 返回操作成功信息
|
||||
func Success() (*pb.RPCSuccess, error) {
|
||||
return &pb.RPCSuccess{}, nil
|
||||
}
|
||||
|
||||
// 返回数量
|
||||
func NewCountResponse(count int64) (*pb.RPCCountResponse, error) {
|
||||
return &pb.RPCCountResponse{Count: count}, nil
|
||||
}
|
||||
|
||||
// 包装错误
|
||||
func Wrap(description string, err error) error {
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user