mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
netexec shellCommand endpoint returns the error if shell command fails, instead of killing netexec
This commit is contained in:
parent
915bc04488
commit
e40f1533f9
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user