mirror of https://github.com/docker/docs.git
add search and login
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
3f55099c06
commit
93d63a3fea
|
|
@ -10,14 +10,12 @@ Here are the main differences:
|
|||
```
|
||||
GET "/images/json"
|
||||
GET "/images/json"
|
||||
GET "/images/search"
|
||||
GET "/images/get"
|
||||
GET "/images/{name:.*}/get"
|
||||
GET "/images/{name:.*}/history"
|
||||
GET "/images/{name:.*}/json"
|
||||
GET "/containers/{name:.*}/attach/ws"
|
||||
|
||||
POST "/auth"
|
||||
POST "/commit"
|
||||
POST "/build"
|
||||
POST "/images/create"
|
||||
|
|
|
|||
20
api/api.go
20
api/api.go
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sort"
|
||||
|
|
@ -229,7 +230,7 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
|
|||
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)
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +246,16 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -258,7 +268,7 @@ func proxyHijack(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -293,7 +303,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
|
|||
"/version": getVersion,
|
||||
"/images/json": notImplementedHandler,
|
||||
"/images/viz": notImplementedHandler,
|
||||
"/images/search": notImplementedHandler,
|
||||
"/images/search": proxyRandom,
|
||||
"/images/get": notImplementedHandler,
|
||||
"/images/{name:.*}/get": notImplementedHandler,
|
||||
"/images/{name:.*}/history": notImplementedHandler,
|
||||
|
|
@ -309,7 +319,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
|
|||
"/exec/{execid:.*}/json": proxyContainer,
|
||||
},
|
||||
"POST": {
|
||||
"/auth": notImplementedHandler,
|
||||
"/auth": proxyRandom,
|
||||
"/commit": notImplementedHandler,
|
||||
"/build": notImplementedHandler,
|
||||
"/images/create": notImplementedHandler,
|
||||
|
|
|
|||
10
api/utils.go
10
api/utils.go
|
|
@ -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
|
||||
client, scheme := newClientAndScheme(tlsConfig)
|
||||
// RequestURI may not be sent to client
|
||||
r.RequestURI = ""
|
||||
|
||||
r.URL.Scheme = scheme
|
||||
|
||||
r.URL.Host = container.Node.Addr
|
||||
r.URL.Host = addr
|
||||
|
||||
log.Debugf("[PROXY] --> %s %s", r.Method, r.URL)
|
||||
resp, err := client.Do(r)
|
||||
|
|
@ -74,9 +73,8 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
|
|||
return nil
|
||||
}
|
||||
|
||||
func hijack(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error {
|
||||
addr := container.Node.Addr
|
||||
if parts := strings.SplitN(container.Node.Addr, "://", 2); len(parts) == 2 {
|
||||
func hijack(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
|
||||
if parts := strings.SplitN(addr, "://", 2); len(parts) == 2 {
|
||||
addr = parts[1]
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue