Skip to content

Commit

Permalink
Support firewall reorder command
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Apr 27, 2023
1 parent ae8d410 commit dfbeb75
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions unifi/firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ package unifi

import (
"context"
"fmt"
)

type FirewallRuleIndexUpdate struct {
ID string `json:"_id"`
RuleIndex int `json:"rule_index,string"`
}

func (c *Client) ListFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) {
return c.listFirewallRule(ctx, site)
}
Expand All @@ -23,3 +29,21 @@ func (c *Client) CreateFirewallRule(ctx context.Context, site string, d *Firewal
func (c *Client) UpdateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) {
return c.updateFirewallRule(ctx, site, d)
}

func (c *Client) ReorderFirewallRules(ctx context.Context, site, ruleset string, reorder []FirewallRuleIndexUpdate) error {
reqBody := struct {
Cmd string `json:"cmd"`
Ruleset string `json:"ruleset"`
Rules []FirewallRuleIndexUpdate `json:"rules"`
}{
Cmd: "reorder",
Ruleset: ruleset,
Rules: reorder,
}
err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/firewall", site), reqBody, nil)
if err != nil {
return err
}

return nil
}

0 comments on commit dfbeb75

Please sign in to comment.