mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
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 <github@gone.nl>
This commit is contained in:
@@ -61,7 +61,7 @@ func (c *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
|
||||
return err
|
||||
}
|
||||
|
||||
return httputils.WriteJSON(w, http.StatusCreated, &types.IDResponse{
|
||||
return httputils.WriteJSON(w, http.StatusCreated, &container.ExecCreateResponse{
|
||||
ID: id,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package container
|
||||
|
||||
import "github.com/docker/docker/api/types/common"
|
||||
|
||||
// ExecCreateResponse is the response for a successful exec-create request.
|
||||
// It holds the ID of the exec that was created.
|
||||
//
|
||||
// TODO(thaJeztah): make this a distinct type.
|
||||
type ExecCreateResponse = common.IDResponse
|
||||
|
||||
// ExecOptions is a small subset of the Config struct that holds the configuration
|
||||
// for the exec feature of docker.
|
||||
type ExecOptions struct {
|
||||
|
||||
@@ -73,7 +73,7 @@ type ContainerAPIClient interface {
|
||||
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
|
||||
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
|
||||
ContainerExecAttach(ctx context.Context, execID string, options container.ExecAttachOptions) (types.HijackedResponse, error)
|
||||
ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (types.IDResponse, error)
|
||||
ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (container.ExecCreateResponse, error)
|
||||
ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)
|
||||
ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
|
||||
ContainerExecStart(ctx context.Context, execID string, options container.ExecStartOptions) error
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
)
|
||||
|
||||
// ContainerExecCreate creates a new exec configuration to run an exec process.
|
||||
func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string, options container.ExecOptions) (types.IDResponse, error) {
|
||||
func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string, options container.ExecOptions) (container.ExecCreateResponse, error) {
|
||||
containerID, err := trimID("container", containerID)
|
||||
if err != nil {
|
||||
return types.IDResponse{}, err
|
||||
return container.ExecCreateResponse{}, err
|
||||
}
|
||||
|
||||
// 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,
|
||||
// Normally, version-negotiation (if enabled) would not happen until
|
||||
// the API request is made.
|
||||
if err := cli.checkVersion(ctx); err != nil {
|
||||
return types.IDResponse{}, err
|
||||
return container.ExecCreateResponse{}, err
|
||||
}
|
||||
|
||||
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
|
||||
return types.IDResponse{}, err
|
||||
return container.ExecCreateResponse{}, err
|
||||
}
|
||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
||||
options.ConsoleSize = nil
|
||||
@@ -36,10 +36,10 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
|
||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/exec", nil, options, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return types.IDResponse{}, err
|
||||
return container.ExecCreateResponse{}, err
|
||||
}
|
||||
|
||||
var response types.IDResponse
|
||||
var response container.ExecCreateResponse
|
||||
err = json.NewDecoder(resp.body).Decode(&response)
|
||||
return response, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -67,7 +66,7 @@ func TestContainerExecCreate(t *testing.T) {
|
||||
if execConfig.User != "user" {
|
||||
return nil, fmt.Errorf("expected an execConfig with User == 'user', got %v", execConfig)
|
||||
}
|
||||
b, err := json.Marshal(types.IDResponse{
|
||||
b, err := json.Marshal(container.ExecCreateResponse{
|
||||
ID: "exec_id",
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user