Bump to go-unifi 1.2.0
Add context.TODO to prep for SDKv2
This commit is contained in:
4
go.mod
4
go.mod
@@ -2,6 +2,8 @@ module github.com/paultyng/terraform-provider-unifi
|
||||
|
||||
go 1.12
|
||||
|
||||
// replace github.com/paultyng/go-unifi => ../go-unifi
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.50.0 // indirect
|
||||
cloud.google.com/go/bigquery v1.3.0 // indirect
|
||||
@@ -20,7 +22,7 @@ require (
|
||||
github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect
|
||||
github.com/jstemmer/go-junit-report v0.9.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.11 // indirect
|
||||
github.com/paultyng/go-unifi v1.1.0
|
||||
github.com/paultyng/go-unifi v1.2.0
|
||||
github.com/posener/complete v1.2.3 // indirect
|
||||
github.com/sergi/go-diff v1.1.0 // indirect
|
||||
github.com/ulikunitz/xz v0.5.6 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -310,8 +310,8 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/packer-community/winrmcp v0.0.0-20180102160824-81144009af58/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/paultyng/go-unifi v1.1.0 h1:muFZHYGu+FdycoCd3w0nkmoMAflxlBYuI5MLWWDFWnc=
|
||||
github.com/paultyng/go-unifi v1.1.0/go.mod h1:L8VrStOsfwfMx4lk8vxlOJS0D6Pj4rkV4wHAj8yP0dc=
|
||||
github.com/paultyng/go-unifi v1.2.0 h1:O9UqmwGSqr8GGycKZ4+3hpFUB7KEnACBhAjTp6P7qb0=
|
||||
github.com/paultyng/go-unifi v1.2.0/go.mod h1:L8VrStOsfwfMx4lk8vxlOJS0D6Pj4rkV4wHAj8yP0dc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
@@ -34,7 +35,7 @@ func dataUserGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
groups, err := c.c.ListUserGroup(c.site)
|
||||
groups, err := c.c.ListUserGroup(context.TODO(), c.site)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
@@ -25,7 +26,7 @@ func dataWLANGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
groups, err := c.c.ListWLANGroup(c.site)
|
||||
groups, err := c.c.ListWLANGroup(context.TODO(), c.site)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -49,7 +50,7 @@ func setHTTPClient(c *unifi.Client) {
|
||||
c.SetHTTPClient(httpClient)
|
||||
}
|
||||
|
||||
func (c *lazyClient) init() error {
|
||||
func (c *lazyClient) init(ctx context.Context) error {
|
||||
var err error
|
||||
c.once.Do(func() {
|
||||
c.inner = &unifi.Client{}
|
||||
@@ -60,128 +61,148 @@ func (c *lazyClient) init() error {
|
||||
return
|
||||
}
|
||||
|
||||
err = c.inner.Login(c.user, c.pass)
|
||||
err = c.inner.Login(ctx, c.user, c.pass)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *lazyClient) ListUserGroup(site string) ([]unifi.UserGroup, error) {
|
||||
c.init()
|
||||
return c.inner.ListUserGroup(site)
|
||||
func (c *lazyClient) ListUserGroup(ctx context.Context, site string) ([]unifi.UserGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.ListUserGroup(ctx, site)
|
||||
}
|
||||
func (c *lazyClient) ListWLANGroup(site string) ([]unifi.WLANGroup, error) {
|
||||
c.init()
|
||||
return c.inner.ListWLANGroup(site)
|
||||
func (c *lazyClient) ListWLANGroup(ctx context.Context, site string) ([]unifi.WLANGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.ListWLANGroup(ctx, site)
|
||||
}
|
||||
func (c *lazyClient) DeleteNetwork(site, id, name string) error {
|
||||
c.init()
|
||||
return c.inner.DeleteNetwork(site, id, name)
|
||||
func (c *lazyClient) DeleteNetwork(ctx context.Context, site, id, name string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteNetwork(ctx, site, id, name)
|
||||
}
|
||||
func (c *lazyClient) CreateNetwork(site string, d *unifi.Network) (*unifi.Network, error) {
|
||||
c.init()
|
||||
return c.inner.CreateNetwork(site, d)
|
||||
func (c *lazyClient) CreateNetwork(ctx context.Context, site string, d *unifi.Network) (*unifi.Network, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateNetwork(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetNetwork(site, id string) (*unifi.Network, error) {
|
||||
c.init()
|
||||
return c.inner.GetNetwork(site, id)
|
||||
func (c *lazyClient) GetNetwork(ctx context.Context, site, id string) (*unifi.Network, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetNetwork(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) UpdateNetwork(site string, d *unifi.Network) (*unifi.Network, error) {
|
||||
c.init()
|
||||
return c.inner.UpdateNetwork(site, d)
|
||||
func (c *lazyClient) UpdateNetwork(ctx context.Context, site string, d *unifi.Network) (*unifi.Network, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateNetwork(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) DeleteWLAN(site, id string) error {
|
||||
c.init()
|
||||
return c.inner.DeleteWLAN(site, id)
|
||||
func (c *lazyClient) DeleteWLAN(ctx context.Context, site, id string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteWLAN(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) CreateWLAN(site string, d *unifi.WLAN) (*unifi.WLAN, error) {
|
||||
c.init()
|
||||
return c.inner.CreateWLAN(site, d)
|
||||
func (c *lazyClient) CreateWLAN(ctx context.Context, site string, d *unifi.WLAN) (*unifi.WLAN, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateWLAN(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetWLAN(site, id string) (*unifi.WLAN, error) {
|
||||
c.init()
|
||||
return c.inner.GetWLAN(site, id)
|
||||
func (c *lazyClient) GetWLAN(ctx context.Context, site, id string) (*unifi.WLAN, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetWLAN(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) UpdateWLAN(site string, d *unifi.WLAN) (*unifi.WLAN, error) {
|
||||
c.init()
|
||||
return c.inner.UpdateWLAN(site, d)
|
||||
func (c *lazyClient) UpdateWLAN(ctx context.Context, site string, d *unifi.WLAN) (*unifi.WLAN, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateWLAN(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) DeleteUserGroup(site, id string) error {
|
||||
c.init()
|
||||
return c.inner.DeleteUserGroup(site, id)
|
||||
func (c *lazyClient) DeleteUserGroup(ctx context.Context, site, id string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteUserGroup(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) CreateUserGroup(site string, d *unifi.UserGroup) (*unifi.UserGroup, error) {
|
||||
c.init()
|
||||
return c.inner.CreateUserGroup(site, d)
|
||||
func (c *lazyClient) CreateUserGroup(ctx context.Context, site string, d *unifi.UserGroup) (*unifi.UserGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateUserGroup(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetUserGroup(site, id string) (*unifi.UserGroup, error) {
|
||||
c.init()
|
||||
return c.inner.GetUserGroup(site, id)
|
||||
func (c *lazyClient) GetUserGroup(ctx context.Context, site, id string) (*unifi.UserGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetUserGroup(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) UpdateUserGroup(site string, d *unifi.UserGroup) (*unifi.UserGroup, error) {
|
||||
c.init()
|
||||
return c.inner.UpdateUserGroup(site, d)
|
||||
func (c *lazyClient) UpdateUserGroup(ctx context.Context, site string, d *unifi.UserGroup) (*unifi.UserGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateUserGroup(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetUser(site, id string) (*unifi.User, error) {
|
||||
c.init()
|
||||
return c.inner.GetUser(site, id)
|
||||
func (c *lazyClient) GetUser(ctx context.Context, site, id string) (*unifi.User, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetUser(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) GetUserByMAC(site, mac string) (*unifi.User, error) {
|
||||
c.init()
|
||||
return c.inner.GetUserByMAC(site, mac)
|
||||
func (c *lazyClient) GetUserByMAC(ctx context.Context, site, mac string) (*unifi.User, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetUserByMAC(ctx, site, mac)
|
||||
}
|
||||
func (c *lazyClient) CreateUser(site string, d *unifi.User) (*unifi.User, error) {
|
||||
c.init()
|
||||
return c.inner.CreateUser(site, d)
|
||||
func (c *lazyClient) CreateUser(ctx context.Context, site string, d *unifi.User) (*unifi.User, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateUser(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) UpdateUser(site string, d *unifi.User) (*unifi.User, error) {
|
||||
c.init()
|
||||
return c.inner.UpdateUser(site, d)
|
||||
func (c *lazyClient) UpdateUser(ctx context.Context, site string, d *unifi.User) (*unifi.User, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateUser(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) DeleteUserByMAC(site, mac string) error {
|
||||
c.init()
|
||||
return c.inner.DeleteUserByMAC(site, mac)
|
||||
func (c *lazyClient) DeleteUserByMAC(ctx context.Context, site, mac string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteUserByMAC(ctx, site, mac)
|
||||
}
|
||||
func (c *lazyClient) BlockUserByMAC(site, mac string) error {
|
||||
c.init()
|
||||
return c.inner.BlockUserByMAC(site, mac)
|
||||
func (c *lazyClient) BlockUserByMAC(ctx context.Context, site, mac string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.BlockUserByMAC(ctx, site, mac)
|
||||
}
|
||||
func (c *lazyClient) UnblockUserByMAC(site, mac string) error {
|
||||
c.init()
|
||||
return c.inner.UnblockUserByMAC(site, mac)
|
||||
func (c *lazyClient) UnblockUserByMAC(ctx context.Context, site, mac string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.UnblockUserByMAC(ctx, site, mac)
|
||||
}
|
||||
func (c *lazyClient) ListFirewallGroup(site string) ([]unifi.FirewallGroup, error) {
|
||||
c.init()
|
||||
return c.inner.ListFirewallGroup(site)
|
||||
func (c *lazyClient) ListFirewallGroup(ctx context.Context, site string) ([]unifi.FirewallGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.ListFirewallGroup(ctx, site)
|
||||
}
|
||||
func (c *lazyClient) DeleteFirewallGroup(site, id string) error {
|
||||
c.init()
|
||||
return c.inner.DeleteFirewallGroup(site, id)
|
||||
func (c *lazyClient) DeleteFirewallGroup(ctx context.Context, site, id string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteFirewallGroup(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) CreateFirewallGroup(site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error) {
|
||||
c.init()
|
||||
return c.inner.CreateFirewallGroup(site, d)
|
||||
func (c *lazyClient) CreateFirewallGroup(ctx context.Context, site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateFirewallGroup(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetFirewallGroup(site, id string) (*unifi.FirewallGroup, error) {
|
||||
c.init()
|
||||
return c.inner.GetFirewallGroup(site, id)
|
||||
func (c *lazyClient) GetFirewallGroup(ctx context.Context, site, id string) (*unifi.FirewallGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetFirewallGroup(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) UpdateFirewallGroup(site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error) {
|
||||
c.init()
|
||||
return c.inner.UpdateFirewallGroup(site, d)
|
||||
func (c *lazyClient) UpdateFirewallGroup(ctx context.Context, site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateFirewallGroup(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetPortForward(site, id string) (*unifi.PortForward, error) {
|
||||
c.init()
|
||||
return c.inner.GetPortForward(site, id)
|
||||
func (c *lazyClient) ListFirewallRule(ctx context.Context, site string) ([]unifi.FirewallRule, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.ListFirewallRule(ctx, site)
|
||||
}
|
||||
func (c *lazyClient) DeletePortForward(site, id string) error {
|
||||
c.init()
|
||||
return c.inner.DeletePortForward(site, id)
|
||||
func (c *lazyClient) DeleteFirewallRule(ctx context.Context, site, id string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeleteFirewallRule(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) CreatePortForward(site string, d *unifi.PortForward) (*unifi.PortForward, error) {
|
||||
c.init()
|
||||
return c.inner.CreatePortForward(site, d)
|
||||
func (c *lazyClient) CreateFirewallRule(ctx context.Context, site string, d *unifi.FirewallRule) (*unifi.FirewallRule, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreateFirewallRule(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) UpdatePortForward(site string, d *unifi.PortForward) (*unifi.PortForward, error) {
|
||||
c.init()
|
||||
return c.inner.UpdatePortForward(site, d)
|
||||
func (c *lazyClient) GetFirewallRule(ctx context.Context, site, id string) (*unifi.FirewallRule, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetFirewallRule(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) UpdateFirewallRule(ctx context.Context, site string, d *unifi.FirewallRule) (*unifi.FirewallRule, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdateFirewallRule(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) GetPortForward(ctx context.Context, site, id string) (*unifi.PortForward, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.GetPortForward(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) DeletePortForward(ctx context.Context, site, id string) error {
|
||||
c.init(ctx)
|
||||
return c.inner.DeletePortForward(ctx, site, id)
|
||||
}
|
||||
func (c *lazyClient) CreatePortForward(ctx context.Context, site string, d *unifi.PortForward) (*unifi.PortForward, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.CreatePortForward(ctx, site, d)
|
||||
}
|
||||
func (c *lazyClient) UpdatePortForward(ctx context.Context, site string, d *unifi.PortForward) (*unifi.PortForward, error) {
|
||||
c.init(ctx)
|
||||
return c.inner.UpdatePortForward(ctx, site, d)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/terraform"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -74,42 +76,48 @@ func configure(p *schema.Provider) schema.ConfigureFunc {
|
||||
}
|
||||
|
||||
type unifiClient interface {
|
||||
ListUserGroup(site string) ([]unifi.UserGroup, error)
|
||||
DeleteUserGroup(site, id string) error
|
||||
CreateUserGroup(site string, d *unifi.UserGroup) (*unifi.UserGroup, error)
|
||||
GetUserGroup(site, id string) (*unifi.UserGroup, error)
|
||||
UpdateUserGroup(site string, d *unifi.UserGroup) (*unifi.UserGroup, error)
|
||||
ListUserGroup(ctx context.Context, site string) ([]unifi.UserGroup, error)
|
||||
DeleteUserGroup(ctx context.Context, site, id string) error
|
||||
CreateUserGroup(ctx context.Context, site string, d *unifi.UserGroup) (*unifi.UserGroup, error)
|
||||
GetUserGroup(ctx context.Context, site, id string) (*unifi.UserGroup, error)
|
||||
UpdateUserGroup(ctx context.Context, site string, d *unifi.UserGroup) (*unifi.UserGroup, error)
|
||||
|
||||
ListFirewallGroup(site string) ([]unifi.FirewallGroup, error)
|
||||
DeleteFirewallGroup(site, id string) error
|
||||
CreateFirewallGroup(site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error)
|
||||
GetFirewallGroup(site, id string) (*unifi.FirewallGroup, error)
|
||||
UpdateFirewallGroup(site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error)
|
||||
ListFirewallGroup(ctx context.Context, site string) ([]unifi.FirewallGroup, error)
|
||||
DeleteFirewallGroup(ctx context.Context, site, id string) error
|
||||
CreateFirewallGroup(ctx context.Context, site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error)
|
||||
GetFirewallGroup(ctx context.Context, site, id string) (*unifi.FirewallGroup, error)
|
||||
UpdateFirewallGroup(ctx context.Context, site string, d *unifi.FirewallGroup) (*unifi.FirewallGroup, error)
|
||||
|
||||
ListWLANGroup(site string) ([]unifi.WLANGroup, error)
|
||||
ListFirewallRule(ctx context.Context, site string) ([]unifi.FirewallRule, error)
|
||||
DeleteFirewallRule(ctx context.Context, site, id string) error
|
||||
CreateFirewallRule(ctx context.Context, site string, d *unifi.FirewallRule) (*unifi.FirewallRule, error)
|
||||
GetFirewallRule(ctx context.Context, site, id string) (*unifi.FirewallRule, error)
|
||||
UpdateFirewallRule(ctx context.Context, site string, d *unifi.FirewallRule) (*unifi.FirewallRule, error)
|
||||
|
||||
DeleteNetwork(site, id, name string) error
|
||||
CreateNetwork(site string, d *unifi.Network) (*unifi.Network, error)
|
||||
GetNetwork(site, id string) (*unifi.Network, error)
|
||||
UpdateNetwork(site string, d *unifi.Network) (*unifi.Network, error)
|
||||
ListWLANGroup(ctx context.Context, site string) ([]unifi.WLANGroup, error)
|
||||
|
||||
DeleteWLAN(site, id string) error
|
||||
CreateWLAN(site string, d *unifi.WLAN) (*unifi.WLAN, error)
|
||||
GetWLAN(site, id string) (*unifi.WLAN, error)
|
||||
UpdateWLAN(site string, d *unifi.WLAN) (*unifi.WLAN, error)
|
||||
DeleteNetwork(ctx context.Context, site, id, name string) error
|
||||
CreateNetwork(ctx context.Context, site string, d *unifi.Network) (*unifi.Network, error)
|
||||
GetNetwork(ctx context.Context, site, id string) (*unifi.Network, error)
|
||||
UpdateNetwork(ctx context.Context, site string, d *unifi.Network) (*unifi.Network, error)
|
||||
|
||||
GetUser(site, id string) (*unifi.User, error)
|
||||
GetUserByMAC(site, mac string) (*unifi.User, error)
|
||||
CreateUser(site string, d *unifi.User) (*unifi.User, error)
|
||||
BlockUserByMAC(site, mac string) error
|
||||
UnblockUserByMAC(site, mac string) error
|
||||
UpdateUser(site string, d *unifi.User) (*unifi.User, error)
|
||||
DeleteUserByMAC(site, mac string) error
|
||||
DeleteWLAN(ctx context.Context, site, id string) error
|
||||
CreateWLAN(ctx context.Context, site string, d *unifi.WLAN) (*unifi.WLAN, error)
|
||||
GetWLAN(ctx context.Context, site, id string) (*unifi.WLAN, error)
|
||||
UpdateWLAN(ctx context.Context, site string, d *unifi.WLAN) (*unifi.WLAN, error)
|
||||
|
||||
GetPortForward(site, id string) (*unifi.PortForward, error)
|
||||
DeletePortForward(site, id string) error
|
||||
CreatePortForward(site string, d *unifi.PortForward) (*unifi.PortForward, error)
|
||||
UpdatePortForward(site string, d *unifi.PortForward) (*unifi.PortForward, error)
|
||||
GetUser(ctx context.Context, site, id string) (*unifi.User, error)
|
||||
GetUserByMAC(ctx context.Context, site, mac string) (*unifi.User, error)
|
||||
CreateUser(ctx context.Context, site string, d *unifi.User) (*unifi.User, error)
|
||||
BlockUserByMAC(ctx context.Context, site, mac string) error
|
||||
UnblockUserByMAC(ctx context.Context, site, mac string) error
|
||||
UpdateUser(ctx context.Context, site string, d *unifi.User) (*unifi.User, error)
|
||||
DeleteUserByMAC(ctx context.Context, site, mac string) error
|
||||
|
||||
GetPortForward(ctx context.Context, site, id string) (*unifi.PortForward, error)
|
||||
DeletePortForward(ctx context.Context, site, id string) error
|
||||
CreatePortForward(ctx context.Context, site string, d *unifi.PortForward) (*unifi.PortForward, error)
|
||||
UpdatePortForward(ctx context.Context, site string, d *unifi.PortForward) (*unifi.PortForward, error)
|
||||
}
|
||||
|
||||
type client struct {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -30,7 +31,7 @@ func TestMain(m *testing.M) {
|
||||
testClient = &unifi.Client{}
|
||||
setHTTPClient(testClient)
|
||||
testClient.SetBaseURL(baseURL)
|
||||
err := testClient.Login(user, pass)
|
||||
err := testClient.Login(context.Background(), user, pass)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -43,7 +45,7 @@ func resourceFirewallGroupCreate(d *schema.ResourceData, meta interface{}) error
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.c.CreateFirewallGroup(c.site, req)
|
||||
resp, err := c.c.CreateFirewallGroup(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -79,7 +81,7 @@ func resourceFirewallGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetFirewallGroup(c.site, id)
|
||||
resp, err := c.c.GetFirewallGroup(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -102,7 +104,7 @@ func resourceFirewallGroupUpdate(d *schema.ResourceData, meta interface{}) error
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdateFirewallGroup(c.site, req)
|
||||
resp, err := c.c.UpdateFirewallGroup(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -115,7 +117,7 @@ func resourceFirewallGroupDelete(d *schema.ResourceData, meta interface{}) error
|
||||
|
||||
id := d.Id()
|
||||
|
||||
err := c.c.DeleteFirewallGroup(c.site, id)
|
||||
err := c.c.DeleteFirewallGroup(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -80,7 +82,7 @@ func resourceNetworkCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.c.CreateNetwork(c.site, req)
|
||||
resp, err := c.c.CreateNetwork(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -147,7 +149,7 @@ func resourceNetworkRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetNetwork(c.site, id)
|
||||
resp, err := c.c.GetNetwork(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -170,7 +172,7 @@ func resourceNetworkUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdateNetwork(c.site, req)
|
||||
resp, err := c.c.UpdateNetwork(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,7 +186,7 @@ func resourceNetworkDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
name := d.Get("name").(string)
|
||||
id := d.Id()
|
||||
|
||||
err := c.c.DeleteNetwork(c.site, id, name)
|
||||
err := c.c.DeleteNetwork(context.TODO(), c.site, id, name)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -77,7 +79,7 @@ func resourcePortForwardCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.c.CreatePortForward(c.site, req)
|
||||
resp, err := c.c.CreatePortForward(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -120,7 +122,7 @@ func resourcePortForwardRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetPortForward(c.site, id)
|
||||
resp, err := c.c.GetPortForward(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -143,7 +145,7 @@ func resourcePortForwardUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdatePortForward(c.site, req)
|
||||
resp, err := c.c.UpdatePortForward(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -156,6 +158,6 @@ func resourcePortForwardDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
err := c.c.DeletePortForward(c.site, id)
|
||||
err := c.c.DeletePortForward(context.TODO(), c.site, id)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -87,7 +89,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
allowExisting := d.Get("allow_existing").(bool)
|
||||
|
||||
resp, err := c.c.CreateUser(c.site, req)
|
||||
resp, err := c.c.CreateUser(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
apiErr, ok := err.(*unifi.APIError)
|
||||
if !ok || (apiErr.Message != "api.err.MacUsed" || !allowExisting) {
|
||||
@@ -96,7 +98,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
// mac in use, just absorb it
|
||||
mac := d.Get("mac").(string)
|
||||
existing, err := c.c.GetUserByMAC(c.site, mac)
|
||||
existing, err := c.c.GetUserByMAC(context.TODO(), c.site, mac)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,7 +106,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = existing.ID
|
||||
req.SiteID = existing.SiteID
|
||||
|
||||
resp, err = c.c.UpdateUser(c.site, req)
|
||||
resp, err = c.c.UpdateUser(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -113,7 +115,7 @@ func resourceUserCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
d.SetId(resp.ID)
|
||||
|
||||
if d.Get("blocked").(bool) {
|
||||
err := c.c.BlockUserByMAC(c.site, d.Get("mac").(string))
|
||||
err := c.c.BlockUserByMAC(context.TODO(), c.site, d.Get("mac").(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -163,7 +165,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetUser(c.site, id)
|
||||
resp, err := c.c.GetUser(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -173,7 +175,7 @@ func resourceUserRead(d *schema.ResourceData, meta interface{}) error {
|
||||
}
|
||||
|
||||
// for some reason the IP address is only on this endpoint, so issue another request
|
||||
macResp, err := c.c.GetUserByMAC(c.site, resp.MAC)
|
||||
macResp, err := c.c.GetUserByMAC(context.TODO(), c.site, resp.MAC)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -193,12 +195,12 @@ func resourceUserUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
if d.HasChange("blocked") {
|
||||
mac := d.Get("mac").(string)
|
||||
if d.Get("blocked").(bool) {
|
||||
err := c.c.BlockUserByMAC(c.site, mac)
|
||||
err := c.c.BlockUserByMAC(context.TODO(), c.site, mac)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := c.c.UnblockUserByMAC(c.site, mac)
|
||||
err := c.c.UnblockUserByMAC(context.TODO(), c.site, mac)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -213,7 +215,7 @@ func resourceUserUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdateUser(c.site, req)
|
||||
resp, err := c.c.UpdateUser(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -231,7 +233,7 @@ func resourceUserDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
}
|
||||
|
||||
// lookup MAC instead of trusting state
|
||||
u, err := c.c.GetUser(c.site, id)
|
||||
u, err := c.c.GetUser(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
return nil
|
||||
}
|
||||
@@ -239,6 +241,6 @@ func resourceUserDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.c.DeleteUserByMAC(c.site, u.MAC)
|
||||
err = c.c.DeleteUserByMAC(context.TODO(), c.site, u.MAC)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
)
|
||||
@@ -44,7 +46,7 @@ func resourceUserGroupCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.c.CreateUserGroup(c.site, req)
|
||||
resp, err := c.c.CreateUserGroup(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,7 +77,7 @@ func resourceUserGroupRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetUserGroup(c.site, id)
|
||||
resp, err := c.c.GetUserGroup(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -98,7 +100,7 @@ func resourceUserGroupUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdateUserGroup(c.site, req)
|
||||
resp, err := c.c.UpdateUserGroup(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -111,7 +113,7 @@ func resourceUserGroupDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
err := c.c.DeleteUserGroup(c.site, id)
|
||||
err := c.c.DeleteUserGroup(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"testing"
|
||||
@@ -128,7 +129,7 @@ func TestAccUser_existing_mac_allow(t *testing.T) {
|
||||
PreCheck: func() {
|
||||
preCheck(t)
|
||||
|
||||
_, err := testClient.CreateUser("default", &unifi.User{
|
||||
_, err := testClient.CreateUser(context.Background(), "default", &unifi.User{
|
||||
MAC: testMAC,
|
||||
Name: "tfacc-existing",
|
||||
Note: "tfacc-existing",
|
||||
@@ -140,7 +141,7 @@ func TestAccUser_existing_mac_allow(t *testing.T) {
|
||||
CheckDestroy: func(*terraform.State) error {
|
||||
// TODO: CheckDestroy: ,
|
||||
|
||||
return testClient.DeleteUserByMAC("default", testMAC)
|
||||
return testClient.DeleteUserByMAC(context.Background(), "default", testMAC)
|
||||
},
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
@@ -163,7 +164,7 @@ func TestAccUser_existing_mac_deny(t *testing.T) {
|
||||
PreCheck: func() {
|
||||
preCheck(t)
|
||||
|
||||
_, err := testClient.CreateUser("default", &unifi.User{
|
||||
_, err := testClient.CreateUser(context.Background(), "default", &unifi.User{
|
||||
MAC: testMAC,
|
||||
Name: "tfacc-existing",
|
||||
Note: "tfacc-existing",
|
||||
@@ -175,7 +176,7 @@ func TestAccUser_existing_mac_deny(t *testing.T) {
|
||||
CheckDestroy: func(*terraform.State) error {
|
||||
// TODO: CheckDestroy: ,
|
||||
|
||||
return testClient.DeleteUserByMAC("default", testMAC)
|
||||
return testClient.DeleteUserByMAC(context.Background(), "default", testMAC)
|
||||
},
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
||||
"github.com/paultyng/go-unifi/unifi"
|
||||
@@ -136,7 +138,7 @@ func resourceWLANCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
resp, err := c.c.CreateWLAN(c.site, req)
|
||||
resp, err := c.c.CreateWLAN(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -188,7 +190,7 @@ func resourceWLANRead(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
resp, err := c.c.GetWLAN(c.site, id)
|
||||
resp, err := c.c.GetWLAN(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
d.SetId("")
|
||||
return nil
|
||||
@@ -211,7 +213,7 @@ func resourceWLANUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
req.ID = d.Id()
|
||||
req.SiteID = c.site
|
||||
|
||||
resp, err := c.c.UpdateWLAN(c.site, req)
|
||||
resp, err := c.c.UpdateWLAN(context.TODO(), c.site, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -224,7 +226,7 @@ func resourceWLANDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
||||
id := d.Id()
|
||||
|
||||
err := c.c.DeleteWLAN(c.site, id)
|
||||
err := c.c.DeleteWLAN(context.TODO(), c.site, id)
|
||||
if _, ok := err.(*unifi.NotFoundError); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user