Skip to content

Commit 4df03a2

Browse files
authored
Merge pull request moby#50991 from thaJeztah/move_exec_inspect
api/types/container: move ExecInspect type to client
2 parents 962857d + ff21989 commit 4df03a2

File tree

7 files changed

+69
-43
lines changed

7 files changed

+69
-43
lines changed

api/types/container/exec.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ import "github.com/moby/moby/api/types/common"
88
// TODO(thaJeztah): make this a distinct type.
99
type ExecCreateResponse = common.IDResponse
1010

11-
// ExecInspect holds information returned by exec inspect.
12-
//
13-
// It is used by the client to unmarshal a [ExecInspectResponse],
14-
// but currently only provides a subset of the information included
15-
// in that type.
16-
//
17-
// TODO(thaJeztah): merge [ExecInspect] and [ExecInspectResponse],
18-
type ExecInspect struct {
19-
ExecID string `json:"ID"`
20-
ContainerID string `json:"ContainerID"`
21-
Running bool `json:"Running"`
22-
ExitCode int `json:"ExitCode"`
23-
Pid int `json:"Pid"`
24-
}
25-
2611
// ExecInspectResponse is the API response for the "GET /exec/{id}/json"
2712
// endpoint and holds information about and exec.
2813
type ExecInspectResponse struct {

client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type ContainerAPIClient interface {
7171
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
7272
ContainerExecAttach(ctx context.Context, execID string, options ExecAttachOptions) (HijackedResponse, error)
7373
ContainerExecCreate(ctx context.Context, container string, options ExecCreateOptions) (container.ExecCreateResponse, error)
74-
ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)
74+
ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error)
7575
ContainerExecResize(ctx context.Context, execID string, options ContainerResizeOptions) error
7676
ContainerExecStart(ctx context.Context, execID string, options ExecStartOptions) error
7777
ContainerExport(ctx context.Context, container string) (io.ReadCloser, error)

client/container_exec.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,43 @@ func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, confi
146146
})
147147
}
148148

149+
// ExecInspect holds information returned by exec inspect.
150+
//
151+
// It provides a subset of the information included in [container.ExecInspectResponse].
152+
//
153+
// TODO(thaJeztah): include all fields of [container.ExecInspectResponse] ?
154+
type ExecInspect struct {
155+
ExecID string `json:"ID"`
156+
ContainerID string `json:"ContainerID"`
157+
Running bool `json:"Running"`
158+
ExitCode int `json:"ExitCode"`
159+
Pid int `json:"Pid"`
160+
}
161+
149162
// ContainerExecInspect returns information about a specific exec process on the docker host.
150-
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error) {
163+
func (cli *Client) ContainerExecInspect(ctx context.Context, execID string) (ExecInspect, error) {
151164
resp, err := cli.get(ctx, "/exec/"+execID+"/json", nil, nil)
152165
defer ensureReaderClosed(resp)
153166
if err != nil {
154-
return container.ExecInspect{}, err
167+
return ExecInspect{}, err
155168
}
156169

157-
var response container.ExecInspect
170+
var response container.ExecInspectResponse
158171
err = json.NewDecoder(resp.Body).Decode(&response)
159-
return response, err
172+
if err != nil {
173+
return ExecInspect{}, err
174+
}
175+
176+
var ec int
177+
if response.ExitCode != nil {
178+
ec = *response.ExitCode
179+
}
180+
181+
return ExecInspect{
182+
ExecID: response.ID,
183+
ContainerID: response.ContainerID,
184+
Running: response.Running,
185+
ExitCode: ec,
186+
Pid: response.Pid,
187+
}, nil
160188
}

client/container_exec_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ func TestContainerExecInspect(t *testing.T) {
146146
client, err := NewClientWithOpts(
147147
WithMockClient(func(req *http.Request) (*http.Response, error) {
148148
if !strings.HasPrefix(req.URL.Path, expectedURL) {
149-
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
149+
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
150150
}
151-
b, err := json.Marshal(container.ExecInspect{
152-
ExecID: "exec_id",
151+
b, err := json.Marshal(container.ExecInspectResponse{
152+
ID: "exec_id",
153153
ContainerID: "container_id",
154154
})
155155
if err != nil {

vendor/github.com/moby/moby/api/types/container/exec.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/moby/moby/client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/moby/moby/client/container_exec.go

Lines changed: 32 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)