fleet/server/service/transport_queries.go
Zachary Wasserman 0b7747bef0
Fix pack and query UI issues in Fleet 2.0 (#1829)
Replaces (and appropriately refactors) a number of endpoints that were removed long ago when we decided to kill the UI with the fleetctl release. We turned out not to do this, and now need to restore these missing endpoints.

This is not a straight up replacement of the existing code because of refactoring to the DB schemas that was also done in the migration.

Most of the replaced code was removed in #1670 and #1686.

Fixes #1811, fixes #1810
2018-06-15 10:13:11 -04:00

84 lines
1.9 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) {
name, err := nameFromRequest(r, "name")
if err != nil {
return nil, err
}
var req deleteQueryRequest
req.Name = name
return req, nil
}
func decodeDeleteQueryByIDRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req deleteQueryByIDRequest
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
}