2018-05-07 19:44:40 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2018-05-07 19:44:40 +00:00
|
|
|
)
|
|
|
|
|
2018-05-09 00:10:01 +00:00
|
|
|
// ApplyLabels sends the list of Labels to be applied (upserted) to the
|
2018-05-07 19:44:40 +00:00
|
|
|
// Fleet instance.
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) ApplyLabels(specs []*fleet.LabelSpec) error {
|
2018-05-07 19:44:40 +00:00
|
|
|
req := applyLabelSpecsRequest{Specs: specs}
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "POST", "/api/latest/fleet/spec/labels"
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody applyLabelSpecsResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
return c.authenticatedRequest(req, verb, path, &responseBody)
|
2018-05-07 19:44:40 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 00:10:01 +00:00
|
|
|
// GetLabel retrieves information about a label by name
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) GetLabel(name string) (*fleet.LabelSpec, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/spec/labels/"+url.PathEscape(name)
|
2018-05-09 00:10:01 +00:00
|
|
|
var responseBody getLabelSpecResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
|
|
return responseBody.Spec, err
|
2018-05-09 00:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabels retrieves the list of all Labels.
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) GetLabels() ([]*fleet.LabelSpec, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/spec/labels"
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody getLabelSpecsResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
|
|
return responseBody.Specs, err
|
2018-05-07 19:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteLabel deletes the label with the matching name.
|
|
|
|
func (c *Client) DeleteLabel(name string) error {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "DELETE", "/api/latest/fleet/labels/"+url.PathEscape(name)
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody deleteLabelResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
2018-05-07 19:44:40 +00:00
|
|
|
}
|