no more name encoding

This commit is contained in:
Victor Vieux 2013-10-17 23:22:14 +00:00
parent c4923757f1
commit 256b7537e3
3 changed files with 22 additions and 32 deletions

16
api.go
View file

@ -15,7 +15,6 @@ import (
"mime"
"net"
"net/http"
"net/url"
"os"
"os/exec"
"regexp"
@ -156,7 +155,6 @@ func postContainersKill(srv *Server, version float64, w http.ResponseWriter, r *
}
}
}
name = decodeName(name)
if err := srv.ContainerKill(name, signal); err != nil {
return err
}
@ -169,7 +167,6 @@ func getContainersExport(srv *Server, version float64, w http.ResponseWriter, r
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
if err := srv.ContainerExport(name, w); err != nil {
utils.Errorf("%s", err)
@ -580,7 +577,6 @@ func postContainersRestart(srv *Server, version float64, w http.ResponseWriter,
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
if err := srv.ContainerRestart(name, t); err != nil {
return err
}
@ -596,7 +592,6 @@ func deleteContainers(srv *Server, version float64, w http.ResponseWriter, r *ht
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
removeVolume, err := getBoolParam(r.Form.Get("v"))
if err != nil {
@ -654,7 +649,6 @@ func postContainersStart(srv *Server, version float64, w http.ResponseWriter, r
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
if err := srv.ContainerStart(name, hostConfig); err != nil {
return err
}
@ -675,7 +669,6 @@ func postContainersStop(srv *Server, version float64, w http.ResponseWriter, r *
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
if err := srv.ContainerStop(name, t); err != nil {
return err
@ -689,7 +682,6 @@ func postContainersWait(srv *Server, version float64, w http.ResponseWriter, r *
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
status, err := srv.ContainerWait(name)
if err != nil {
@ -750,7 +742,6 @@ func postContainersAttach(srv *Server, version float64, w http.ResponseWriter, r
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
c, err := srv.ContainerInspect(name)
if err != nil {
@ -823,7 +814,6 @@ func wsContainersAttach(srv *Server, version float64, w http.ResponseWriter, r *
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
if _, err := srv.ContainerInspect(name); err != nil {
return err
@ -846,7 +836,6 @@ func getContainersByName(srv *Server, version float64, w http.ResponseWriter, r
return fmt.Errorf("Missing parameter")
}
name := vars["name"]
name = decodeName(name)
container, err := srv.ContainerInspect(name)
if err != nil {
@ -1097,11 +1086,6 @@ func postContainerLink(srv *Server, version float64, w http.ResponseWriter, r *h
return nil
}
func decodeName(name string) string {
s, _ := url.QueryUnescape(name)
return s
}
func createRouter(srv *Server, logging bool) (*mux.Router, error) {
r := mux.NewRouter()

View file

@ -23,6 +23,7 @@ import (
"os/signal"
"path/filepath"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
@ -504,8 +505,7 @@ func (cli *DockerCli) CmdStop(args ...string) error {
v.Set("t", strconv.Itoa(*nSeconds))
for _, name := range cmd.Args() {
encName := cleanName(name)
_, _, err := cli.call("POST", "/containers/"+encName+"/stop?"+v.Encode(), nil)
_, _, err := cli.call("POST", "/containers/"+name+"/stop?"+v.Encode(), nil)
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
} else {
@ -530,8 +530,7 @@ func (cli *DockerCli) CmdRestart(args ...string) error {
v.Set("t", strconv.Itoa(*nSeconds))
for _, name := range cmd.Args() {
encName := cleanName(name)
_, _, err := cli.call("POST", "/containers/"+encName+"/restart?"+v.Encode(), nil)
_, _, err := cli.call("POST", "/containers/"+name+"/restart?"+v.Encode(), nil)
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
} else {
@ -607,8 +606,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
var encounteredError error
for _, name := range cmd.Args() {
encName := cleanName(name)
_, _, err := cli.call("POST", "/containers/"+encName+"/start", nil)
_, _, err := cli.call("POST", "/containers/"+name+"/start", nil)
if err != nil {
if !*attach || !*openStdin {
fmt.Fprintf(cli.err, "%s\n", err)
@ -831,8 +829,7 @@ func (cli *DockerCli) CmdRm(args ...string) error {
val.Set("link", "1")
}
for _, name := range cmd.Args() {
encName := cleanName(name)
_, _, err := cli.call("DELETE", "/containers/"+encName+"?"+val.Encode(), nil)
_, _, err := cli.call("DELETE", "/containers/"+name+"?"+val.Encode(), nil)
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
} else {
@ -854,8 +851,7 @@ func (cli *DockerCli) CmdKill(args ...string) error {
}
for _, name := range args {
encName := cleanName(name)
_, _, err := cli.call("POST", "/containers/"+encName+"/kill", nil)
_, _, err := cli.call("POST", "/containers/"+name+"/kill", nil)
if err != nil {
fmt.Fprintf(cli.err, "%s\n", err)
} else {
@ -1363,7 +1359,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
cmd.Usage()
return nil
}
name := cleanName(cmd.Arg(0))
name := cmd.Arg(0)
if err := cli.hijack("POST", "/containers/"+name+"/attach?logs=1&stdout=1&stderr=1", false, nil, cli.out, cli.err, nil); err != nil {
return err
@ -1383,7 +1379,6 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
return nil
}
name := cmd.Arg(0)
name = cleanName(name)
body, _, err := cli.call("GET", "/containers/"+name+"/json", nil)
if err != nil {
return err
@ -1799,6 +1794,10 @@ func (cli *DockerCli) call(method, path string, data interface{}) ([]byte, int,
params = bytes.NewBuffer(buf)
}
// fixme: refactor client to support redirect
re := regexp.MustCompile("/+")
path = re.ReplaceAllString(path, "/")
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), params)
if err != nil {
return nil, -1, err
@ -1845,6 +1844,11 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer, h
if (method == "POST" || method == "PUT") && in == nil {
in = bytes.NewReader([]byte{})
}
// fixme: refactor client to support redirect
re := regexp.MustCompile("/+")
path = re.ReplaceAllString(path, "/")
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), in)
if err != nil {
return err
@ -1901,6 +1905,9 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer, h
}
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan bool) error {
// fixme: refactor client to support redirect
re := regexp.MustCompile("/+")
path = re.ReplaceAllString(path, "/")
req, err := http.NewRequest(method, fmt.Sprintf("/v%g%s", APIVERSION, path), nil)
if err != nil {
@ -2081,10 +2088,6 @@ func getExitCode(cli *DockerCli, containerId string) (bool, int, error) {
return c.State.Running, c.State.ExitCode, nil
}
func cleanName(name string) string {
return strings.Replace(name, "/", "%252F", -1)
}
func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string) *DockerCli {
var (
isTerminal = false

View file

@ -66,6 +66,9 @@ func (runtime *Runtime) getContainerElement(id string) *list.Element {
// Get looks for a container by the specified ID or name, and returns it.
// If the container is not found, or if an error occurs, nil is returned.
func (runtime *Runtime) Get(name string) *Container {
if name[0] != '/' {
name = "/" + name
}
if c, _ := runtime.GetByName(name); c != nil {
return c
}