diff --git a/devices.go b/devices.go index c235ced..b037499 100644 --- a/devices.go +++ b/devices.go @@ -161,6 +161,18 @@ func (dr *DevicesResource) SetPostureAttribute(ctx context.Context, deviceID, at return dr.do(req, nil) } +// DeletePostureAttribute deletes the posture attribute of the device identified by deviceID. +// +// Using the device `NodeID` is preferred, but its numeric `ID` value can also be used. +func (dr *DevicesResource) DeletePostureAttribute(ctx context.Context, deviceID, attributeKey string) error { + req, err := dr.buildRequest(ctx, http.MethodDelete, dr.buildURL("device", deviceID, "attributes", attributeKey)) + if err != nil { + return err + } + + return dr.do(req, nil) +} + // ListWithAllFields lists every [Device] in the tailnet. Each [Device] in // the response will have all fields populated. func (dr *DevicesResource) ListWithAllFields(ctx context.Context) ([]Device, error) { diff --git a/devices_test.go b/devices_test.go index 5829e58..668af51 100644 --- a/devices_test.go +++ b/devices_test.go @@ -399,6 +399,21 @@ func TestClient_SetDevicePostureAttributes(t *testing.T) { assert.EqualValues(t, setRequest, receivedRequest) } +func TestClient_DeleteDevicePostureAttributes(t *testing.T) { + t.Parallel() + + client, server := NewTestHarness(t) + server.ResponseCode = http.StatusOK + server.ResponseBody = nil + + const deviceID = "test" + const attributeKey = "custom:test" + + assert.NoError(t, client.Devices().DeletePostureAttribute(context.Background(), deviceID, attributeKey)) + assert.EqualValues(t, http.MethodDelete, server.Method) + assert.EqualValues(t, "/api/v2/device/"+deviceID+"/attributes/"+attributeKey, server.Path) +} + func TestClient_SetDeviceKey(t *testing.T) { t.Parallel()