mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 10:00:13 +00:00
Allow passing arguments to controls
This commit is contained in:
committed by
Simon Howe
parent
403b70dde8
commit
37ba071feb
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/ugorji/go/codec"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/weaveworks/scope/common/xfer"
|
||||
@@ -29,14 +30,26 @@ func RegisterControlRoutes(router *mux.Router, cr ControlRouter) {
|
||||
func handleControl(cr ControlRouter) CtxHandlerFunc {
|
||||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
vars = mux.Vars(r)
|
||||
probeID = vars["probeID"]
|
||||
nodeID = vars["nodeID"]
|
||||
control = vars["control"]
|
||||
vars = mux.Vars(r)
|
||||
probeID = vars["probeID"]
|
||||
nodeID = vars["nodeID"]
|
||||
control = vars["control"]
|
||||
controlArgs map[string]string
|
||||
)
|
||||
|
||||
if r.ContentLength > 0 {
|
||||
err := codec.NewDecoder(r.Body, &codec.JsonHandle{}).Decode(&controlArgs)
|
||||
defer r.Body.Close()
|
||||
if err != nil {
|
||||
respondWith(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
result, err := cr.Handle(ctx, probeID, xfer.Request{
|
||||
NodeID: nodeID,
|
||||
Control: control,
|
||||
NodeID: nodeID,
|
||||
Control: control,
|
||||
ControlArgs: controlArgs,
|
||||
})
|
||||
if err != nil {
|
||||
respondWith(w, http.StatusBadRequest, err.Error())
|
||||
|
||||
@@ -57,7 +57,11 @@ func TestControl(t *testing.T) {
|
||||
httpClient := http.Client{
|
||||
Timeout: 1 * time.Second,
|
||||
}
|
||||
resp, err := httpClient.Post(server.URL+"/api/control/foo/nodeid/control", "", nil)
|
||||
resp, err := httpClient.Post(
|
||||
server.URL+"/api/control/foo/nodeid/control",
|
||||
"application/json",
|
||||
strings.NewReader("{}"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,10 @@ var ErrInvalidMessage = fmt.Errorf("Invalid Message")
|
||||
|
||||
// Request is the UI -> App -> Probe message type for control RPCs
|
||||
type Request struct {
|
||||
AppID string // filled in by the probe on receiving this request
|
||||
NodeID string
|
||||
Control string
|
||||
AppID string // filled in by the probe on receiving this request
|
||||
NodeID string
|
||||
Control string
|
||||
ControlArgs map[string]string
|
||||
}
|
||||
|
||||
// Response is the Probe -> App -> UI message type for the control RPCs.
|
||||
|
||||
Reference in New Issue
Block a user