fleet/server/service/transport_queries.go
Tomas Touceda 545b3f396e
Issue 1362 fleetctl user roles (#1397)
* WIP

* Add get user_roles and apply for a user_roles spec to fleetctl

* Uncomment other tests

* Update test to check output

* Update test with the new struct

* Mock token so that it doesn't pick up the one in the local machine

* Address review comments

* Fix printJSON and printYaml

* Fix merge conflict error

* If both roles are specified, fail

* Fix test

* Switch arguments around

* Update test with the new rule

* Fix other tests that fell through the cracks
2021-07-16 15:28:13 -03:00

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