mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 06:40:26 +08:00
访问日志存储策略增加“停止默认数据库存储”选项
This commit is contained in:
@@ -12,5 +12,5 @@ dbs:
|
||||
|
||||
|
||||
fields:
|
||||
bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "autoSystemTuning" ]
|
||||
bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "autoSystemTuning", "disableDefaultDB" ]
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func (this *HTTPAccessLogPolicyDAO) FindAllEnabledAndOnPolicies(tx *dbs.Tx) (res
|
||||
}
|
||||
|
||||
// CreatePolicy 创建策略
|
||||
func (this *HTTPAccessLogPolicyDAO) CreatePolicy(tx *dbs.Tx, name string, policyType string, optionsJSON []byte, condsJSON []byte, isPublic bool, firewallOnly bool) (policyId int64, err error) {
|
||||
func (this *HTTPAccessLogPolicyDAO) CreatePolicy(tx *dbs.Tx, name string, policyType string, optionsJSON []byte, condsJSON []byte, isPublic bool, firewallOnly bool, disableDefaultDB bool) (policyId int64, err error) {
|
||||
var op = NewHTTPAccessLogPolicyOperator()
|
||||
op.Name = name
|
||||
op.Type = policyType
|
||||
@@ -120,12 +120,13 @@ func (this *HTTPAccessLogPolicyDAO) CreatePolicy(tx *dbs.Tx, name string, policy
|
||||
op.IsPublic = isPublic
|
||||
op.IsOn = true
|
||||
op.FirewallOnly = firewallOnly
|
||||
op.DisableDefaultDB = disableDefaultDB
|
||||
op.State = HTTPAccessLogPolicyStateEnabled
|
||||
return this.SaveInt64(tx, op)
|
||||
}
|
||||
|
||||
// UpdatePolicy 修改策略
|
||||
func (this *HTTPAccessLogPolicyDAO) UpdatePolicy(tx *dbs.Tx, policyId int64, name string, optionsJSON []byte, condsJSON []byte, isPublic bool, firewallOnly bool, isOn bool) error {
|
||||
func (this *HTTPAccessLogPolicyDAO) UpdatePolicy(tx *dbs.Tx, policyId int64, name string, optionsJSON []byte, condsJSON []byte, isPublic bool, firewallOnly bool, disableDefaultDB bool, isOn bool) error {
|
||||
if policyId <= 0 {
|
||||
return errors.New("invalid policyId")
|
||||
}
|
||||
@@ -159,6 +160,7 @@ func (this *HTTPAccessLogPolicyDAO) UpdatePolicy(tx *dbs.Tx, policyId int64, nam
|
||||
|
||||
op.IsPublic = isPublic
|
||||
op.FirewallOnly = firewallOnly
|
||||
op.DisableDefaultDB = disableDefaultDB
|
||||
op.IsOn = isOn
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
@@ -2,39 +2,59 @@ package models
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
const (
|
||||
HTTPAccessLogPolicyField_Id dbs.FieldName = "id" // ID
|
||||
HTTPAccessLogPolicyField_TemplateId dbs.FieldName = "templateId" // 模版ID
|
||||
HTTPAccessLogPolicyField_AdminId dbs.FieldName = "adminId" // 管理员ID
|
||||
HTTPAccessLogPolicyField_UserId dbs.FieldName = "userId" // 用户ID
|
||||
HTTPAccessLogPolicyField_State dbs.FieldName = "state" // 状态
|
||||
HTTPAccessLogPolicyField_CreatedAt dbs.FieldName = "createdAt" // 创建时间
|
||||
HTTPAccessLogPolicyField_Name dbs.FieldName = "name" // 名称
|
||||
HTTPAccessLogPolicyField_IsOn dbs.FieldName = "isOn" // 是否启用
|
||||
HTTPAccessLogPolicyField_Type dbs.FieldName = "type" // 存储类型
|
||||
HTTPAccessLogPolicyField_Options dbs.FieldName = "options" // 存储选项
|
||||
HTTPAccessLogPolicyField_Conds dbs.FieldName = "conds" // 请求条件
|
||||
HTTPAccessLogPolicyField_IsPublic dbs.FieldName = "isPublic" // 是否为公用
|
||||
HTTPAccessLogPolicyField_FirewallOnly dbs.FieldName = "firewallOnly" // 是否只记录防火墙相关
|
||||
HTTPAccessLogPolicyField_Version dbs.FieldName = "version" // 版本号
|
||||
HTTPAccessLogPolicyField_DisableDefaultDB dbs.FieldName = "disableDefaultDB" // 是否停止默认数据库存储
|
||||
)
|
||||
|
||||
// HTTPAccessLogPolicy 访问日志策略
|
||||
type HTTPAccessLogPolicy struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Name string `field:"name"` // 名称
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
Type string `field:"type"` // 存储类型
|
||||
Options dbs.JSON `field:"options"` // 存储选项
|
||||
Conds dbs.JSON `field:"conds"` // 请求条件
|
||||
IsPublic bool `field:"isPublic"` // 是否为公用
|
||||
FirewallOnly uint8 `field:"firewallOnly"` // 是否只记录防火墙相关
|
||||
Version uint32 `field:"version"` // 版本号
|
||||
Id uint32 `field:"id"` // ID
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Name string `field:"name"` // 名称
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
Type string `field:"type"` // 存储类型
|
||||
Options dbs.JSON `field:"options"` // 存储选项
|
||||
Conds dbs.JSON `field:"conds"` // 请求条件
|
||||
IsPublic bool `field:"isPublic"` // 是否为公用
|
||||
FirewallOnly uint8 `field:"firewallOnly"` // 是否只记录防火墙相关
|
||||
Version uint32 `field:"version"` // 版本号
|
||||
DisableDefaultDB bool `field:"disableDefaultDB"` // 是否停止默认数据库存储
|
||||
}
|
||||
|
||||
type HTTPAccessLogPolicyOperator struct {
|
||||
Id interface{} // ID
|
||||
TemplateId interface{} // 模版ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Name interface{} // 名称
|
||||
IsOn interface{} // 是否启用
|
||||
Type interface{} // 存储类型
|
||||
Options interface{} // 存储选项
|
||||
Conds interface{} // 请求条件
|
||||
IsPublic interface{} // 是否为公用
|
||||
FirewallOnly interface{} // 是否只记录防火墙相关
|
||||
Version interface{} // 版本号
|
||||
Id any // ID
|
||||
TemplateId any // 模版ID
|
||||
AdminId any // 管理员ID
|
||||
UserId any // 用户ID
|
||||
State any // 状态
|
||||
CreatedAt any // 创建时间
|
||||
Name any // 名称
|
||||
IsOn any // 是否启用
|
||||
Type any // 存储类型
|
||||
Options any // 存储选项
|
||||
Conds any // 请求条件
|
||||
IsPublic any // 是否为公用
|
||||
FirewallOnly any // 是否只记录防火墙相关
|
||||
Version any // 版本号
|
||||
DisableDefaultDB any // 是否停止默认数据库存储
|
||||
}
|
||||
|
||||
func NewHTTPAccessLogPolicyOperator() *HTTPAccessLogPolicyOperator {
|
||||
|
||||
@@ -31,9 +31,11 @@ func (this *HTTPAccessLogService) CreateHTTPAccessLogs(ctx context.Context, req
|
||||
|
||||
var tx = this.NullTx()
|
||||
|
||||
err = models.SharedHTTPAccessLogDAO.CreateHTTPAccessLogs(tx, req.HttpAccessLogs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if this.canWriteAccessLogsToDB() {
|
||||
err = models.SharedHTTPAccessLogDAO.CreateHTTPAccessLogs(tx, req.HttpAccessLogs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = this.writeAccessLogsToPolicy(req.HttpAccessLogs)
|
||||
|
||||
@@ -5,6 +5,10 @@ package services
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
|
||||
func (this *HTTPAccessLogService) canWriteAccessLogsToDB() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *HTTPAccessLogService) writeAccessLogsToPolicy(pbAccessLogs []*pb.HTTPAccessLog) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user