Compare commits

...

12 Commits

Author SHA1 Message Date
5626d6341e Merge branch '2-create-firewall-zone-api' 2025-04-14 08:19:13 +02:00
825508ed03 debugging 2025-04-14 08:19:06 +02:00
b3b119c402 Merge branch '2-create-firewall-zone-api' 2025-04-13 19:39:29 +02:00
b4e2400bcf Another test 2025-04-13 19:39:16 +02:00
8974e82e78 Merge 2025-04-13 15:42:41 +02:00
01e89ca98d debug firewall zone api 2025-04-13 15:42:28 +02:00
f85fe28c53 Merge branch '2-create-firewall-zone-api' 2025-04-13 15:36:23 +02:00
82702848f9 fix 2025-04-13 15:35:58 +02:00
c52743effa Merge branch '2-create-firewall-zone-api' 2025-04-13 15:26:49 +02:00
b079790183 reverse test 2025-04-13 15:26:35 +02:00
bae6a964eb Merge branch '2-create-firewall-zone-api' 2025-04-13 15:20:31 +02:00
bab50ebfc4 Unifi API v2 2025-04-13 15:20:13 +02:00
2 changed files with 13 additions and 8 deletions

View File

@@ -14,25 +14,23 @@ type FirewallZone struct {
// NoEdit bool `json:"attr_no_edit,omitempty"` // NoEdit bool `json:"attr_no_edit,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"desc"`
DefaultZone bool `json:default_zone,omitempty` DefaultZone bool `json:default_zone,omitempty`
NetworkIDs []string `json:network_ids,omitempty` NetworkIDs []string `json:network_ids,omitempty`
ZoneKey string `json:"zone_key,omitempty"`
// Role string `json:"role"` // Role string `json:"role"`
} }
func (c *Client) ListFirewallZones(ctx context.Context, site string) ([]FirewallZone, error) { func (c *Client) ListFirewallZones(ctx context.Context, site string) ([]FirewallZone, error) {
var respBody struct { var respBody []FirewallZone
Meta meta `json:"meta"`
Data []FirewallZone `json:"data"`
}
err := c.do(ctx, "GET", fmt.Sprintf("site/%s/firewall/zone", site), nil, &respBody) err := c.do(ctx, "GET", fmt.Sprintf("site/%s/firewall/zone", site), nil, &respBody)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return respBody.Data, nil return respBody, nil
} }
func (c *Client) GetFirewallZone(ctx context.Context, site, id string) (*FirewallZone, error) { func (c *Client) GetFirewallZone(ctx context.Context, site, id string) (*FirewallZone, error) {

View File

@@ -13,6 +13,7 @@ import (
"path" "path"
"strings" "strings"
"sync" "sync"
"log"
) )
const ( const (
@@ -213,7 +214,11 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err) return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err)
} }
if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() { if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() {
reqURL.Path = path.Join(c.apiPath, reqURL.Path) if strings.Contains(relativeURL, "firewall/zone") {
reqURL.Path = path.Join(c.apiV2Path, reqURL.Path)
} else {
reqURL.Path = path.Join(c.apiPath, reqURL.Path)
}
} }
url := c.baseURL.ResolveReference(reqURL) url := c.baseURL.ResolveReference(reqURL)
@@ -269,7 +274,9 @@ func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody int
} }
// TODO: check rc in addition to status code? // TODO: check rc in addition to status code?
log.Printf("%+v", respBody)
log.Printf("%+v", resp.Body)
err = json.NewDecoder(resp.Body).Decode(respBody) err = json.NewDecoder(resp.Body).Decode(respBody)
if err != nil { if err != nil {
return fmt.Errorf("unable to decode body: %s %s %w", method, relativeURL, err) return fmt.Errorf("unable to decode body: %s %s %w", method, relativeURL, err)