@@ -44,6 +44,29 @@ func (t *Time) UnmarshalJSON(data []byte) error {
44
44
return nil
45
45
}
46
46
47
+ type DERPRegion struct {
48
+ Preferred bool `json:"preferred,omitempty"`
49
+ LatencyMilliseconds float64 `json:"latencyMs"`
50
+ }
51
+
52
+ type ClientSupports struct {
53
+ HairPinning bool `json:"hairPinning"`
54
+ IPV6 bool `json:"ipv6"`
55
+ PCP bool `json:"pcp"`
56
+ PMP bool `json:"pmp"`
57
+ UDP bool `json:"udp"`
58
+ UPNP bool `json:"upnp"`
59
+ }
60
+
61
+ type ClientConnectivity struct {
62
+ Endpoints []string `json:"endpoints"`
63
+ DERP string `json:"derp"`
64
+ MappingVariesByDestIP bool `json:"mappingVariesByDestIP"`
65
+ // DERPLatency is mapped by region name (e.g. "New York City", "Seattle").
66
+ DERPLatency map [string ]DERPRegion `json:"latency"`
67
+ ClientSupports ClientSupports `json:"clientSupports"`
68
+ }
69
+
47
70
type Device struct {
48
71
Addresses []string `json:"addresses"`
49
72
Name string `json:"name"`
@@ -66,6 +89,11 @@ type Device struct {
66
89
TailnetLockError string `json:"tailnetLockError"`
67
90
TailnetLockKey string `json:"tailnetLockKey"`
68
91
UpdateAvailable bool `json:"updateAvailable"`
92
+
93
+ // The below are only included in listings when querying `all` fields.
94
+ AdvertisedRoutes []string `json:"AdvertisedRoutes"`
95
+ EnabledRoutes []string `json:"enabledRoutes"`
96
+ ClientConnectivity * ClientConnectivity `json:"clientConnectivity"`
69
97
}
70
98
71
99
type DevicePostureAttributes struct {
@@ -115,13 +143,31 @@ func (dr *DevicesResource) SetPostureAttribute(ctx context.Context, deviceID, at
115
143
return dr .do (req , nil )
116
144
}
117
145
118
- // List lists every [Device] in the tailnet.
146
+ // ListWithAllFields lists every [Device] in the tailnet. Each [Device] in
147
+ // the response will have all fields populated.
148
+ func (dr * DevicesResource ) ListWithAllFields (ctx context.Context ) ([]Device , error ) {
149
+ return dr .list (ctx , true )
150
+ }
151
+
152
+ // List lists every [Device] in the tailnet. The fields `EnabledRoutes`,
153
+ // `AdvertisedRoutes` and `ClientConnectivity` will be omitted from the resulting
154
+ // [Devices]. To get these fields, use `ListWithAllFields`.
119
155
func (dr * DevicesResource ) List (ctx context.Context ) ([]Device , error ) {
156
+ return dr .list (ctx , false )
157
+ }
158
+
159
+ func (dr * DevicesResource ) list (ctx context.Context , all bool ) ([]Device , error ) {
120
160
req , err := dr .buildRequest (ctx , http .MethodGet , dr .buildTailnetURL ("devices" ))
121
161
if err != nil {
122
162
return nil , err
123
163
}
124
164
165
+ if all {
166
+ q := req .URL .Query ()
167
+ q .Set ("fields" , "all" )
168
+ req .URL .RawQuery = q .Encode ()
169
+ }
170
+
125
171
m := make (map [string ][]Device )
126
172
err = dr .do (req , & m )
127
173
if err != nil {
0 commit comments