add search and login

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-01-14 21:29:26 +00:00
parent 3f55099c06
commit 93d63a3fea
3 changed files with 19 additions and 13 deletions

View File

@ -10,14 +10,12 @@ Here are the main differences:
``` ```
GET "/images/json" GET "/images/json"
GET "/images/json" GET "/images/json"
GET "/images/search"
GET "/images/get" GET "/images/get"
GET "/images/{name:.*}/get" GET "/images/{name:.*}/get"
GET "/images/{name:.*}/history" GET "/images/{name:.*}/history"
GET "/images/{name:.*}/json" GET "/images/{name:.*}/json"
GET "/containers/{name:.*}/attach/ws" GET "/containers/{name:.*}/attach/ws"
POST "/auth"
POST "/commit" POST "/commit"
POST "/build" POST "/build"
POST "/images/create" POST "/images/create"

View File

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"net/http" "net/http"
"runtime" "runtime"
"sort" "sort"
@ -229,7 +230,7 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
return return
} }
if err := proxy(c.tlsConfig, container, w, r); err != nil { if err := proxy(c.tlsConfig, container.Node.Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError) httpError(w, err.Error(), http.StatusInternalServerError)
} }
@ -245,7 +246,16 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
return return
} }
if err := proxy(c.tlsConfig, container, w, r); err != nil { if err := proxy(c.tlsConfig, container.Node.Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
}
// Proxy a request to a random node
func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) {
nodes := c.cluster.Nodes()
if err := proxy(c.tlsConfig, nodes[rand.Intn(len(nodes))].Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError) httpError(w, err.Error(), http.StatusInternalServerError)
} }
} }
@ -258,7 +268,7 @@ func proxyHijack(c *context, w http.ResponseWriter, r *http.Request) {
return return
} }
if err := hijack(c.tlsConfig, container, w, r); err != nil { if err := hijack(c.tlsConfig, container.Node.Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError) httpError(w, err.Error(), http.StatusInternalServerError)
} }
} }
@ -293,7 +303,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
"/version": getVersion, "/version": getVersion,
"/images/json": notImplementedHandler, "/images/json": notImplementedHandler,
"/images/viz": notImplementedHandler, "/images/viz": notImplementedHandler,
"/images/search": notImplementedHandler, "/images/search": proxyRandom,
"/images/get": notImplementedHandler, "/images/get": notImplementedHandler,
"/images/{name:.*}/get": notImplementedHandler, "/images/{name:.*}/get": notImplementedHandler,
"/images/{name:.*}/history": notImplementedHandler, "/images/{name:.*}/history": notImplementedHandler,
@ -309,7 +319,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
"/exec/{execid:.*}/json": proxyContainer, "/exec/{execid:.*}/json": proxyContainer,
}, },
"POST": { "POST": {
"/auth": notImplementedHandler, "/auth": proxyRandom,
"/commit": notImplementedHandler, "/commit": notImplementedHandler,
"/build": notImplementedHandler, "/build": notImplementedHandler,
"/images/create": notImplementedHandler, "/images/create": notImplementedHandler,

View File

@ -51,15 +51,14 @@ func copyHeader(dst, src http.Header) {
} }
} }
func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error { func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
// Use a new client for each request // Use a new client for each request
client, scheme := newClientAndScheme(tlsConfig) client, scheme := newClientAndScheme(tlsConfig)
// RequestURI may not be sent to client // RequestURI may not be sent to client
r.RequestURI = "" r.RequestURI = ""
r.URL.Scheme = scheme r.URL.Scheme = scheme
r.URL.Host = addr
r.URL.Host = container.Node.Addr
log.Debugf("[PROXY] --> %s %s", r.Method, r.URL) log.Debugf("[PROXY] --> %s %s", r.Method, r.URL)
resp, err := client.Do(r) resp, err := client.Do(r)
@ -74,9 +73,8 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
return nil return nil
} }
func hijack(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error { func hijack(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
addr := container.Node.Addr if parts := strings.SplitN(addr, "://", 2); len(parts) == 2 {
if parts := strings.SplitN(container.Node.Addr, "://", 2); len(parts) == 2 {
addr = parts[1] addr = parts[1]
} }