From 6203ee9620cde49552acc228de6b4e338c908ae3 Mon Sep 17 00:00:00 2001 From: James Stephenson Date: Wed, 7 Oct 2020 08:58:59 -0400 Subject: [PATCH] Renaming `PortConf` to `PortProfile`; cleanup `Device` API func names --- fields/main.go | 2 ++ unifi/device.generated.go | 2 +- unifi/device.go | 4 +-- unifi/port_conf.go | 25 ----------------- ...generated.go => port_profile.generated.go} | 28 +++++++++---------- unifi/port_profile.go | 25 +++++++++++++++++ 6 files changed, 44 insertions(+), 42 deletions(-) delete mode 100644 unifi/port_conf.go rename unifi/{port_conf.generated.go => port_profile.generated.go} (86%) create mode 100644 unifi/port_profile.go diff --git a/fields/main.go b/fields/main.go index 016cfd6..f02d4be 100644 --- a/fields/main.go +++ b/fields/main.go @@ -55,6 +55,7 @@ var fieldReps = []replacement{ {"Networkgroup", "NetworkGroup"}, {"Pd", "PD"}, {"Pmf", "PMF"}, + {"Portconf", "PortProfile"}, {"Qos", "QOS"}, {"Radiusprofile", "RADIUSProfile"}, {"Radius", "RADIUS"}, @@ -80,6 +81,7 @@ var fileReps = []replacement{ {"Dhcp", "DHCP"}, {"Wlan", "WLAN"}, {"NetworkConf", "Network"}, + {"PortConf", "PortProfile"}, {"RadiusProfile", "RADIUSProfile"}, } diff --git a/unifi/device.generated.go b/unifi/device.generated.go index 69b7557..cb6ff30 100644 --- a/unifi/device.generated.go +++ b/unifi/device.generated.go @@ -120,9 +120,9 @@ type DevicePortOverrides struct { OpMode string `json:"op_mode,omitempty"` // switch|mirror|aggregate PoeMode string `json:"poe_mode,omitempty"` // auto|pasv24|passthrough|off PortIDX int `json:"port_idx,omitempty"` // [1-9]|[1-4][0-9]|5[0-2] + PortProfileID string `json:"portconf_id,omitempty"` // [\d\w]+ PortSecurityEnabled bool `json:"port_security_enabled,omitempty"` PortSecurityMACAddress []string `json:"port_security_mac_address,omitempty"` // ^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$ - PortconfID string `json:"portconf_id,omitempty"` // [\d\w]+ PriorityQueue1Level int `json:"priority_queue1_level,omitempty"` // [0-9]|[1-9][0-9]|100 PriorityQueue2Level int `json:"priority_queue2_level,omitempty"` // [0-9]|[1-9][0-9]|100 PriorityQueue3Level int `json:"priority_queue3_level,omitempty"` // [0-9]|[1-9][0-9]|100 diff --git a/unifi/device.go b/unifi/device.go index 177d862..4cae075 100644 --- a/unifi/device.go +++ b/unifi/device.go @@ -8,7 +8,7 @@ func (c *Client) ListDevice(ctx context.Context, site string) ([]Device, error) return c.listDevice(ctx, site) } -func (c *Client) GetDevice(ctx context.Context, site, mac string) (*Device, error) { +func (c *Client) GetDeviceByMAC(ctx context.Context, site, mac string) (*Device, error) { return c.getDevice(ctx, site, mac) } @@ -24,7 +24,7 @@ func (c *Client) UpdateDevice(ctx context.Context, site string, d *Device) (*Dev return c.updateDevice(ctx, site, d) } -func (c *Client) GetDeviceById(ctx context.Context, site, id string) (*Device, error) { +func (c *Client) GetDevice(ctx context.Context, site, id string) (*Device, error) { devices, err := c.ListDevice(ctx, site) if err != nil { diff --git a/unifi/port_conf.go b/unifi/port_conf.go deleted file mode 100644 index 3adeb1b..0000000 --- a/unifi/port_conf.go +++ /dev/null @@ -1,25 +0,0 @@ -package unifi - -import ( - "context" -) - -func (c *Client) ListPortConf(ctx context.Context, site string) ([]PortConf, error) { - return c.listPortConf(ctx, site) -} - -func (c *Client) GetPortConf(ctx context.Context, site, id string) (*PortConf, error) { - return c.getPortConf(ctx, site, id) -} - -func (c *Client) DeletePortConf(ctx context.Context, site, id string) error { - return c.deletePortConf(ctx, site, id) -} - -func (c *Client) CreatePortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { - return c.createPortConf(ctx, site, d) -} - -func (c *Client) UpdatePortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { - return c.updatePortConf(ctx, site, d) -} diff --git a/unifi/port_conf.generated.go b/unifi/port_profile.generated.go similarity index 86% rename from unifi/port_conf.generated.go rename to unifi/port_profile.generated.go index ad6f78c..514d123 100644 --- a/unifi/port_conf.generated.go +++ b/unifi/port_profile.generated.go @@ -14,7 +14,7 @@ var ( _ context.Context ) -type PortConf struct { +type PortProfile struct { ID string `json:"_id,omitempty"` SiteID string `json:"site_id,omitempty"` @@ -59,10 +59,10 @@ type PortConf struct { VoiceNetworkID string `json:"voice_networkconf_id"` } -func (c *Client) listPortConf(ctx context.Context, site string) ([]PortConf, error) { +func (c *Client) listPortProfile(ctx context.Context, site string) ([]PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` - Data []PortConf `json:"data"` + Meta meta `json:"meta"` + Data []PortProfile `json:"data"` } err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf", site), nil, &respBody) @@ -73,10 +73,10 @@ func (c *Client) listPortConf(ctx context.Context, site string) ([]PortConf, err return respBody.Data, nil } -func (c *Client) getPortConf(ctx context.Context, site, id string) (*PortConf, error) { +func (c *Client) getPortProfile(ctx context.Context, site, id string) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` - Data []PortConf `json:"data"` + Meta meta `json:"meta"` + Data []PortProfile `json:"data"` } err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), nil, &respBody) @@ -92,7 +92,7 @@ func (c *Client) getPortConf(ctx context.Context, site, id string) (*PortConf, e return &d, nil } -func (c *Client) deletePortConf(ctx context.Context, site, id string) error { +func (c *Client) deletePortProfile(ctx context.Context, site, id string) error { err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), struct{}{}, nil) if err != nil { return err @@ -100,10 +100,10 @@ func (c *Client) deletePortConf(ctx context.Context, site, id string) error { return nil } -func (c *Client) createPortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { +func (c *Client) createPortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` - Data []PortConf `json:"data"` + Meta meta `json:"meta"` + Data []PortProfile `json:"data"` } err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portconf", site), d, &respBody) @@ -120,10 +120,10 @@ func (c *Client) createPortConf(ctx context.Context, site string, d *PortConf) ( return &new, nil } -func (c *Client) updatePortConf(ctx context.Context, site string, d *PortConf) (*PortConf, error) { +func (c *Client) updatePortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` - Data []PortConf `json:"data"` + Meta meta `json:"meta"` + Data []PortProfile `json:"data"` } err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portconf/%s", site, d.ID), d, &respBody) diff --git a/unifi/port_profile.go b/unifi/port_profile.go new file mode 100644 index 0000000..fc68243 --- /dev/null +++ b/unifi/port_profile.go @@ -0,0 +1,25 @@ +package unifi + +import ( + "context" +) + +func (c *Client) ListPortProfile(ctx context.Context, site string) ([]PortProfile, error) { + return c.listPortProfile(ctx, site) +} + +func (c *Client) GetPortProfile(ctx context.Context, site, id string) (*PortProfile, error) { + return c.getPortProfile(ctx, site, id) +} + +func (c *Client) DeletePortProfile(ctx context.Context, site, id string) error { + return c.deletePortProfile(ctx, site, id) +} + +func (c *Client) CreatePortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { + return c.createPortProfile(ctx, site, d) +} + +func (c *Client) UpdatePortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { + return c.updatePortProfile(ctx, site, d) +}