Files
EdgeAPI/internal/rpc/services/service_http_auth_policy.go

70 lines
2.0 KiB
Go
Raw Normal View History

2021-06-17 21:17:53 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package services
import (
"context"
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
// HTTPAuthPolicyService 服务认证策略服务
type HTTPAuthPolicyService struct {
BaseService
}
// CreateHTTPAuthPolicy 创建策略
func (this *HTTPAuthPolicyService) CreateHTTPAuthPolicy(ctx context.Context, req *pb.CreateHTTPAuthPolicyRequest) (*pb.CreateHTTPAuthPolicyResponse, error) {
2022-07-22 14:35:17 +08:00
_, err := this.ValidateAdmin(ctx)
2021-06-17 21:17:53 +08:00
if err != nil {
return nil, err
}
var tx = this.NullTx()
policyId, err := models.SharedHTTPAuthPolicyDAO.CreateHTTPAuthPolicy(tx, req.Name, req.Type, req.ParamsJSON)
if err != nil {
return nil, err
}
return &pb.CreateHTTPAuthPolicyResponse{HttpAuthPolicyId: policyId}, nil
}
// UpdateHTTPAuthPolicy 修改策略
func (this *HTTPAuthPolicyService) UpdateHTTPAuthPolicy(ctx context.Context, req *pb.UpdateHTTPAuthPolicyRequest) (*pb.RPCSuccess, error) {
2022-07-22 14:35:17 +08:00
_, err := this.ValidateAdmin(ctx)
2021-06-17 21:17:53 +08:00
if err != nil {
return nil, err
}
var tx = this.NullTx()
err = models.SharedHTTPAuthPolicyDAO.UpdateHTTPAuthPolicy(tx, req.HttpAuthPolicyId, req.Name, req.ParamsJSON, req.IsOn)
if err != nil {
return nil, err
}
return this.Success()
}
// FindEnabledHTTPAuthPolicy 查找策略信息
func (this *HTTPAuthPolicyService) FindEnabledHTTPAuthPolicy(ctx context.Context, req *pb.FindEnabledHTTPAuthPolicyRequest) (*pb.FindEnabledHTTPAuthPolicyResponse, error) {
2022-07-22 14:35:17 +08:00
_, err := this.ValidateAdmin(ctx)
2021-06-17 21:17:53 +08:00
if err != nil {
return nil, err
}
var tx = this.NullTx()
policy, err := models.SharedHTTPAuthPolicyDAO.FindEnabledHTTPAuthPolicy(tx, req.HttpAuthPolicyId)
if err != nil {
return nil, err
}
if policy == nil {
return &pb.FindEnabledHTTPAuthPolicyResponse{HttpAuthPolicy: nil}, nil
}
return &pb.FindEnabledHTTPAuthPolicyResponse{HttpAuthPolicy: &pb.HTTPAuthPolicy{
Id: int64(policy.Id),
2022-03-22 21:45:07 +08:00
IsOn: policy.IsOn,
2021-06-17 21:17:53 +08:00
Name: policy.Name,
Type: policy.Type,
2022-03-22 19:30:30 +08:00
ParamsJSON: policy.Params,
2021-06-17 21:17:53 +08:00
}}, nil
}