Skip to content

Commit 7679ab1

Browse files
hosomoxtoacart
authored andcommitted
Add method to retrieve posture attributes
Signed-off-by: hosom <[email protected]>
1 parent cc83c9e commit 7679ab1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

v2/devices.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ type Device struct {
6767
UpdateAvailable bool `json:"updateAvailable"`
6868
}
6969

70+
type DevicePostureAttributes struct {
71+
Attributes map[string]any `json:"attributes"`
72+
Expiries map[string]Time `json:"expiries"`
73+
}
74+
7075
// Get gets the [Device] identified by deviceID.
7176
func (dr *DevicesResource) Get(ctx context.Context, deviceID string) (*Device, error) {
7277
req, err := dr.buildRequest(ctx, http.MethodGet, dr.buildURL("device", deviceID))
@@ -77,6 +82,15 @@ func (dr *DevicesResource) Get(ctx context.Context, deviceID string) (*Device, e
7782
return body[Device](dr, req)
7883
}
7984

85+
func (dr *DevicesResource) GetPostureAttributes(ctx context.Context, deviceID string) (*DevicePostureAttributes, error) {
86+
req, err := dr.buildRequest(ctx, http.MethodGet, dr.buildURL("device", deviceID, "attributes"))
87+
if err != nil {
88+
return nil, err
89+
}
90+
91+
return body[DevicePostureAttributes](dr, req)
92+
}
93+
8094
// List lists every [Device] in the tailnet.
8195
func (dr *DevicesResource) List(ctx context.Context) ([]Device, error) {
8296
req, err := dr.buildRequest(ctx, http.MethodGet, dr.buildTailnetURL("devices"))

v2/devices_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ func TestClient_Devices_Get(t *testing.T) {
7777
assert.EqualValues(t, expectedDevice, actualDevice)
7878
}
7979

80+
func TestClient_Devices_GetPostureAttributes(t *testing.T) {
81+
t.Parallel()
82+
83+
expectedAttributes := &tsclient.DevicePostureAttributes{
84+
Attributes: map[string]interface{}{
85+
"custom:key": "value",
86+
"node:os": "linux",
87+
"node:osVersion": "5.19.0-42-generic",
88+
"node:tsReleaseTrack": "stable",
89+
"node:tsVersion": "1.40.0",
90+
"node:tsAutoUpdate": false,
91+
},
92+
Expiries: map[string]tsclient.Time{
93+
"custom:key": {time.Date(2022, 2, 10, 11, 50, 23, 0, time.UTC)},
94+
},
95+
}
96+
97+
client, server := NewTestHarness(t)
98+
server.ResponseCode = http.StatusOK
99+
server.ResponseBody = expectedAttributes
100+
101+
actualAttributes, err := client.Devices().GetPostureAttributes(context.Background(), "testid")
102+
assert.NoError(t, err)
103+
assert.Equal(t, http.MethodGet, server.Method)
104+
assert.Equal(t, "/api/v2/device/testid/attributes", server.Path)
105+
106+
assert.EqualValues(t, expectedAttributes, actualAttributes)
107+
}
108+
80109
func TestClient_Devices_List(t *testing.T) {
81110
t.Parallel()
82111

0 commit comments

Comments
 (0)