Skip to content

Commit 9a20edf

Browse files
committed
api/types/container: introduce ExecCreateResponse type
Introduce a container.ExecCreateResponse type as alias for IDResponse to allow consumers to use ContainerCommit without having to import the "types" package, and allows us to differentiate the response for container commit separate from other endpoints currently using IDResponse. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0df3a00 commit 9a20edf

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

api/server/router/container/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (c *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
6161
return err
6262
}
6363

64-
return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{
64+
return httputils.WriteJSON(w, http.StatusCreated, &container.ExecCreateResponse{
6565
ID: id,
6666
})
6767
}

api/types/container/exec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package container
22

3+
import "github.com/docker/docker/api/types/common"
4+
5+
// ExecCreateResponse is the response for a successful exec-create request.
6+
// It holds the ID of the exec that was created.
7+
//
8+
// TODO(thaJeztah): make this a distinct type.
9+
type ExecCreateResponse = common.IDResponse
10+
311
// ExecOptions is a small subset of the Config struct that holds the configuration
412
// for the exec feature of docker.
513
type ExecOptions struct {

client/client_interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type ContainerAPIClient interface {
7373
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
7474
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
7575
ContainerExecAttach(ctx context.Context, execID string, options container.ExecAttachOptions) (types.HijackedResponse, error)
76-
ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (types.IDResponse, error)
76+
ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (container.ExecCreateResponse, error)
7777
ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)
7878
ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
7979
ContainerExecStart(ctx context.Context, execID string, options container.ExecStartOptions) error

client/container_exec.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
)
1212

1313
// ContainerExecCreate creates a new exec configuration to run an exec process.
14-
func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string, options container.ExecOptions) (types.IDResponse, error) {
14+
func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string, options container.ExecOptions) (container.ExecCreateResponse, error) {
1515
containerID, err := trimID("container", containerID)
1616
if err != nil {
17-
return types.IDResponse{}, err
17+
return container.ExecCreateResponse{}, err
1818
}
1919

2020
// Make sure we negotiated (if the client is configured to do so),
@@ -23,11 +23,11 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
2323
// Normally, version-negotiation (if enabled) would not happen until
2424
// the API request is made.
2525
if err := cli.checkVersion(ctx); err != nil {
26-
return types.IDResponse{}, err
26+
return container.ExecCreateResponse{}, err
2727
}
2828

2929
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
30-
return types.IDResponse{}, err
30+
return container.ExecCreateResponse{}, err
3131
}
3232
if versions.LessThan(cli.ClientVersion(), "1.42") {
3333
options.ConsoleSize = nil
@@ -36,10 +36,10 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
3636
resp, err := cli.post(ctx, "/containers/"+containerID+"/exec", nil, options, nil)
3737
defer ensureReaderClosed(resp)
3838
if err != nil {
39-
return types.IDResponse{}, err
39+
return container.ExecCreateResponse{}, err
4040
}
4141

42-
var response types.IDResponse
42+
var response container.ExecCreateResponse
4343
err = json.NewDecoder(resp.body).Decode(&response)
4444
return response, err
4545
}

client/container_exec_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
1514
"github.com/docker/docker/errdefs"
1615
"gotest.tools/v3/assert"
@@ -67,7 +66,7 @@ func TestContainerExecCreate(t *testing.T) {
6766
if execConfig.User != "user" {
6867
return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig)
6968
}
70-
b, err := json.Marshal(types.IDResponse{
69+
b, err := json.Marshal(container.ExecCreateResponse{
7170
ID: "exec_id",
7271
})
7372
if err != nil {

0 commit comments

Comments
 (0)