Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -251,6 +252,11 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
wf := NewWriteFlusher(w)

if image := r.Form.Get("fromImage"); image != "" { //pull
authConfig := dockerclient.AuthConfig{}
buf, err := base64.URLEncoding.DecodeString(r.Header.Get("X-Registry-Auth"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, however I was wondering why passing the auth only when using fromImage?

If we receive a X-Registry-Auth from the client, shouldn't we always pass it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when fromImage is not provided it means import, and we don't need authConfig for import

if err == nil {
json.Unmarshal(buf, &authConfig)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)

Expand All @@ -264,7 +270,7 @@ func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(wf, "{%q:%q,%q:\"Pulling %s... : %s\",%q:{}}", "id", what, "status", image, status, "progressDetail")
}
}
c.cluster.Pull(image, callback)
c.cluster.Pull(image, &authConfig, callback)
} else { //import
httpError(w, "Not supported in clustering mode.", http.StatusNotImplemented)
}
Expand Down
5 changes: 3 additions & 2 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cluster

import (
"github.com/samalba/dockerclient"
"io"

"github.com/samalba/dockerclient"
)

// Cluster is exported
Expand Down Expand Up @@ -32,7 +33,7 @@ type Cluster interface {
// `callback` can be called multiple time
// `what` is what is being pulled
// `status` is the current status, like "", "in progress" or "downloaded
Pull(name string, callback func(what, status string))
Pull(name string, authConfig *dockerclient.AuthConfig, callback func(what, status string))

// Load images
// `callback` can be called multiple time
Expand Down
6 changes: 3 additions & 3 deletions cluster/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (e *Engine) Create(config *dockerclient.ContainerConfig, name string, pullI
return nil, err
}
// Otherwise, try to pull the image...
if err = e.Pull(config.Image); err != nil {
if err = e.Pull(config.Image, nil); err != nil {
return nil, err
}
// ...And try agaie.
Expand Down Expand Up @@ -402,11 +402,11 @@ func (e *Engine) Destroy(container *Container, force bool) error {
}

// Pull an image on the engine
func (e *Engine) Pull(image string) error {
func (e *Engine) Pull(image string, authConfig *dockerclient.AuthConfig) error {
if !strings.Contains(image, ":") {
image = image + ":latest"
}
if err := e.client.PullImage(image, nil); err != nil {
if err := e.client.PullImage(image, authConfig); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions cluster/swarm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *Cluster) RemoveImage(image *cluster.Image) ([]*dockerclient.ImageDelete
}

// Pull is exported
func (c *Cluster) Pull(name string, callback func(what, status string)) {
func (c *Cluster) Pull(name string, authConfig *dockerclient.AuthConfig, callback func(what, status string)) {
var wg sync.WaitGroup

c.RLock()
Expand All @@ -225,7 +225,7 @@ func (c *Cluster) Pull(name string, callback func(what, status string)) {
if callback != nil {
callback(nn.Name, "")
}
err := nn.Pull(name)
err := nn.Pull(name, authConfig)
if callback != nil {
if err != nil {
callback(nn.Name, err.Error())
Expand Down