mirror of https://github.com/docker/docs.git
allow hostnames in join
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
01633efaa0
commit
bcbd0fec0f
10
join.go
10
join.go
|
@ -9,6 +9,11 @@ import (
|
||||||
"github.com/docker/swarm/discovery"
|
"github.com/docker/swarm/discovery"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkAddrFormat(addr string) bool {
|
||||||
|
m, _ := regexp.MatchString("^[0-9a-zA-Z._-]+:[0-9]{1,5}$", addr)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func join(c *cli.Context) {
|
func join(c *cli.Context) {
|
||||||
|
|
||||||
if c.String("discovery") == "" {
|
if c.String("discovery") == "" {
|
||||||
|
@ -21,8 +26,9 @@ func join(c *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := c.String("addr")
|
addr := c.String("addr")
|
||||||
if m, _ := regexp.MatchString("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}$", addr); !m {
|
|
||||||
log.Fatal("--addr should be of the form ip:port")
|
if !checkAddrFormat(addr) {
|
||||||
|
log.Fatal("--addr should be of the form ip:port or hostname:port")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.Register(addr); err != nil {
|
if err := d.Register(addr); err != nil {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCheckAddrFormat(t *testing.T) {
|
||||||
|
assert.False(t, checkAddrFormat("1.1.1.1"))
|
||||||
|
assert.False(t, checkAddrFormat("hostname"))
|
||||||
|
assert.False(t, checkAddrFormat("1.1.1.1:"))
|
||||||
|
assert.False(t, checkAddrFormat("hostname:"))
|
||||||
|
assert.False(t, checkAddrFormat("1.1.1.1:111111"))
|
||||||
|
assert.False(t, checkAddrFormat("hostname:111111"))
|
||||||
|
assert.False(t, checkAddrFormat("http://1.1.1.1"))
|
||||||
|
assert.False(t, checkAddrFormat("http://hostname"))
|
||||||
|
assert.False(t, checkAddrFormat("http://1.1.1.1:1"))
|
||||||
|
assert.False(t, checkAddrFormat("http://hostname:1"))
|
||||||
|
assert.False(t, checkAddrFormat(":1.1.1.1"))
|
||||||
|
assert.False(t, checkAddrFormat(":hostname"))
|
||||||
|
assert.False(t, checkAddrFormat(":1.1.1.1:1"))
|
||||||
|
assert.False(t, checkAddrFormat(":hostname:1"))
|
||||||
|
assert.True(t, checkAddrFormat("1.1.1.1:1111"))
|
||||||
|
assert.True(t, checkAddrFormat("hostname:1111"))
|
||||||
|
assert.True(t, checkAddrFormat("host-name_42:1111"))
|
||||||
|
}
|
Loading…
Reference in New Issue