mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
实现访问日志配置
This commit is contained in:
39
internal/rpc/services/service_http_access_log_policy.go
Normal file
39
internal/rpc/services/service_http_access_log_policy.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type HTTPAccessLogPolicyService struct {
|
||||
}
|
||||
|
||||
// 获取所有可用策略
|
||||
func (this *HTTPAccessLogPolicyService) FindAllEnabledHTTPAccessLogPolicies(ctx context.Context, req *pb.FindAllEnabledHTTPAccessLogPoliciesRequest) (*pb.FindAllEnabledHTTPAccessLogPoliciesResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
policies, err := models.SharedHTTPAccessLogPolicyDAO.FindAllEnabledAccessLogPolicies()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := []*pb.HTTPAccessLogPolicy{}
|
||||
for _, policy := range policies {
|
||||
result = append(result, &pb.HTTPAccessLogPolicy{
|
||||
Id: int64(policy.Id),
|
||||
Name: policy.Name,
|
||||
IsOn: policy.IsOn == 1,
|
||||
Type: policy.Name,
|
||||
OptionsJSON: []byte(policy.Options),
|
||||
CondsJSON: []byte(policy.Conds),
|
||||
})
|
||||
}
|
||||
|
||||
return &pb.FindAllEnabledHTTPAccessLogPoliciesResponse{AccessLogPolicies: result}, nil
|
||||
}
|
||||
@@ -162,3 +162,18 @@ func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.Upda
|
||||
}
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
// 更改访问日志配置
|
||||
func (this *HTTPWebService) UpdateHTTPAccessLog(ctx context.Context, req *pb.UpdateHTTPAccessLogRequest) (*pb.RPCUpdateSuccess, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebAccessLogConfig(req.WebId, req.AccessLogJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rpcutils.RPCUpdateSuccess()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user