fleet/server/service/transport_queries.go
Zachary Wasserman c5f0e5a6b4
Add endpoints for apply/get of each spec type (#1752)
- Osquery Options (to be renamed to Options after current Options removed)
- Labels
- Queries
- Packs
2018-05-03 18:01:57 -07:00

74 lines
1.7 KiB
Go

package service
import (
"context"
"encoding/json"
"net/http"
)
func decodeCreateQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req createQueryRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
return req, nil
}
func decodeModifyQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req modifyQueryRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
req.ID = id
return req, nil
}
func decodeDeleteQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req deleteQueryRequest
req.ID = id
return req, nil
}
func decodeDeleteQueriesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req deleteQueriesRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
}
func decodeGetQueryRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req getQueryRequest
req.ID = id
return req, nil
}
func decodeListQueriesRequest(ctx context.Context, r *http.Request) (interface{}, error) {
opt, err := listOptionsFromRequest(r)
if err != nil {
return nil, err
}
return listQueriesRequest{ListOptions: opt}, nil
}
func decodeApplyQuerySpecsRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req applyQuerySpecsRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
}