Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions api/types/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ import "github.com/moby/moby/api/types/common"
// TODO(thaJeztah): make this a distinct type.
type ExecCreateResponse = common.IDResponse

// ExecInspect holds information returned by exec inspect.
//
// It is used by the client to unmarshal a [ExecInspectResponse],
// but currently only provides a subset of the information included
// in that type.
//
// TODO(thaJeztah): merge [ExecInspect] and [ExecInspectResponse],
type ExecInspect struct {
ExecID string `json:"ID"`
ContainerID string `json:"ContainerID"`
Running bool `json:"Running"`
ExitCode int `json:"ExitCode"`
Pid int `json:"Pid"`
}

// ExecInspectResponse is the API response for the "GET /exec/{id}/json"
// endpoint and holds information about and exec.
type ExecInspectResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion client/client_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ContainerAPIClient interface {
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
ContainerExecAttach(ctx context.Context, execID string, options ExecAttachOptions) (HijackedResponse, error)
ContainerExecCreate(ctx context.Context, container string, options ExecCreateOptions) (container.ExecCreateResponse, error)
ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)
ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error)
ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error
ContainerExecStart(ctx context.Context, execID string, options ExecStartOptions) error
ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)
Expand Down
36 changes: 32 additions & 4 deletions client/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,43 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi
})
}

// ExecInspect holds information returned by exec inspect.
//
// It provides a subset of the information included in [container.ExecInspectResponse].
//
// TODO(thaJeztah): include all fields of [container.ExecInspectResponse] ?
type ExecInspect struct {
ExecID string `json:"ID"`
ContainerID string `json:"ContainerID"`
Running bool `json:"Running"`
ExitCode int `json:"ExitCode"`
Pid int `json:"Pid"`
Comment on lines +155 to +159
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably consider taking the opportunity to rename ExecID to ID (matching the response), and Pid to PID (the field-name, not the json name if we want to keep marshalling the same when used) to have the proper casing.

}

// ContainerExecInspect returns information about a specific exec process on the docker host.
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) {
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) {
resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil)
defer ensureReaderClosed(resp)
if err != nil {
return container.ExecInspect{}, err
return ExecInspect{}, err
}

var response container.ExecInspect
var response container.ExecInspectResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return response, err
if err != nil {
return ExecInspect{}, err
}

var ec int
if response.ExitCode != nil {
ec = *response.ExitCode
}

return ExecInspect{
ExecID: response.ID,
ContainerID: response.ContainerID,
Running: response.Running,
ExitCode: ec,
Pid: response.Pid,
}, nil
}
6 changes: 3 additions & 3 deletions client/container_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ func TestContainerExecInspect(t *testing.T) {
client, err := NewClientWithOpts(
WithMockClient(func(req *http.Request) (*http.Response, error) {
if !strings.HasPrefix(req.URL.Path, expectedURL) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
}
b, err := json.Marshal(container.ExecInspect{
ExecID: "exec_id",
b, err := json.Marshal(container.ExecInspectResponse{
ID: "exec_id",
ContainerID: "container_id",
})
if err != nil {
Expand Down
15 changes: 0 additions & 15 deletions vendor/github.com/moby/moby/api/types/container/exec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/moby/moby/client/client_interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions vendor/github.com/moby/moby/client/container_exec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading