mirror of
https://github.com/fleetdm/fleet
synced 2026-05-10 02:30:56 +00:00
Previously when passing labels to the query run endpoints that do not exist, the labels would simply be ignored. Now the endpoint will return an error indicating which labels are invalid. This change also affects the `fleetctl query` command `--labels` flag. https://github.com/fleetdm/fleet/issues/23015 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Ian Littman <iansltx@gmail.com>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
// ApplyLabels sends the list of Labels to be applied (upserted) to the
|
|
// Fleet instance.
|
|
func (c *Client) ApplyLabels(specs []*fleet.LabelSpec) error {
|
|
req := applyLabelSpecsRequest{Specs: specs}
|
|
verb, path := "POST", "/api/latest/fleet/spec/labels"
|
|
var responseBody applyLabelSpecsResponse
|
|
return c.authenticatedRequest(req, verb, path, &responseBody)
|
|
}
|
|
|
|
// GetLabel retrieves information about a label by name
|
|
func (c *Client) GetLabel(name string) (*fleet.LabelSpec, error) {
|
|
verb, path := "GET", "/api/latest/fleet/spec/labels/"+url.PathEscape(name)
|
|
var responseBody getLabelSpecResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Spec, err
|
|
}
|
|
|
|
// GetLabels retrieves the list of all LabelSpecs.
|
|
func (c *Client) GetLabels() ([]*fleet.LabelSpec, error) {
|
|
verb, path := "GET", "/api/latest/fleet/spec/labels"
|
|
var responseBody getLabelSpecsResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Specs, err
|
|
}
|
|
|
|
// DeleteLabel deletes the label with the matching name.
|
|
func (c *Client) DeleteLabel(name string) error {
|
|
verb, path := "DELETE", "/api/latest/fleet/labels/"+url.PathEscape(name)
|
|
var responseBody deleteLabelResponse
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
}
|