fleet/server/service/client_labels.go
Tomas Touceda a18e09b613
Simplify fleetctl implementation and improve testing (#3830)
* Simplify fleetctl implementation and improve testing

* Add a few more

* Handle not founds better

* Fix tests

* Check that logout ds func is called
2022-01-24 16:40:51 -03:00

40 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/v1/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/v1/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 Labels.
func (c *Client) GetLabels() ([]*fleet.LabelSpec, error) {
verb, path := "GET", "/api/v1/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/v1/fleet/labels/"+url.PathEscape(name)
var responseBody deleteLabelResponse
return c.authenticatedRequest(nil, verb, path, &responseBody)
}