Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devices): add missing devices fields #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions v2/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,57 @@ func (t *Time) UnmarshalJSON(data []byte) error {
return nil
}

type DeviceClientConnectivityClientSupports struct {
HairPinning bool `json:"hairPinning"`
IPv6 bool `json:"ipv6"`
PCP bool `json:"pcp"`
PMP bool `json:"pmp"`
UDP bool `json:"udp"`
UPnP bool `json:"upnp"`
}

type DeviceClientConnectivityLocationLatency struct {
Preferred bool `json:"preferred"`
LatencyMs float64 `json:"latencyMs"`
}

type DeviceClientConnectivity struct {
Endpoints []string `json:"endpoints"`
MappingVariesByDestIP bool `json:"mappingVariesByDestIP"`
Latency map[string]DeviceClientConnectivityLocationLatency `json:"latency"`
ClientSupports DeviceClientConnectivityClientSupports `json:"clientSupports"`
}

type DevicePostureIdentity struct {
Disabled bool `json:"disabled"`
SerialNumbers []string `json:"serialNumbers"`
}

type Device struct {
Addresses []string `json:"addresses"`
Name string `json:"name"`
ID string `json:"id"`
Authorized bool `json:"authorized"`
User string `json:"user"`
Tags []string `json:"tags"`
KeyExpiryDisabled bool `json:"keyExpiryDisabled"`
BlocksIncomingConnections bool `json:"blocksIncomingConnections"`
ClientVersion string `json:"clientVersion"`
Created Time `json:"created"`
Expires Time `json:"expires"`
Hostname string `json:"hostname"`
IsExternal bool `json:"isExternal"`
LastSeen Time `json:"lastSeen"`
MachineKey string `json:"machineKey"`
NodeKey string `json:"nodeKey"`
OS string `json:"os"`
UpdateAvailable bool `json:"updateAvailable"`
Addresses []string `json:"addresses"`
Name string `json:"name"`
ID string `json:"id"`
Authorized bool `json:"authorized"`
User string `json:"user"`
Tags []string `json:"tags"`
KeyExpiryDisabled bool `json:"keyExpiryDisabled"`
BlocksIncomingConnections bool `json:"blocksIncomingConnections"`
ClientVersion string `json:"clientVersion"`
Created Time `json:"created"`
Expires Time `json:"expires"`
Hostname string `json:"hostname"`
IsExternal bool `json:"isExternal"`
LastSeen Time `json:"lastSeen"`
MachineKey string `json:"machineKey"`
NodeKey string `json:"nodeKey"`
OS string `json:"os"`
UpdateAvailable bool `json:"updateAvailable"`
EnabledRoutes []string `json:"enabledRoutes"`
AdvertisedRoutes []string `json:"advertisedRoutes"`
ClientConnectivity DeviceClientConnectivity `json:"clientConnectivity"`
TailnetLockError string `json:"tailnetLockError"`
TailnetLockKey string `json:"tailnetLockKey"`
PostureIdentity DevicePostureIdentity `json:"postureIdentity"`
}

// Get gets the [Device] identified by deviceID.
Expand Down
69 changes: 63 additions & 6 deletions v2/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ func TestClient_Devices_Get(t *testing.T) {
NodeKey: "nodekey:test",
OS: "windows",
UpdateAvailable: true,
EnabledRoutes: []string{"10.0.0.0/16"},
AdvertisedRoutes: []string{"10.0.0.0/16"},
ClientConnectivity: tsclient.DeviceClientConnectivity{
Endpoints: []string{"199.9.14.201:59128", "192.68.0.21:59128"},
Latency: map[string]tsclient.DeviceClientConnectivityLocationLatency{"Dallas": {LatencyMs: 60.463043}, "New York City": {Preferred: true, LatencyMs: 31.323811}},
MappingVariesByDestIP: false,
ClientSupports: tsclient.DeviceClientConnectivityClientSupports{
HairPinning: false,
IPv6: true,
PCP: false,
PMP: false,
UDP: false,
UPnP: false,
},
},
TailnetLockError: "test",
TailnetLockKey: "test",
PostureIdentity: tsclient.DevicePostureIdentity{
Disabled: false,
SerialNumbers: []string{"test"},
},
}

client, server := NewTestHarness(t)
Expand Down Expand Up @@ -101,6 +122,27 @@ func TestClient_Devices_List(t *testing.T) {
NodeKey: "nodekey:test",
OS: "windows",
UpdateAvailable: true,
EnabledRoutes: []string{"10.0.0.0/16"},
AdvertisedRoutes: []string{"10.0.0.0/16"},
ClientConnectivity: tsclient.DeviceClientConnectivity{
Endpoints: []string{"199.9.14.201:59128", "192.68.0.21:59128"},
Latency: map[string]tsclient.DeviceClientConnectivityLocationLatency{"Dallas": {LatencyMs: 60.463043}, "New York City": {Preferred: true, LatencyMs: 31.323811}},
MappingVariesByDestIP: false,
ClientSupports: tsclient.DeviceClientConnectivityClientSupports{
HairPinning: false,
IPv6: true,
PCP: false,
PMP: false,
UDP: false,
UPnP: false,
},
},
TailnetLockError: "test",
TailnetLockKey: "test",
PostureIdentity: tsclient.DevicePostureIdentity{
Disabled: false,
SerialNumbers: []string{"test"},
},
},
},
}
Expand Down Expand Up @@ -171,12 +213,27 @@ func TestDevices_Unmarshal(t *testing.T) {
LastSeen: tsclient.Time{
time.Date(2022, 4, 15, 13, 25, 21, 0, time.UTC),
},
MachineKey: "mkey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
Name: "foo.example.com",
NodeKey: "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
OS: "linux",
UpdateAvailable: false,
User: "[email protected]",
MachineKey: "mkey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
Name: "foo.example.com",
NodeKey: "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
OS: "linux",
UpdateAvailable: false,
User: "[email protected]",
EnabledRoutes: []string{"10.0.0.0/16", "192.168.1.0/24"},
AdvertisedRoutes: []string{"10.0.0.0/16", "192.168.1.0/24"},
ClientConnectivity: tsclient.DeviceClientConnectivity{
Endpoints: []string{"199.9.14.201:59128", "192.68.0.21:59128"},
Latency: map[string]tsclient.DeviceClientConnectivityLocationLatency{"Dallas": {LatencyMs: 60.463043}, "New York City": {Preferred: true, LatencyMs: 31.323811}},
MappingVariesByDestIP: false,
ClientSupports: tsclient.DeviceClientConnectivityClientSupports{
HairPinning: false,
IPv6: true,
PCP: false,
PMP: false,
UDP: false,
UPnP: false,
},
},
},
},
},
Expand Down
34 changes: 33 additions & 1 deletion v2/testdata/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,39 @@
"nodeKey": "nodekey:30dc3c061ac8b33fdc6d88a4a67b053b01b56930d78cae0cf7a164411d424c0d",
"os": "linux",
"updateAvailable": false,
"user": "[email protected]"
"user": "[email protected]",
"enabledRoutes": [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoinked from the examples in the openapi spec
https://tailscale.com/api#tag/devices/GET/tailnet/{tailnet}/devices

"10.0.0.0/16",
"192.168.1.0/24"
],
"advertisedRoutes": [
"10.0.0.0/16",
"192.168.1.0/24"
],
"clientConnectivity": {
"endpoints": [
"199.9.14.201:59128",
"192.68.0.21:59128"
],
"latency": {
"Dallas": {
"latencyMs": 60.463043
},
"New York City": {
"preferred": true,
"latencyMs": 31.323811
}
},
"mappingVariesByDestIP": false,
"clientSupports": {
"hairPinning": false,
"ipv6": true,
"pcp": false,
"pmp": false,
"udp": false,
"upnp": false
}
}
}
]
}