fleet/server/service/transport_hosts.go
Zach Wasserman a2a7082bd3
Implement add hosts to team by filters API (#866)
- Add hosts to team using label, status, and query filters.
- Documentation (+ docs for regular add hosts to team).
2021-05-25 21:29:52 -07:00

67 lines
1.6 KiB
Go

package service
import (
"context"
"encoding/json"
"net/http"
)
func decodeGetHostRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
return getHostRequest{ID: id}, nil
}
func decodeHostByIdentifierRequest(ctx context.Context, r *http.Request) (interface{}, error) {
identifier, err := nameFromRequest(r, "identifier")
if err != nil {
return nil, err
}
return hostByIdentifierRequest{Identifier: identifier}, nil
}
func decodeDeleteHostRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
return deleteHostRequest{ID: id}, nil
}
func decodeRefetchHostRequest(ctx context.Context, r *http.Request) (interface{}, error) {
id, err := idFromRequest(r, "id")
if err != nil {
return nil, err
}
return refetchHostRequest{ID: id}, nil
}
func decodeListHostsRequest(ctx context.Context, r *http.Request) (interface{}, error) {
hopt, err := hostListOptionsFromRequest(r)
if err != nil {
return nil, err
}
return listHostsRequest{ListOptions: hopt}, nil
}
func decodeAddHostsToTeamRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req addHostsToTeamRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
}
func decodeAddHostsToTeamByFilterRequest(ctx context.Context, r *http.Request) (interface{}, error) {
var req addHostsToTeamByFilterRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}
return req, nil
}