From 23f4659d36f4c87ca4449afb52676ec4cfd9b03d Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Sun, 7 Mar 2021 10:59:52 -0500 Subject: [PATCH] Fix AP group access on API proxy --- unifi/ap_group.go | 4 ++-- unifi/unifi.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/unifi/ap_group.go b/unifi/ap_group.go index 66496a9..34e3f8d 100644 --- a/unifi/ap_group.go +++ b/unifi/ap_group.go @@ -28,7 +28,7 @@ type APGroup struct { func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error) { var respBody []APGroup - err := c.do(ctx, "GET", fmt.Sprintf("/v2/api/site/%s/apgroups", site), nil, &respBody) + err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/apgroups", c.apiV2Path, site), nil, &respBody) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error func (c *Client) CreateAPGroup(ctx context.Context, site string, d *APGroup) (*APGroup, error) { var respBody APGroup - err := c.do(ctx, "POST", fmt.Sprintf("/v2/api/site/%s/apgroups", site), d, &respBody) + err := c.do(ctx, "POST", fmt.Sprintf("%s/site/%s/apgroups", c.apiV2Path, site), d, &respBody) if err != nil { return nil, err } diff --git a/unifi/unifi.go b/unifi/unifi.go index 77600a7..9eb9d08 100644 --- a/unifi/unifi.go +++ b/unifi/unifi.go @@ -16,8 +16,11 @@ import ( ) const ( - apiPath = "/api" - apiPathNew = "/proxy/network/api" + apiPath = "/api" + apiV2Path = "/v2/api" + + apiPathNew = "/proxy/network/api" + apiV2PathNew = "/proxy/network/v2/api" loginPath = "/api/login" loginPathNew = "/api/auth/login" @@ -49,6 +52,7 @@ type Client struct { baseURL *url.URL apiPath string + apiV2Path string loginPath string statusPath string @@ -115,6 +119,7 @@ func (c *Client) setAPIUrlStyle(ctx context.Context) error { if resp.StatusCode == http.StatusOK { // the new API returns a 200 for a / request c.apiPath = apiPathNew + c.apiV2Path = apiV2PathNew c.loginPath = loginPathNew c.statusPath = statusPathNew return nil @@ -122,6 +127,7 @@ func (c *Client) setAPIUrlStyle(ctx context.Context) error { // The old version returns a "302" (to /manage) for a / request c.apiPath = apiPath + c.apiV2Path = apiV2Path c.loginPath = loginPath c.statusPath = statusPath return nil