Merge pull request #1032 from vieux/fix_match_push

fix image matching in push
This commit is contained in:
Alexandre Beslic 2015-07-14 17:02:01 -07:00
commit 02ba1fad43
2 changed files with 16 additions and 16 deletions

View File

@ -68,20 +68,6 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(version)
}
// GET /images/{name:.*}/get
func getImage(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
for _, image := range c.cluster.Images() {
if len(strings.SplitN(name, ":", 2)) == 2 && image.Match(name, true) ||
len(strings.SplitN(name, ":", 2)) == 1 && image.Match(name, false) {
proxy(c.tlsConfig, image.Engine.Addr, w, r)
return
}
}
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// GET /images/get
func getImages(c *context, w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
@ -577,6 +563,20 @@ func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// Proxy a request to the right node
func proxyImageTagOptional(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
for _, image := range c.cluster.Images() {
if len(strings.SplitN(name, ":", 2)) == 2 && image.Match(name, true) ||
len(strings.SplitN(name, ":", 2)) == 1 && image.Match(name, false) {
proxy(c.tlsConfig, image.Engine.Addr, w, r)
return
}
}
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// Proxy a request to the right node and force refresh
func proxyImageAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]

View File

@ -30,7 +30,7 @@ var routes = map[string]map[string]handler{
"/images/viz": notImplementedHandler,
"/images/search": proxyRandom,
"/images/get": getImages,
"/images/{name:.*}/get": getImage,
"/images/{name:.*}/get": proxyImageTagOptional,
"/images/{name:.*}/history": proxyImage,
"/images/{name:.*}/json": proxyImage,
"/containers/ps": getContainersJSON,
@ -50,7 +50,7 @@ var routes = map[string]map[string]handler{
"/build": proxyRandomAndForceRefresh,
"/images/create": postImagesCreate,
"/images/load": postImagesLoad,
"/images/{name:.*}/push": proxyImage,
"/images/{name:.*}/push": proxyImageTagOptional,
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
"/containers/create": postContainersCreate,
"/containers/{name:.*}/kill": proxyContainerAndForceRefresh,