summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess Frazelle <jfrazelle@users.noreply.github.com>2015-09-23 16:52:39 -0700
committerJess Frazelle <jfrazelle@users.noreply.github.com>2015-09-23 16:52:39 -0700
commitddd0c47412dd30f1d333b5bd53e22c9949d1e86f (patch)
tree7562ea890fbeea209708e8ed2629ea508920c65a
parentd71ae4577293e6600447433126f4034d80d85ddb (diff)
parent8aef1a33eb730a7c9b7e92b688bc63e6a3c69f62 (diff)
downloaddocker-ddd0c47412dd30f1d333b5bd53e22c9949d1e86f.tar.gz
Merge pull request #16497 from MHBauer/attach-refactor-new
refactor attach to not use internal data structures
-rw-r--r--api/server/container.go16
-rw-r--r--daemon/attach.go13
2 files changed, 19 insertions, 10 deletions
diff --git a/api/server/container.go b/api/server/container.go
index 15817e0089..c4ea19d9b2 100644
--- a/api/server/container.go
+++ b/api/server/container.go
@@ -444,10 +444,10 @@ func (s *Server) postContainersAttach(ctx context.Context, w http.ResponseWriter
if vars == nil {
return fmt.Errorf("Missing parameter")
}
+ containerName := vars["name"]
- cont, err := s.daemon.Get(vars["name"])
- if err != nil {
- return err
+ if !s.daemon.Exists(containerName) {
+ return derr.ErrorCodeNoSuchContainer.WithArgs(containerName)
}
inStream, outStream, err := hijackServer(w)
@@ -472,7 +472,7 @@ func (s *Server) postContainersAttach(ctx context.Context, w http.ResponseWriter
Stream: boolValue(r, "stream"),
}
- if err := s.daemon.ContainerAttachWithLogs(cont, attachWithLogsConfig); err != nil {
+ if err := s.daemon.ContainerAttachWithLogs(containerName, attachWithLogsConfig); err != nil {
fmt.Fprintf(outStream, "Error attaching: %s\n", err)
}
@@ -486,10 +486,10 @@ func (s *Server) wsContainersAttach(ctx context.Context, w http.ResponseWriter,
if vars == nil {
return fmt.Errorf("Missing parameter")
}
+ containerName := vars["name"]
- cont, err := s.daemon.Get(vars["name"])
- if err != nil {
- return err
+ if !s.daemon.Exists(containerName) {
+ return derr.ErrorCodeNoSuchContainer.WithArgs(containerName)
}
h := websocket.Handler(func(ws *websocket.Conn) {
@@ -503,7 +503,7 @@ func (s *Server) wsContainersAttach(ctx context.Context, w http.ResponseWriter,
Stream: boolValue(r, "stream"),
}
- if err := s.daemon.ContainerWsAttachWithLogs(cont, wsAttachWithLogsConfig); err != nil {
+ if err := s.daemon.ContainerWsAttachWithLogs(containerName, wsAttachWithLogsConfig); err != nil {
logrus.Errorf("Error attaching websocket: %s", err)
}
})
diff --git a/daemon/attach.go b/daemon/attach.go
index 5d8d283f52..3ffc6d6be1 100644
--- a/daemon/attach.go
+++ b/daemon/attach.go
@@ -15,7 +15,12 @@ type ContainerAttachWithLogsConfig struct {
}
// ContainerAttachWithLogs attaches to logs according to the config passed in. See ContainerAttachWithLogsConfig.
-func (daemon *Daemon) ContainerAttachWithLogs(container *Container, c *ContainerAttachWithLogsConfig) error {
+func (daemon *Daemon) ContainerAttachWithLogs(prefixOrName string, c *ContainerAttachWithLogsConfig) error {
+ container, err := daemon.Get(prefixOrName)
+ if err != nil {
+ return err
+ }
+
var errStream io.Writer
if !container.Config.Tty {
@@ -50,6 +55,10 @@ type ContainerWsAttachWithLogsConfig struct {
}
// ContainerWsAttachWithLogs websocket connection
-func (daemon *Daemon) ContainerWsAttachWithLogs(container *Container, c *ContainerWsAttachWithLogsConfig) error {
+func (daemon *Daemon) ContainerWsAttachWithLogs(prefixOrName string, c *ContainerWsAttachWithLogsConfig) error {
+ container, err := daemon.Get(prefixOrName)
+ if err != nil {
+ return err
+ }
return container.attachWithLogs(c.InStream, c.OutStream, c.ErrStream, c.Logs, c.Stream)
}