Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions agent/app/api/v2/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ func (b *BaseApi) SyncFirewallRules(c *gin.Context) {
}

// @Tags Firewall
// @Summary Queue managed firewall rule deletion
// @Description Returns a taskID immediately; per-rule deletion results and failures are written to the task log.
// @Summary Queue firewall rule deletion
// @Description Deletes managed rules by UUID or unprotected before-chain rules by instance key. Returns a taskID immediately; results are written to the task log.
// @Accept json
// @Param request body dto.FirewallRuleDelete true "request"
// @Success 200 {object} dto.FirewallRuleDeleteResponse
Expand Down Expand Up @@ -494,10 +494,10 @@ func (b *BaseApi) LoadFirewallSettings(c *gin.Context) {

// @Tags Firewall
// @Summary Create firewall port whitelist rules
// @Description Returns a synchronization taskID. The whitelist configuration is saved only after synchronization succeeds.
// @Description Saves whitelist configuration only. Missing rules are added on startup, restart, initialization, or synchronization; existing rules are not removed.
// @Accept json
// @Param request body dto.FirewallPortWhitelistCreate true "request"
// @Success 200 {object} dto.FilterChainOperationResponse
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/firewall/settings/whitelist [post]
Expand All @@ -507,20 +507,19 @@ func (b *BaseApi) CreateFirewallPortWhitelist(c *gin.Context) {
if err := helper.CheckBindAndValidate(&request, c); err != nil {
return
}
result, err := firewallSettingService.CreatePortWhitelist(c.Request.Context(), request)
if err != nil {
if err := firewallSettingService.CreatePortWhitelist(c.Request.Context(), request); err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, result)
helper.Success(c)
}

// @Tags Firewall
// @Summary Update firewall port whitelist rules
// @Description Returns a synchronization taskID. The whitelist configuration is saved only after synchronization succeeds.
// @Description Saves whitelist configuration only. Missing rules are added on startup, restart, initialization, or synchronization; existing rules are not removed.
// @Accept json
// @Param request body dto.FirewallPortWhitelistUpdate true "request"
// @Success 200 {object} dto.FilterChainOperationResponse
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/firewall/settings/whitelist/update [post]
Expand All @@ -530,20 +529,19 @@ func (b *BaseApi) UpdateFirewallPortWhitelist(c *gin.Context) {
if err := helper.CheckBindAndValidate(&request, c); err != nil {
return
}
result, err := firewallSettingService.UpdatePortWhitelist(c.Request.Context(), request)
if err != nil {
if err := firewallSettingService.UpdatePortWhitelist(c.Request.Context(), request); err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, result)
helper.Success(c)
}

// @Tags Firewall
// @Summary Delete firewall port whitelist rules
// @Description Returns a synchronization taskID. The whitelist configuration is saved only after synchronization succeeds.
// @Description Saves whitelist configuration only. Missing rules are added on startup, restart, initialization, or synchronization; existing rules are not removed.
// @Accept json
// @Param request body dto.FirewallPortWhitelistDelete true "request"
// @Success 200 {object} dto.FilterChainOperationResponse
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/firewall/settings/whitelist/delete [post]
Expand All @@ -553,12 +551,11 @@ func (b *BaseApi) DeleteFirewallPortWhitelist(c *gin.Context) {
if err := helper.CheckBindAndValidate(&request, c); err != nil {
return
}
result, err := firewallSettingService.DeletePortWhitelist(c.Request.Context(), request)
if err != nil {
if err := firewallSettingService.DeletePortWhitelist(c.Request.Context(), request); err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, result)
helper.Success(c)
}

// @Tags Firewall
Expand Down
8 changes: 7 additions & 1 deletion agent/app/dto/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,13 @@ type FirewallRuleSyncFailure struct {
}

type FirewallRuleDelete struct {
UUIDs []string `json:"uuids" validate:"required,min=1,dive,required,max=64"`
UUIDs []string `json:"uuids" validate:"omitempty,dive,required,max=64"`
BeforeRules []FirewallRuleDeleteTarget `json:"beforeRules,omitempty" validate:"omitempty,dive"`
}

type FirewallRuleDeleteTarget struct {
Scope filter.Scope `json:"scope" validate:"required"`
InstanceKey string `json:"instanceKey" validate:"required,max=128"`
}

type FirewallRuleDeleteResponse struct {
Expand Down
6 changes: 0 additions & 6 deletions agent/app/repo/firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ type FirewallRuleRepo struct {
db *gorm.DB
}

func WithFirewallRuleSource(kind, id string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("owner = ?", model.FirewallRuleOwner(kind, id))
}
}

func NewIFirewallRuleRepo() IFirewallRuleRepo {
return &FirewallRuleRepo{}
}
Expand Down
Loading
Loading