Git Product home page Git Product logo

go-unifi's Introduction

Unifi Go SDK GoDoc

This was written primarily for use in my Terraform provider for Unifi.

Versioning

Many of the naming adjustments are breaking changes, but to simplify things, treating naming errors as minor changes for the 1.0.0 version (probably should have just started at 0.1.0).

Note on Code Generation

The data models and basic REST methods are "generated" from JSON files in the JAR that show all fields and the associated regex/validation information.

To regenerate the code, you can bump the Unifi Controller version number in [unifi/gen.go] and run go generate inside the unifi directory.

This code generation is kind of gross, I wanted to switch to using the java classes in the jar like scala2go but the jar is obfuscated and I couldn't find a way to extract that information from anywhere else. Maybe it exists somewhere in the web UI, but I was unable to find it in there in a way that was extractable in a practical way.

Still planning to dig through the bits some more later on.

go-unifi's People

Contributors

bullshit avatar chrishas35 avatar ddollar avatar dependabot[bot] avatar github-actions[bot] avatar jalfresi avatar james-stephenson avatar jlosito avatar joshuaspence avatar kurtmc avatar lkubb avatar maienm avatar patricol avatar paultyng avatar solarmicrobe avatar t4cc0re avatar yoyostile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-unifi's Issues

Simple examples?

Nice work! Before I dive deep into source reading, is there a page with some simple examples, say how to change the port PoE power mode, or do the auth plumbing?

I'd love to add some resources and functions to https://github.com/purpleidea/mgmt/ for your code. In particular, I'd love to know if there is a non-polling way (events) to get an event when the state of any of the properties changes.

Thanks!

Godoc annotations

I was wondering if you mind as the maintainer if one can submit some godoc comments for this package?

I personally make use of this package and would like to see some annotations when reading the docs.

Inconsistent `int` typing on `Network`

As uncovered in paultyng/terraform-provider-unifi#89 when executing GetNetwork on a WAN network without a VLAN tag, unmarshalling the JSON fails.

json: cannot unmarshal string into Go struct field .wan_vlan of type int

Looking at the JSON from the API, it is clear why: (formatted for readability and some values removed)

{
  "meta":{
    "rc":"ok"
  },
  "data":[
    {
      "_id":"5b69042b78118a0f722cb8b2",
      "site_id":"5b69038878118a0f722cb893",
      "purpose":"wan",
      "name":"WAN",
      "wan_type":"dhcp",
      "wan_type_v6":"dhcpv6",
      "wan_egress_qos":"",
      "wan_dhcpv6_pd_size":58,
      "wan_smartq_enabled":false,
      "wan_vlan_enabled":false,
      "wan_dhcp_options":[ ],
      "wan_dns1":"1.1.1.1",
      "wan_dns2":"1.0.0.1",
      "wan_vlan":""
    }
  ]
}

wan_vlan is expected to be an int, but is a string.

the Network.UnmarshalJSON function already handles some cases via a custom emptyStringInt type, which handles this gracefully.

I propose to use this emptyStringInt type as an override for every int field of the Network struct.

Pull request incoming.

cannot unmarshal string because lte_ext_ant and lte_poe are not boolean

First of all, thanks for your hard work on the provider! I'm looking forward to using it.

My first try with it (importing a switch) sadly failed because Ubiquiti decided "enabled"/"disabled" are booleanish enough. This probably affects not as many people since it is tied to the LTE failover products.

Error: unable to decode body: GET s/default/stat/device unable to unmarshal alias: json: cannot unmarshal string into Go struct field .lte_ext_ant of type bool

The relevant part of the affected response:

   "lte_ext_ant": "disabled",
   "lte_poe": "disabled",
   "lte_failover_mode": "failover",
   "lte_data_warning_enabled": true,
   "lte_data_limit_enabled": true,
   "lte_roaming_allowed": true,

The definition in Device.json:

    "lte_ext_ant": "true|false",
    "lte_poe": "true|false",

I might submit a PR if I figure out how to do the override properly.

NotFoundError when update returns no data objects

When calling UpdateNetwork, I occasionally get a response containing no data elements:

HTTP/1.1 200
...
{
 "meta": {
  "rc": "ok"
 },
 "data": []
}

This results in a &NotFoundError{} being returned at https://github.com/paultyng/go-unifi/blob/main/unifi/network.generated.go#L392.

I suspect what's happening is that my change ends up being a no-op change from the controller's perspective, so it returns an empty data element. In Terraform land, this results in my apply failing even though it did actually apply "correctly". What should happen here? The implied behavior of the update methods seems to be to return a new copy of the object passed, presumably with any added fields from the controller populated or changed. But it doesn't seem like we can actually rely on that behavior. Should the function return an empty &Network{} instance in this case? nil?

Is there any documentation collecting a description of apparent behavior and assumptions like this?

This is potentially one of many bugs/changes I might want to start hacking on. Is the right thing to do to start opening individual issues, pull requests, or do you have a preference for accepting contributions?

setAPIUrlStyle defaults to old api style

UDM Firmware: 1.8.6
Controller Version: 6.0.43

Currently failing terraform plan using provider 0.19.2 with 401 Unauthorized.

setAPIUrlStyle sets the new api style only for 200 responses. The api style check will never set the new api paths for controller versions 6.x.x as the code is effectively unreachable. See below...

	if resp.StatusCode == http.StatusOk {
		// the new API returns a 200 for a / request
		c.apiPath = apiPathNew
		c.loginPath = loginPathNew
		c.statusPath = statusPathNew
		return nil
	}

Add support for traffic management

Currently go-unifi (and terraform downstream) cannot manage traffic management

Endpoint is api/site/default/trafficrules and an example GET

[
  {
    "_id": "6341da70ae89fe09e5458a22",
    "action": "BLOCK",
    "app_category_ids": [],
    "app_ids": [],
    "bandwidth_limit": {
      "download_limit_kbps": 1024,
      "enabled": false,
      "upload_limit_kbps": 1024
    },
    "description": "Traffic Rule",
    "domains": [
      {
        "domain": "somedomain.com",
        "port_ranges": [],
        "ports": []
      }
    ],
    "enabled": false,
    "ip_addresses": [],
    "ip_ranges": [],
    "matching_target": "DOMAIN",
    "network_ids": [],
    "regions": [],
    "schedule": {
      "date_end": "2022-10-15",
      "date_start": "2022-10-08",
      "mode": "ALWAYS",
      "repeat_on_days": [],
      "time_all_day": false,
      "time_range_end": "12:00",
      "time_range_start": "09:00"
    },
    "target_devices": [
      {
        "client_mac": "78:c8:81:cd:dd:6d",
        "type": "CLIENT"
      }
    ]
  }
]

Add support for management via cloud keys

Did some initial investigation on this, poked around with MQTT/WebRTC packages available in Go.

The AWS IoT support in the Go SDK does not handle websockets, but you can manually set one up. The AWS SDK presigning adds an expiration I think which messes it up, so you need to create a presign without an expiration: https://gist.github.com/paultyng/d9d3b900b5524d133df2be058148c5c0#file-aws_presign-go

The WebRTC m=application 9 UDP/DTLS/SCTP webrtc-datachannel media does not yet seem to be supported in pion/webrtc (specifically the UDP portion). Thats at least my working theory for why this is not working. The above is the media description in the offer/answer in the browser.

Too many attributes being sent with Create and Update operations

Presently the client serializes all attributes it knows about when sending Create and Update requests to the controller. By contrast, the official web UI only sends a subset of attributes that appear relevant. When retrieving resources with the Get operation, some attributes that the controller doesn't think we should care about get omitted, and others that we've set previously (that the controller never expected to see) get returned. Because we set far more attributes than the web UI sets, this results in two classes of bugs:

  1. There appears to be perpetual differences between local state and what's stored on the controller, because we are trying to set an attribute that the controller omits in its response. This results in Terraform diffs that never converge.
  2. When attributes that the controller isn't expecting are later made available to the web UI client, this causes the web UI to behave incorrectly. For instance, a network configured as WAN will show "LAN" on the network list. There may be more serious bugs lurking.

Acknowledging that this is a poorly-behaved API service (it's not exactly documented or supported), it's still an issue that needs a solution. Has anyone given this any thought?

It seems like there needs to be a few decisions:

  1. Do we try to fix this?
  2. How should we go about suppressing fields? How do we figure out what to suppress?
  3. Knowing the best plan for (2), do we still think this is a tractable problem?

I suggest:

  1. Yes
  2. Making requests, cataloging behavior, and hand-crafting a set of conditions that need to be true for a list of fields to exist in the request (and contribute to a diff), along with whether fields are required, and what their defaults are.
  3. I don't know.

For reference, here are some JSON blobs (sorted fields):

Network

Creating a WAN in the web UI:

{
  "name": "LTE",
  "purpose": "wan",
  "report_wan_event": true,
  "wan_dhcp_options": [],
  "wan_egress_qos": "",
  "wan_ip_aliases": [],
  "wan_load_balance_type": "failover-only",
  "wan_load_balance_weight": 50,
  "wan_networkgroup": "WAN2",
  "wan_type": "dhcp",
  "wan_type_v6": "disabled"
}

Retrieving this object back from the controller adds an _id and site attributes.

Creating a LAN in the web UI:

{
  "dhcp_relay_enabled": false,
  "dhcpd_dns_enabled": false,
  "dhcpd_enabled": true,
  "dhcpd_gateway_enabled": false,
  "dhcpd_leasetime": 86400,
  "dhcpd_start": "10.0.0.6",
  "dhcpd_stop": "10.0.0.254",
  "dhcpd_time_offset_enabled": false,
  "enabled": true,
  "gateway_type": "default",
  "ip_subnet": "10.0.0.1/24",
  "ipv6_interface_type": "none",
  "ipv6_pd_start": "::2",
  "ipv6_pd_stop": "::7d1",
  "is_nat": true,
  "name": "Test",
  "nat_outbound_ip_addresses": [],
  "networkgroup": "LAN",
  "purpose": "corporate",
  "vlan": "22",
  "vlan_enabled": true
}

Note the entirely different field sets, such as networkgroup.

Switch Port Profile

Separately, here's a GET of an existing switch port profile:

  {
   "_id": "...omitted...",
   "site_id": "...omitted...",
   "name": "IoT",
   "forward": "native",
   "isolation": false,
   "native_networkconf_id": "...omitted...",
   "attr_no_edit": true
  }

Here's the Terraform config:

resource "unifi_port_profile" "iot" {
  name                  = "IoT"
  native_networkconf_id = unifi_network.iot.id
}

But it sees this diff (with my commentary):

  ~ resource "unifi_port_profile" "iot" {
      ~ autoneg                        = false -> true  // the web UI says "link speed" = "Autonegotiate"
      + dot1x_ctrl                     = "force_authorized" // the web UI says "802.1X Control" = "Force authorized"
      ~ dot1x_idle_timeout             = 0 -> 300
        id                             = "...omitted..."
      ~ lldpmed_enabled                = false -> true // Enabled in the web UI
        name                           = "IoT"
      + op_mode                        = "switch"
      ~ stp_port_mode                  = false -> true // Enabled in the web UI
        # (25 unchanged attributes hidden)
    }

And here's what it sends to the controller:

{
 "_id": "5d6f172bf25e119aa7e3005e",
 "site_id": "default",
 "autoneg": true,
 "dot1x_ctrl": "force_authorized",
 "dot1x_idle_timeout": 300,
 "egress_rate_limit_kbps_enabled": false,
 "forward": "native",
 "full_duplex": false,
 "isolation": false,
 "lldpmed_enabled": true,
 "lldpmed_notify_enabled": false,
 "native_networkconf_id": "5d6f172bf25e119aa7e3005d",
 "name": "IoT",
 "op_mode": "switch",
 "port_security_enabled": false,
 "stormctrl_bcast_enabled": false,
 "stormctrl_mcast_enabled": false,
 "stormctrl_ucast_enabled": false,
 "stp_port_mode": true,
 "voice_networkconf_id": ""
}

(This particular update gets a 400 api.err.NoEdit but that's another issue.)

Login fails for UDMP (Unifi OS)

The UDMP is my first experience with a cloud key device as opposed to a standalone controller, so it's possible any CK controller may deal with this. Here's what I'm able to gather so far from the browser network calls:

When presented with the login page, the auth end-point is https://unifi/api/auth/login.

Once logged into the "device" home page, you click on Network to go do what is the typical controller view. That UI makes calls to API where the base URL is: https://unifi/proxy/network/api/.

So when I give the Terraform provider an api_url of "https://unifi/proxy/network/api/" it attempts to login at https://unifi/proxy/proxy/network/api/login which shows a return of 400 Bad Request.

Not entirely sure best way to move this forward, or the exact similarities between UDMP and other CK deployments. I have both a plain controller and the UDMP to compare to, but not a CK. Happy to provide any additional testing/troubleshooting.

TF import network fails "json: cannot unmarshal string into Go struct field .data of type int"

I'm running a slightly older version of the controller, so potentially some of the JSON responses are different than what is expected. Other imports have been succesful. Here's the TF_LOG trace output showing the response I get:

2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: -----------------------------------------------------
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: 2020/02/09 17:12:05 [DEBUG] Unifi API Request Details:
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: ---[ REQUEST ]---------------------------------------
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: GET /api/s/default/rest/networkconf/569e7a29e4b005dfeedb9ff6 HTTP/1.1
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: Host: unifi:8443
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: User-Agent: terraform-provider-unifi/0.1
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: Cookie: unifises=<redacted>; csrf_token=<redacted>
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: Accept-Encoding: gzip
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi:
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi:
2020-02-09T17:12:05.389-0600 [DEBUG] plugin.terraform-provider-unifi: -----------------------------------------------------
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: 2020/02/09 17:12:05 [DEBUG] Unifi API Response Details:
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: ---[ RESPONSE ]--------------------------------------
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: HTTP/1.1 200
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Transfer-Encoding: chunked
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Access-Control-Allow-Credentials: true
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Access-Control-Expose-Headers: Access-Control-Allow-Origin,Access-Control-Allow-Credentials
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Cache-Control: private
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Content-Type: application/json;charset=UTF-8
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Date: Sun, 09 Feb 2020 23:11:23 GMT
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Expires: Thu, 01 Jan 1970 00:00:00 GMT
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: Vary: Origin,Accept-Encoding
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: X-Frame-Options: DENY
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: 403
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: {
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:  "meta": {
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:   "rc": "ok"
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:  },
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:  "data": [
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:   {
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "_id": "569e7a29e4b005dfeedb9ff6",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "attr_no_delete": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "attr_hidden_id": "LAN",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "name": "LAN",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "site_id": "569e7a24e4b005dfeedb9ff1",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "vlan_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "purpose": "corporate",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ip_subnet": "192.168.0.1/24",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "is_nat": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_enabled": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_start": "192.168.0.200",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_stop": "192.168.0.254",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "networkgroup": "LAN",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "enabled": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_dns_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_wins_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_leasetime": "3600",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpguard_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_ip_1": "",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_dns_1": "192.168.0.10",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_dns_2": "",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "domain_name": "<redacted>",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_gateway_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpd_time_offset_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_interface_type": "pd",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcp_relay_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "lte_lan_enabled": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_pd_interface": "wan",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_ra_enabled": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_ra_priority": "high",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_ra_valid_lifetime": 86400,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_ra_preferred_lifetime": 14400,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpdv6_enabled": false,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpdv6_leasetime": 86400,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpdv6_dns_auto": true,
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_pd_start": "::2",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "ipv6_pd_stop": "::7d1",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpdv6_dns_1": "<redacted>",
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:    "dhcpdv6_dns_2": "<redacted>"
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:   }
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:  ]
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: }
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: 0
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi:
2020-02-09T17:12:05.456-0600 [DEBUG] plugin.terraform-provider-unifi: -----------------------------------------------------
2020/02/09 17:12:05 [ERROR] <root>: eval: *terraform.EvalRefresh, err: json: cannot unmarshal string into Go struct field .data of type int
2020/02/09 17:12:05 [ERROR] <root>: eval: *terraform.EvalSequence, err: json: cannot unmarshal string into Go struct field .data of type int
2020/02/09 17:12:05 [TRACE] [walkImport] Exiting eval tree: import unifi_network.test result
2020/02/09 17:12:05 [TRACE] vertex "import unifi_network.test result": visit complete
2020/02/09 17:12:05 [TRACE] vertex "unifi_network.test (import id \"569e7a29e4b005dfeedb9ff6\")": dynamic subgraph encountered errors
2020/02/09 17:12:05 [TRACE] vertex "unifi_network.test (import id \"569e7a29e4b005dfeedb9ff6\")": visit complete
2020/02/09 17:12:05 [TRACE] dag/walk: upstream of "provider.unifi (close)" errored, so skipping

Status broken with UDMP on latest firmware (1.8.5)

I have a UDMP running firmware 1.8.5 which includes network controller 6.0.43. When I attempt to use the terraform provider, I receive a 401 trying to access the /proxy/network/status endpoint.

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

unifi_user.truenas: Creating...

Error:   (401 Unauthorized) for GET https://unifi.home.xxxxxxxx.net/proxy/network/status

When I attempt to navigate to https://unifi.home.xxxxxxxx.net/api/auth/login, I get the message "Method Not Allowed". From this forum thread, it looks like the login endpoint has changed back to /api/login.

Supporting 6.X.X versions of Unifi Network Controller

I am currently looking into updating https://github.com/paultyng/terraform-provider-unifi to support all the features of Unifi Network that I require, and I am also using Unifi Network 6.0.23 and I have noticed that the API is different to the 5.X.X versions.

I am keen to add support for 6.X.X to this library but I am unsure what the best strategy for that would be. Should I add some sort of version field to the client and use that to decide how to interact with the API?

The different versions of the controller have different fields for the API calls, so it might become a bit of a mess to add two definitions of some of the models depending on the version? E.g. having type WLAN_v5 struct and type WLAN_v6 struct

Please let me know how you would like to see it done

Add support for clients

I like to tag some clients with metadata like a friendly name, fixed IP and vlan

It would be nice to support that in terraform to easily target clients Mac similar to devices

Panic: Malformed Version

I'm still relatively new to Go, so apologies if I'm completely off base.

I haven't run a terraform plan since before my UDM got upgraded to 6.0, so there are likely many things that changed in this time.

Versions

  • Terraform: v0.13.0
  • paultyng/unifi: v0.20.0
  • Unifi Controller: 6.0.43
  • Unifi Controller Build: atag_6.0.43_14348
  • UDM Firmware: 1.8.6.2969

What I'm seeing is in the terraform trace appears to be:

  1. It logs in with a POST to the /api/auth/login endpoint
  2. This responds back with 200 OK as well as a json response for the details for my account
  3. Performs a GET to /proxy/network/status
  4. Receives 200 OK response with json
{
 "meta": {
  "rc": "ok",
  "uuid": "<redacted>"
 },
 "data": []
}

Followed by

2021-02-24T22:28:45.611-0800 [INFO]  plugin.terraform-provider-unifi_v0.20.0: 2021/02/24 22:28:45 [TRACE] Unifi controller version: "": timestamp=2021-02-24T22:28:45.610-0800
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0:
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
Error: rpc error: code = Unavailable desc = transport is closing
panic: Malformed version:
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0:
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: goroutine 56 [running]:
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/go-version.Must(...)
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/[email protected]/version.go:104
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/paultyng/terraform-provider-unifi/internal/provider.(*client).ControllerVersion(0xc000360000, 0x0)
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/paultyng/terraform-provider-unifi/internal/provider/provider.go:197 +0x95
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/paultyng/terraform-provider-unifi/internal/provider.dataAPGroupRead(0xc00028ee00, 0x17ee1a0, 0xc000360000, 0x1e6d730, 0x192a9c0)
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/paultyng/terraform-provider-unifi/internal/provider/data_ap_group.go:40 +0x5b
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc000122780, 0x19e9b00, 0xc0002feb00, 0xc00028ee00, 0x17ee1a0, 0xc000360000, 0x0, 0x0, 0x0)
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:290 +0x88
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ReadDataApply(0xc000122780, 0x19e9b00, 0xc0002feb00, 0xc00047ec00, 0x17ee1a0, 0xc000360000, 0xc000360000, 0xc00047ec00, 0x0, 0x0)
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:498 +0xfd
2021-02-24T22:28:45.613-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadDataSource(0xc0003c1200, 0x19e9b00, 0xc0002feb00, 0xc00047eb20, 0xc0002feb00, 0x1879cc0, 0x18a87a0)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1105 +0x4d4
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ReadDataSource(0xc0003c0700, 0x19e9b00, 0xc0002feb00, 0xc000476870, 0xc0003c0700, 0xc000486ba0, 0x106a5e7)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/[email protected]/tfprotov5/server/server.go:247 +0xe5
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadDataSource_Handler(0x18a87a0, 0xc0003c0700, 0x19e9bc0, 0xc00058a600, 0xc0000b3da0, 0x0, 0x19e9bc0, 0xc00058a600, 0xc0000b7020, 0x2a)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:416 +0x214
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00019c8c0, 0x19f1c80, 0xc0002a2180, 0xc0001c2800, 0xc000202570, 0x1e2f8f0, 0x0, 0x0, 0x0)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	google.golang.org/[email protected]/server.go:1217 +0x522
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: google.golang.org/grpc.(*Server).handleStream(0xc00019c8c0, 0x19f1c80, 0xc0002a2180, 0xc0001c2800, 0x0)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	google.golang.org/[email protected]/server.go:1540 +0xd05
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000036210, 0xc00019c8c0, 0x19f1c80, 0xc0002a2180, 0xc0001c2800)
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	google.golang.org/[email protected]/server.go:878 +0xa5
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: created by google.golang.org/grpc.(*Server).serveStreams.func1
2021-02-24T22:28:45.614-0800 [DEBUG] plugin.terraform-provider-unifi_v0.20.0: 	google.golang.org/[email protected]/server.go:876 +0x1fd
2021-02-24T22:28:45.616-0800 [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/paultyng/unifi/0.20.0/darwin_amd64/terraform-provider-unifi_v0.20.0 pid=77081 error="exit status 2"
2021-02-24T22:28:45.616-0800 [WARN]  plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing"
2021/02/24 22:28:45 [ERROR] eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2021/02/24 22:28:45 [ERROR] eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2021/02/24 22:28:45 [ERROR] eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing

Looking at the struct that I'm assuming is used to define the schema of the json response, it appears that it's expecting a server_version property in the meta object, but no such thing appears to be in the response I'm getting.

From the above it does seem to confirm that the version is empty on the line following the json response.

When we try to compare this version to controllerV6 in dataAPGroupRead it appears to panic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.