From 2f40c2d150d728a4b8475814551906d58ceca4fe Mon Sep 17 00:00:00 2001 From: jeanluc <2163936+lkubb@users.noreply.github.com> Date: Thu, 22 Jun 2023 00:46:45 +0000 Subject: [PATCH] Support firewall reorder command (#127) --- unifi/firewall_rule.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go index 361ed88..8a1c929 100644 --- a/unifi/firewall_rule.go +++ b/unifi/firewall_rule.go @@ -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) } @@ -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 +}