Skip to content

Commit

Permalink
Create interface that clients that talk to the api must fulfill.
Browse files Browse the repository at this point in the history
Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Dec 9, 2015
1 parent a413be3 commit 8b15839
Show file tree
Hide file tree
Showing 29 changed files with 283 additions and 208 deletions.
4 changes: 2 additions & 2 deletions api/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/docker/distribution/reference"
"github.com/docker/docker/api"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/archive"
Expand Down Expand Up @@ -207,7 +207,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
remoteContext = cmd.Arg(0)
}

options := lib.ImageBuildOptions{
options := types.ImageBuildOptions{
Context: body,
Memory: memory,
MemorySwap: memorySwap,
Expand Down
2 changes: 1 addition & 1 deletion api/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DockerCli struct {
// isTerminalOut indicates whether the client's STDOUT is a TTY
isTerminalOut bool
// client is the http client that performs all API operations
client *lib.Client
client apiClient

// DEPRECATED OPTIONS TO MAKE THE CLIENT COMPILE
// TODO: Remove
Expand Down
55 changes: 55 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,58 @@
// Run "docker help SUBCOMMAND" or "docker SUBCOMMAND --help" to see more information on any Docker subcommand, including the full list of options supported for the subcommand.
// See https://docs.docker.com/installation/ for instructions on installing Docker.
package client

import (
"io"

"github.com/docker/docker/api/types"
"github.com/docker/docker/cliconfig"
"github.com/docker/docker/pkg/parsers/filters"
"github.com/docker/docker/runconfig"
)

// apiClient is an interface that clients that talk with a docker server must implement.
type apiClient interface {
ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error)
ContainerCreate(config *runconfig.ContainerConfigWrapper, containerName string) (types.ContainerCreateResponse, error)
ContainerDiff(containerID string) ([]types.ContainerChange, error)
ContainerExport(containerID string) (io.ReadCloser, error)
ContainerInspect(containerID string) (types.ContainerJSON, error)
ContainerKill(containerID, signal string) error
ContainerList(options types.ContainerListOptions) ([]types.Container, error)
ContainerLogs(options types.ContainerLogsOptions) (io.ReadCloser, error)
ContainerPause(containerID string) error
ContainerRemove(options types.ContainerRemoveOptions) error
ContainerRename(containerID, newContainerName string) error
ContainerRestart(containerID string, timeout int) error
ContainerStatPath(containerID, path string) (types.ContainerPathStat, error)
ContainerStop(containerID string, timeout int) error
ContainerTop(containerID string, arguments []string) (types.ContainerProcessList, error)
ContainerUnpause(containerID string) error
ContainerWait(containerID string) (int, error)
CopyFromContainer(containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
CopyToContainer(options types.CopyToContainerOptions) error
Events(options types.EventsOptions) (io.ReadCloser, error)
ImageBuild(options types.ImageBuildOptions) (types.ImageBuildResponse, error)
ImageCreate(options types.ImageCreateOptions) (io.ReadCloser, error)
ImageHistory(imageID string) ([]types.ImageHistory, error)
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
ImageList(options types.ImageListOptions) ([]types.Image, error)
ImageLoad(input io.Reader) (io.ReadCloser, error)
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
ImageSave(imageIDs []string) (io.ReadCloser, error)
ImageTag(options types.ImageTagOptions) error
Info() (types.Info, error)
NetworkConnect(networkID, containerID string) error
NetworkCreate(options types.NetworkCreate) (types.NetworkCreateResponse, error)
NetworkDisconnect(networkID, containerID string) error
NetworkInspect(networkID string) (types.NetworkResource, error)
NetworkList() ([]types.NetworkResource, error)
NetworkRemove(networkID string) error
RegistryLogin(auth cliconfig.AuthConfig) (types.AuthResponse, error)
SystemVersion() (types.VersionResponse, error)
VolumeCreate(options types.VolumeCreateRequest) (types.Volume, error)
VolumeInspect(volumeID string) (types.Volume, error)
VolumeList(filter filters.Args) (types.VolumesListResponse, error)
VolumeRemove(volumeID string) error
}
4 changes: 2 additions & 2 deletions api/client/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
}
}

options := lib.ContainerCommitOptions{
options := types.ContainerCommitOptions{
ContainerID: name,
RepositoryName: repositoryName,
Tag: tag,
Expand Down
5 changes: 2 additions & 3 deletions api/client/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"

"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/archive"
Expand Down Expand Up @@ -126,7 +125,7 @@ func splitCpArg(arg string) (container, path string) {
}

func (cli *DockerCli) statContainerPath(containerName, path string) (types.ContainerPathStat, error) {
return cli.client.StatContainerPath(containerName, path)
return cli.client.ContainerStatPath(containerName, path)
}

func resolveLocalPath(localPath string) (absPath string, err error) {
Expand Down Expand Up @@ -286,7 +285,7 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string, cpP
content = preparedArchive
}

options := lib.CopyToContainerOptions{
options := types.CopyToContainerOptions{
ContainerID: dstContainer,
Path: resolvedDstPath,
Content: content,
Expand Down
4 changes: 2 additions & 2 deletions api/client/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error {
return err
}

options := lib.CreateImageOptions{
options := types.ImageCreateOptions{
Parent: ref.Name(),
Tag: tag,
RegistryAuth: base64.URLEncoding.EncodeToString(buf),
}

responseBody, err := cli.client.CreateImage(options)
responseBody, err := cli.client.ImageCreate(options)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions api/client/events.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonmessage"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
}
}

options := lib.EventsOptions{
options := types.EventsOptions{
Since: *since,
Until: *until,
Filters: eventFilterArgs,
Expand Down
4 changes: 2 additions & 2 deletions api/client/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
matchName = cmd.Arg(0)
}

options := lib.ImageListOptions{
options := types.ImageListOptions{
MatchName: matchName,
All: *all,
Filters: imageFilterArgs,
Expand Down
6 changes: 3 additions & 3 deletions api/client/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/client/lib"
"github.com/docker/docker/api/types"
Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonmessage"
Expand Down Expand Up @@ -67,7 +67,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {

}

options := lib.ImportImageOptions{
options := types.ImageImportOptions{
Source: in,
SourceName: srcName,
RepositoryName: repository,
Expand All @@ -76,7 +76,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
Changes: changes,
}

responseBody, err := cli.client.ImportImage(options)
responseBody, err := cli.client.ImageImport(options)
if err != nil {
return err
}
Expand Down
12 changes: 0 additions & 12 deletions api/client/lib/container_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ import (
"github.com/docker/docker/runconfig"
)

// ContainerCommitOptions hods parameters to commit changes into a container.
type ContainerCommitOptions struct {
ContainerID string
RepositoryName string
Tag string
Comment string
Author string
Changes []string
Pause bool
JSONConfig string
}

// ContainerCommit applies changes into a container and creates a new tagged image.
func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.ContainerCommitResponse, error) {
query := url.Values{}
Expand Down
14 changes: 1 addition & 13 deletions api/client/lib/container_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,8 @@ import (
"github.com/docker/docker/pkg/parsers/filters"
)

// ContainerListOptions holds parameters to list containers with.
type ContainerListOptions struct {
Quiet bool
Size bool
All bool
Latest bool
Since string
Before string
Limit int
Filter filters.Args
}

// ContainerList returns the list of containers in the docker host.
func (cli *Client) ContainerList(options ContainerListOptions) ([]types.Container, error) {
func (cli *Client) ContainerList(options types.ContainerListOptions) ([]types.Container, error) {
var query url.Values

if options.All {
Expand Down
14 changes: 5 additions & 9 deletions api/client/lib/container_remove.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package lib

import "net/url"
import (
"net/url"

// ContainerRemoveOptions holds parameters to remove containers.
type ContainerRemoveOptions struct {
ContainerID string
RemoveVolumes bool
RemoveLinks bool
Force bool
}
"github.com/docker/docker/api/types"
)

// ContainerRemove kills and removes a container from the docker host.
func (cli *Client) ContainerRemove(options ContainerRemoveOptions) error {
func (cli *Client) ContainerRemove(options types.ContainerRemoveOptions) error {
var query url.Values
if options.RemoveVolumes {
query.Set("v", "1")
Expand Down
15 changes: 3 additions & 12 deletions api/client/lib/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ import (
"github.com/docker/docker/api/types"
)

// CopyToContainerOptions holds information
// about files to copy into a container
type CopyToContainerOptions struct {
ContainerID string
Path string
Content io.Reader
AllowOverwriteDirWithFile bool
}

// StatContainerPath returns Stat information about a path inside the container filesystem.
func (cli *Client) StatContainerPath(containerID, path string) (types.ContainerPathStat, error) {
// ContainerStatPath returns Stat information about a path inside the container filesystem.
func (cli *Client) ContainerStatPath(containerID, path string) (types.ContainerPathStat, error) {
query := make(url.Values, 1)
query.Set("path", filepath.ToSlash(path)) // Normalize the paths used in the API.

Expand All @@ -37,7 +28,7 @@ func (cli *Client) StatContainerPath(containerID, path string) (types.ContainerP
}

// CopyToContainer copies content into the container filesystem.
func (cli *Client) CopyToContainer(options CopyToContainerOptions) error {
func (cli *Client) CopyToContainer(options types.CopyToContainerOptions) error {
var query url.Values
query.Set("path", filepath.ToSlash(options.Path)) // Normalize the paths used in the API.
// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
Expand Down
10 changes: 2 additions & 8 deletions api/client/lib/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ import (
"net/url"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/parsers/filters"
"github.com/docker/docker/pkg/timeutils"
)

// EventsOptions hold parameters to filter events with.
type EventsOptions struct {
Since string
Until string
Filters filters.Args
}

// Events returns a stream of events in the daemon in a ReadCloser.
// It's up to the caller to close the stream.
func (cli *Client) Events(options EventsOptions) (io.ReadCloser, error) {
func (cli *Client) Events(options types.EventsOptions) (io.ReadCloser, error) {
var query url.Values
ref := time.Now()

Expand Down
Loading

0 comments on commit 8b15839

Please sign in to comment.