mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/1Panel-dev/1Panel.git
synced 2026-09-21 00:24:12 +08:00
* refactor(firewall): rebuild rule management foundation * refactor(firewall): streamline rule checks and inventory * feat(firewall): improve native rule inventory * refactor(firewall): refine rule management * feat: add Docker port guard * feat(firewall): support native nftables * feat(firewall): add configurable firewall selection * feat(firewall): support nftables docker port guard * refactor(firewall): complete v2 rule management and migration * refactor(firewall): align state and API contracts * refactor(firewall): unify rule management operations * feat: refine firewall v2 rules and forwarding * fix(firewall): harden dual-stack rule management * refactor(firewall): consolidate rule validation and persistence
37 lines
1019 B
Go
37 lines
1019 B
Go
package repo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/1Panel-dev/1Panel/agent/app/model"
|
|
"github.com/1Panel-dev/1Panel/agent/global"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type IForwardingRuleRepo interface {
|
|
List(context.Context) ([]model.ForwardingRule, error)
|
|
ReplaceAll(context.Context, []model.ForwardingRule) error
|
|
}
|
|
|
|
type ForwardingRuleRepo struct{}
|
|
|
|
func NewIForwardingRuleRepo() IForwardingRuleRepo { return &ForwardingRuleRepo{} }
|
|
|
|
func (r *ForwardingRuleRepo) List(ctx context.Context) ([]model.ForwardingRule, error) {
|
|
var rules []model.ForwardingRule
|
|
err := global.DB.WithContext(ctx).Order("id ASC").Find(&rules).Error
|
|
return rules, err
|
|
}
|
|
|
|
func (r *ForwardingRuleRepo) ReplaceAll(ctx context.Context, rules []model.ForwardingRule) error {
|
|
return global.DB.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
if err := tx.Session(&gorm.Session{AllowGlobalUpdate: true}).Delete(&model.ForwardingRule{}).Error; err != nil {
|
|
return err
|
|
}
|
|
if len(rules) == 0 {
|
|
return nil
|
|
}
|
|
return tx.Create(&rules).Error
|
|
})
|
|
}
|