Skip to content

Add method for deleting posture attributes #20

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

Merged
merged 2 commits into from
Apr 21, 2025
Merged
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
12 changes: 12 additions & 0 deletions devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down