add support for base path in docker cli -H
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
d5b7b9fa88
commit
3314761f62
2 changed files with 15 additions and 6 deletions
|
@ -2,6 +2,7 @@ package parsers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -52,7 +53,11 @@ func ParseTCPAddr(addr string, defaultAddr string) (string, error) {
|
||||||
return "", fmt.Errorf("Invalid proto, expected tcp: %s", addr)
|
return "", fmt.Errorf("Invalid proto, expected tcp: %s", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostParts := strings.Split(addr, ":")
|
u, err := url.Parse("tcp://" + addr)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
hostParts := strings.Split(u.Host, ":")
|
||||||
if len(hostParts) != 2 {
|
if len(hostParts) != 2 {
|
||||||
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +70,7 @@ func ParseTCPAddr(addr string, defaultAddr string) (string, error) {
|
||||||
if err != nil && p == 0 {
|
if err != nil && p == 0 {
|
||||||
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
return "", fmt.Errorf("Invalid bind address format: %s", addr)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("tcp://%s:%d", host, p), nil
|
return fmt.Sprintf("tcp://%s:%d%s", host, p, u.Path), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a repos name and returns the right reposName + tag|digest
|
// Get a repos name and returns the right reposName + tag|digest
|
||||||
|
|
|
@ -14,14 +14,18 @@ func TestParseHost(t *testing.T) {
|
||||||
"0.0.0.0": "Invalid bind address format: 0.0.0.0",
|
"0.0.0.0": "Invalid bind address format: 0.0.0.0",
|
||||||
"tcp://": "Invalid proto, expected tcp: ",
|
"tcp://": "Invalid proto, expected tcp: ",
|
||||||
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
"tcp:a.b.c.d": "Invalid bind address format: tcp:a.b.c.d",
|
||||||
|
"tcp:a.b.c.d/path": "Invalid bind address format: tcp:a.b.c.d/path",
|
||||||
"udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1",
|
"udp://127.0.0.1": "Invalid bind address format: udp://127.0.0.1",
|
||||||
"udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375",
|
"udp://127.0.0.1:2375": "Invalid bind address format: udp://127.0.0.1:2375",
|
||||||
}
|
}
|
||||||
valids := map[string]string{
|
valids := map[string]string{
|
||||||
"0.0.0.1:5555": "tcp://0.0.0.1:5555",
|
"0.0.0.1:5555": "tcp://0.0.0.1:5555",
|
||||||
":6666": "tcp://127.0.0.1:6666",
|
"0.0.0.1:5555/path": "tcp://0.0.0.1:5555/path",
|
||||||
"tcp://:7777": "tcp://127.0.0.1:7777",
|
":6666": "tcp://127.0.0.1:6666",
|
||||||
"": "unix:///var/run/docker.sock",
|
":6666/path": "tcp://127.0.0.1:6666/path",
|
||||||
|
"tcp://:7777": "tcp://127.0.0.1:7777",
|
||||||
|
"tcp://:7777/path": "tcp://127.0.0.1:7777/path",
|
||||||
|
"": "unix:///var/run/docker.sock",
|
||||||
"unix:///run/docker.sock": "unix:///run/docker.sock",
|
"unix:///run/docker.sock": "unix:///run/docker.sock",
|
||||||
"unix://": "unix:///var/run/docker.sock",
|
"unix://": "unix:///var/run/docker.sock",
|
||||||
"fd://": "fd://",
|
"fd://": "fd://",
|
||||||
|
|
Loading…
Reference in a new issue