Skip to content

Commit 17a9401

Browse files
hosommpminardi
authored andcommitted
Add method for deleting posture attributes
1 parent fe1dae8 commit 17a9401

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

devices.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ func (dr *DevicesResource) SetPostureAttribute(ctx context.Context, deviceID, at
161161
return dr.do(req, nil)
162162
}
163163

164+
// DeletePostureAttribute deletes the posture attribute of the device identified by deviceID.
165+
//
166+
// Using the device `NodeID` is preferred, but its numeric `ID` value can also be used.
167+
func (dr *DevicesResource) DeletePostureAttribute(ctx context.Context, deviceID, attributeKey string) error {
168+
req, err := dr.buildRequest(ctx, http.MethodDelete, dr.buildURL("device", deviceID, "attributes", attributeKey))
169+
if err != nil {
170+
return err
171+
}
172+
173+
return dr.do(req, nil)
174+
}
175+
164176
// ListWithAllFields lists every [Device] in the tailnet. Each [Device] in
165177
// the response will have all fields populated.
166178
func (dr *DevicesResource) ListWithAllFields(ctx context.Context) ([]Device, error) {

devices_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ func TestClient_SetDevicePostureAttributes(t *testing.T) {
399399
assert.EqualValues(t, setRequest, receivedRequest)
400400
}
401401

402+
func TestClient_DeleteDevicePostureAttributes(t *testing.T) {
403+
t.Parallel()
404+
405+
client, server := NewTestHarness(t)
406+
server.ResponseCode = http.StatusOK
407+
server.ResponseBody = nil
408+
409+
const deviceID = "test"
410+
const attributeKey = "custom:test"
411+
412+
assert.NoError(t, client.Devices().DeletePostureAttribute(context.Background(), deviceID, attributeKey))
413+
assert.EqualValues(t, http.MethodDelete, server.Method)
414+
assert.EqualValues(t, "/api/v2/device/"+deviceID+"/attributes/"+attributeKey, server.Path)
415+
}
416+
402417
func TestClient_SetDeviceKey(t *testing.T) {
403418
t.Parallel()
404419

0 commit comments

Comments
 (0)