fleet/server/service/client_queries.go
Lucas Manuel Rodriguez b9e6a84f24
Filter out non-observer_can_run queries for observers in fleetctl get queries command to match the UI. (#11251)
#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)).~
2023-04-26 11:38:20 -03:00

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)
}