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
|
|
|
// ApplyQueries sends the list of Queries 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) ApplyQueries(specs []*fleet.QuerySpec) error {
|
2018-05-07 19:44:40 +00:00
|
|
|
req := applyQuerySpecsRequest{Specs: specs}
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "POST", "/api/latest/fleet/spec/queries"
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody applyQuerySpecsResponse
|
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
|
|
|
// GetQuery retrieves the list of all Queries.
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) GetQuery(name string) (*fleet.QuerySpec, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/spec/queries/"+url.PathEscape(name)
|
2018-05-09 00:10:01 +00:00
|
|
|
var responseBody getQuerySpecResponse
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// GetQueries retrieves the list of all Queries.
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) GetQueries() ([]*fleet.QuerySpec, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/spec/queries"
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody getQuerySpecsResponse
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteQuery deletes the query with the matching name.
|
|
|
|
func (c *Client) DeleteQuery(name string) error {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "DELETE", "/api/latest/fleet/queries/"+url.PathEscape(name)
|
2018-05-07 19:44:40 +00:00
|
|
|
var responseBody deleteQueryResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
2021-10-25 12:17:34 +00:00
|
|
|
}
|