mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
If a blank nodeID was previously passed in it resulted in a node list request. The response would then fail to umarshal into a `Node` type returning a JSON error. This adds an extra validation to all inspect calls to check that the ID that is required is provided and if not return an error. Signed-off-by: Emil Davtyan <emil2k@gmail.com>
33 lines
851 B
Go
33 lines
851 B
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
// TaskInspectWithRaw returns the task information and its raw representation..
|
|
func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) {
|
|
if taskID == "" {
|
|
return swarm.Task{}, nil, objectNotFoundError{object: "task", id: taskID}
|
|
}
|
|
serverResp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil)
|
|
if err != nil {
|
|
return swarm.Task{}, nil, wrapResponseError(err, serverResp, "task", taskID)
|
|
}
|
|
defer ensureReaderClosed(serverResp)
|
|
|
|
body, err := ioutil.ReadAll(serverResp.body)
|
|
if err != nil {
|
|
return swarm.Task{}, nil, err
|
|
}
|
|
|
|
var response swarm.Task
|
|
rdr := bytes.NewReader(body)
|
|
err = json.NewDecoder(rdr).Decode(&response)
|
|
return response, body, err
|
|
}
|