diff --git a/contrib/for-tests/netexec/Makefile b/contrib/for-tests/netexec/Makefile index 73c540e6df6..57098585af3 100644 --- a/contrib/for-tests/netexec/Makefile +++ b/contrib/for-tests/netexec/Makefile @@ -1,12 +1,10 @@ .PHONY: all netexec image push clean -TAG = 1.0 +TAG = 1.1 PREFIX = gcr.io/google_containers all: push -TAG = 1.0 - netexec: netexec.go CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' ./netexec.go diff --git a/contrib/for-tests/netexec/netexec.go b/contrib/for-tests/netexec/netexec.go index 92bd75f7f77..cfca4a12971 100644 --- a/contrib/for-tests/netexec/netexec.go +++ b/contrib/for-tests/netexec/netexec.go @@ -191,9 +191,20 @@ func dialUDP(request string, remoteAddress *net.UDPAddr) (string, error) { func shellHandler(w http.ResponseWriter, r *http.Request) { log.Println(r.FormValue("shellCommand")) - output, err := exec.Command(shellPath, "-c", r.FormValue("shellCommand")).CombinedOutput() - assertNoError(err) - fmt.Fprintf(w, string(output)) + cmdOut, err := exec.Command(shellPath, "-c", r.FormValue("shellCommand")).CombinedOutput() + output := map[string]string{} + if len(cmdOut) > 0 { + output["output"] = string(cmdOut) + } + if err != nil { + output["error"] = fmt.Sprintf("%v", err) + } + bytes, err := json.Marshal(output) + if err == nil { + fmt.Fprintf(w, string(bytes)) + } else { + http.Error(w, fmt.Sprintf("response could not be serialized. %v", err), http.StatusExpectationFailed) + } } func hostNameHandler(w http.ResponseWriter, r *http.Request) {