Support firewall reorder command (#127)

This commit is contained in:
jeanluc
2023-06-22 00:46:45 +00:00
committed by GitHub
parent fec12ad245
commit 2f40c2d150

View File

@@ -2,8 +2,14 @@ package unifi
import ( import (
"context" "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) { func (c *Client) ListFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) {
return c.listFirewallRule(ctx, site) 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) { func (c *Client) UpdateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) {
return c.updateFirewallRule(ctx, site, d) 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
}