fleet/server/service/transport_packs.go
Mike Arpaia a03347489c Osquery Configuration Control (#244)
Label management APIs and an osquery config endpoint based on active pack and label state.
2016-10-02 20:14:35 -07:00

131 lines
2.8 KiB
Go

package service
import (
"encoding/json"
"net/http"
"golang.org/x/net/context"
)
func decodeCreatePackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req createPackRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
return req, nil
}
func decodeModifyPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req modifyPackRequest
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
return nil, err
}
req.ID = id
return req, nil
}
func decodeDeletePackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req deletePackRequest
req.ID = id
return req, nil
}
func decodeGetPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req getPackRequest
req.ID = id
return req, nil
}
func decodeAddQueryToPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
qid, err := idFromRequest(r, "qid")
if err != nil {
return nil, err
}
pid, err := idFromRequest(r, "pid")
if err != nil {
return nil, err
}
var req addQueryToPackRequest
req.PackID = pid
req.QueryID = qid
return req, nil
}
func decodeGetQueriesInPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
var req getQueriesInPackRequest
req.ID = id
return req, nil
}
func decodeDeleteQueryFromPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
qid, err := idFromRequest(r, "qid")
if err != nil {
return nil, err
}
pid, err := idFromRequest(r, "pid")
if err != nil {
return nil, err
}
var req deleteQueryFromPackRequest
req.PackID = pid
req.QueryID = qid
return req, nil
}
func decodeAddLabelToPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
lid, err := idFromRequest(r, "lid")
if err != nil {
return nil, err
}
pid, err := idFromRequest(r, "pid")
if err != nil {
return nil, err
}
return addLabelToPackRequest{
PackID: pid,
LabelID: lid,
}, nil
}
func decodeGetLabelsForPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
pid, err := idFromRequest(r, "pid")
if err != nil {
return nil, err
}
var req getLabelsForPackRequest
req.PackID = pid
return req, nil
}
func decodeDeleteLabelFromPackRequest(ctx context.Context, r *http.Request) (interface{}, error) {
lid, err := idFromRequest(r, "lid")
if err != nil {
return nil, err
}
pid, err := idFromRequest(r, "pid")
if err != nil {
return nil, err
}
var req deleteLabelFromPackRequest
req.PackID = pid
req.LabelID = lid
return req, nil
}