mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
b9e6a84f24
#11089 - [X] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - ~[ ] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)~ - [X] Documented any permissions changes - ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements)~ - ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features.~ - [x] Added/updated tests - [X] Manual QA for all new/changed functionality - ~For Orbit and Fleet Desktop changes:~ - ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ - ~[ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
)
|
|
|
|
// ApplyQueries sends the list of Queries to be applied (upserted) to the
|
|
// Fleet instance.
|
|
func (c *Client) ApplyQueries(specs []*fleet.QuerySpec) error {
|
|
req := applyQuerySpecsRequest{Specs: specs}
|
|
verb, path := "POST", "/api/latest/fleet/spec/queries"
|
|
var responseBody applyQuerySpecsResponse
|
|
return c.authenticatedRequest(req, verb, path, &responseBody)
|
|
}
|
|
|
|
// GetQuery retrieves the list of all Queries.
|
|
func (c *Client) GetQuery(name string) (*fleet.QuerySpec, error) {
|
|
verb, path := "GET", "/api/latest/fleet/spec/queries/"+url.PathEscape(name)
|
|
var responseBody getQuerySpecResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Spec, err
|
|
}
|
|
|
|
// GetQueries retrieves the list of all Queries.
|
|
func (c *Client) GetQueries() ([]fleet.Query, error) {
|
|
verb, path := "GET", "/api/latest/fleet/queries"
|
|
var responseBody listQueriesResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Queries, err
|
|
}
|
|
|
|
// DeleteQuery deletes the query with the matching name.
|
|
func (c *Client) DeleteQuery(name string) error {
|
|
verb, path := "DELETE", "/api/latest/fleet/queries/"+url.PathEscape(name)
|
|
var responseBody deleteQueryResponse
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
}
|