Omit empty NetworkID in account resource (#59)
* Omit empty NetworkID in account * Run `go generate` * Fix tests Co-authored-by: Joshua Spence <josh@joshuaspence.com>
This commit is contained in:
@@ -304,7 +304,8 @@ func main() {
|
||||
switch resource.StructName {
|
||||
case "Account":
|
||||
resource.FieldProcessor = func(name string, f *FieldInfo) error {
|
||||
if name == "IP" {
|
||||
switch name {
|
||||
case "IP", "NetworkID":
|
||||
f.OmitEmpty = true
|
||||
}
|
||||
return nil
|
||||
|
||||
2
unifi/account.generated.go
generated
2
unifi/account.generated.go
generated
@@ -27,7 +27,7 @@ type Account struct {
|
||||
|
||||
IP string `json:"ip,omitempty"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$
|
||||
Name string `json:"name,omitempty"` // ^[^"' ]+$
|
||||
NetworkID string `json:"networkconf_id"`
|
||||
NetworkID string `json:"networkconf_id,omitempty"`
|
||||
TunnelConfigType string `json:"tunnel_config_type,omitempty"` // vpn|802.1x|custom
|
||||
TunnelMediumType int `json:"tunnel_medium_type,omitempty"` // [1-9]|1[0-5]|^$
|
||||
TunnelType int `json:"tunnel_type,omitempty"` // [1-9]|1[0-3]|^$
|
||||
|
||||
@@ -14,11 +14,11 @@ func TestAccountMarshalJSON(t *testing.T) {
|
||||
acc unifi.Account
|
||||
}{
|
||||
"empty strings": {
|
||||
`{"vlan":"","tunnel_type":"","tunnel_medium_type":"","networkconf_id":""}`,
|
||||
`{"vlan":"","tunnel_type":"","tunnel_medium_type":""}`,
|
||||
unifi.Account{},
|
||||
},
|
||||
"response": {
|
||||
`{"vlan":10,"tunnel_type":1,"tunnel_medium_type":1,"networkconf_id":""}`,
|
||||
`{"vlan":10,"tunnel_type":1,"tunnel_medium_type":1}`,
|
||||
unifi.Account{
|
||||
VLAN: 10,
|
||||
TunnelType: 1,
|
||||
|
||||
8
unifi/device.generated.go
generated
8
unifi/device.generated.go
generated
@@ -204,7 +204,7 @@ func (dst *DeviceOutletOverrides) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
|
||||
type DevicePortOverrides struct {
|
||||
AggregateNumPorts int `json:"aggregate_num_ports,omitempty"` // [2-6]
|
||||
AggregateNumPorts int `json:"aggregate_num_ports,omitempty"` // [2-8]
|
||||
Autoneg bool `json:"autoneg,omitempty"`
|
||||
Dot1XCtrl string `json:"dot1x_ctrl,omitempty"` // auto|force_authorized|force_unauthorized|mac_based|multi_host
|
||||
Dot1XIDleTimeout int `json:"dot1x_idle_timeout,omitempty"` // [0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]
|
||||
@@ -292,8 +292,8 @@ func (dst *DevicePortOverrides) UnmarshalJSON(b []byte) error {
|
||||
type DeviceRadioTable struct {
|
||||
AntennaGain int `json:"antenna_gain,omitempty"` // ^-?([0-9]|[1-9][0-9])
|
||||
AntennaID int `json:"antenna_id,omitempty"` // -1|[0-9]
|
||||
BackupChannel string `json:"backup_channel,omitempty"` // [0-9]|[1][0-4]|16|34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196|auto
|
||||
Channel string `json:"channel,omitempty"` // [0-9]|[1][0-4]|4.5|16|34|36|38|40|42|44|46|48|52|56|60|64|100|104|108|112|116|120|124|128|132|136|140|144|149|153|157|161|165|183|184|185|187|188|189|192|196|auto
|
||||
BackupChannel string `json:"backup_channel,omitempty"` // [0-9]|[1][0-4]|4.5|5|16|21|34|36|37|38|40|42|44|46|48|52|53|56|60|64|69|85|100|101|104|108|112|117|116|120|124|128|132|133|136|140|144|149|153|157|161|165|181|183|184|185|187|188|189|192|196|197|213|229|auto
|
||||
Channel string `json:"channel,omitempty"` // [0-9]|[1][0-4]|4.5|5|16|21|34|36|37|38|40|42|44|46|48|52|53|56|60|64|69|85|100|101|104|108|112|117|116|120|124|128|132|133|136|140|144|149|153|157|161|165|181|183|184|185|187|188|189|192|196|197|213|229|auto
|
||||
HardNoiseFloorEnabled bool `json:"hard_noise_floor_enabled,omitempty"`
|
||||
Ht int `json:"ht,omitempty"` // 20|40|80|160|1080|2160
|
||||
LoadbalanceEnabled bool `json:"loadbalance_enabled,omitempty"`
|
||||
@@ -301,7 +301,7 @@ type DeviceRadioTable struct {
|
||||
MinRssi int `json:"min_rssi,omitempty"` // ^-(6[7-9]|[7-8][0-9]|90)$
|
||||
MinRssiEnabled bool `json:"min_rssi_enabled,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Radio string `json:"radio,omitempty"` // ng|na|ad
|
||||
Radio string `json:"radio,omitempty"` // ng|na|ad|6e
|
||||
SensLevel int `json:"sens_level,omitempty"` // ^-([5-8][0-9]|90)$
|
||||
SensLevelEnabled bool `json:"sens_level_enabled,omitempty"`
|
||||
TxPower string `json:"tx_power,omitempty"` // [\d]+|auto
|
||||
|
||||
1
unifi/network.generated.go
generated
1
unifi/network.generated.go
generated
@@ -137,6 +137,7 @@ type Network struct {
|
||||
ReportWANEvent bool `json:"report_wan_event"`
|
||||
RequireMschapv2 bool `json:"require_mschapv2"`
|
||||
RouteDistance int `json:"route_distance,omitempty"` // ^[1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]$|^$
|
||||
TeleportEnabled bool `json:"teleport_enabled"`
|
||||
UpnpLanEnabled bool `json:"upnp_lan_enabled"`
|
||||
UserGroupID string `json:"usergroup_id"`
|
||||
VLAN int `json:"vlan,omitempty"` // [2-9]|[1-9][0-9]{1,2}|[1-3][0-9]{3}|400[0-9]|^$
|
||||
|
||||
87
unifi/setting_teleport.generated.go
generated
Normal file
87
unifi/setting_teleport.generated.go
generated
Normal file
@@ -0,0 +1,87 @@
|
||||
// Code generated from ace.jar fields *.json files
|
||||
// DO NOT EDIT.
|
||||
|
||||
package unifi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// just to fix compile issues with the import
|
||||
var (
|
||||
_ context.Context
|
||||
_ fmt.Formatter
|
||||
_ json.Marshaler
|
||||
)
|
||||
|
||||
type SettingTeleport struct {
|
||||
ID string `json:"_id,omitempty"`
|
||||
SiteID string `json:"site_id,omitempty"`
|
||||
|
||||
Hidden bool `json:"attr_hidden,omitempty"`
|
||||
HiddenID string `json:"attr_hidden_id,omitempty"`
|
||||
NoDelete bool `json:"attr_no_delete,omitempty"`
|
||||
NoEdit bool `json:"attr_no_edit,omitempty"`
|
||||
|
||||
Key string `json:"key"`
|
||||
|
||||
SubnetCidr string `json:"subnet_cidr"` // ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([8-9]|[1-2][0-9]|3[0-2])$|^$
|
||||
}
|
||||
|
||||
func (dst *SettingTeleport) UnmarshalJSON(b []byte) error {
|
||||
type Alias SettingTeleport
|
||||
aux := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(dst),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(b, &aux)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to unmarshal alias: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) getSettingTeleport(ctx context.Context, site string) (*SettingTeleport, error) {
|
||||
var respBody struct {
|
||||
Meta meta `json:"meta"`
|
||||
Data []SettingTeleport `json:"data"`
|
||||
}
|
||||
|
||||
err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/teleport", site), nil, &respBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(respBody.Data) != 1 {
|
||||
return nil, &NotFoundError{}
|
||||
}
|
||||
|
||||
d := respBody.Data[0]
|
||||
return &d, nil
|
||||
}
|
||||
|
||||
func (c *Client) updateSettingTeleport(ctx context.Context, site string, d *SettingTeleport) (*SettingTeleport, error) {
|
||||
var respBody struct {
|
||||
Meta meta `json:"meta"`
|
||||
Data []SettingTeleport `json:"data"`
|
||||
}
|
||||
|
||||
d.Key = "teleport"
|
||||
err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/teleport", site), d, &respBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(respBody.Data) != 1 {
|
||||
return nil, &NotFoundError{}
|
||||
}
|
||||
|
||||
new := respBody.Data[0]
|
||||
|
||||
return &new, nil
|
||||
}
|
||||
2
unifi/version.generated.go
generated
2
unifi/version.generated.go
generated
@@ -2,4 +2,4 @@
|
||||
|
||||
package unifi
|
||||
|
||||
const UnifiVersion = "6.4.54"
|
||||
const UnifiVersion = "6.5.55"
|
||||
|
||||
4
unifi/wlan.generated.go
generated
4
unifi/wlan.generated.go
generated
@@ -34,6 +34,7 @@ type WLAN struct {
|
||||
CountryBeacon bool `json:"country_beacon"`
|
||||
DPIEnabled bool `json:"dpi_enabled"`
|
||||
DPIgroupID string `json:"dpigroup_id"` // [\d\w]+|^$
|
||||
DTIM6E int `json:"dtim_6e,omitempty"` // ^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$
|
||||
DTIMMode string `json:"dtim_mode,omitempty"` // default|custom
|
||||
DTIMNa int `json:"dtim_na,omitempty"` // ^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$
|
||||
DTIMNg int `json:"dtim_ng,omitempty"` // ^([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^$
|
||||
@@ -95,6 +96,7 @@ type WLAN struct {
|
||||
VLANEnabled bool `json:"vlan_enabled"`
|
||||
WEPIDX int `json:"wep_idx,omitempty"` // [1-4]
|
||||
WLANBand string `json:"wlan_band,omitempty"` // 2g|5g|both
|
||||
WLANBands []string `json:"wlan_bands,omitempty"` // 2g|5g|6g
|
||||
WLANGroupID string `json:"wlangroup_id"`
|
||||
WPA3Enhanced192 bool `json:"wpa3_enhanced_192"`
|
||||
WPA3FastRoaming bool `json:"wpa3_fast_roaming"`
|
||||
@@ -111,6 +113,7 @@ type WLAN struct {
|
||||
func (dst *WLAN) UnmarshalJSON(b []byte) error {
|
||||
type Alias WLAN
|
||||
aux := &struct {
|
||||
DTIM6E emptyStringInt `json:"dtim_6e"`
|
||||
DTIMNa emptyStringInt `json:"dtim_na"`
|
||||
DTIMNg emptyStringInt `json:"dtim_ng"`
|
||||
GroupRekey emptyStringInt `json:"group_rekey"`
|
||||
@@ -132,6 +135,7 @@ func (dst *WLAN) UnmarshalJSON(b []byte) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to unmarshal alias: %w", err)
|
||||
}
|
||||
dst.DTIM6E = int(aux.DTIM6E)
|
||||
dst.DTIMNa = int(aux.DTIMNa)
|
||||
dst.DTIMNg = int(aux.DTIMNg)
|
||||
dst.GroupRekey = int(aux.GroupRekey)
|
||||
|
||||
Reference in New Issue
Block a user