mirror of https://github.com/docker/docs.git
Verifying the --swarm-discovery flag
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
This commit is contained in:
parent
4a8e93ac9b
commit
fb0af73b80
|
@ -3,6 +3,7 @@ package commands
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
|
|
||||||
|
@ -35,6 +36,10 @@ func cmdCreate(c *cli.Context) {
|
||||||
log.Fatal("You must specify a machine name")
|
log.Fatal("You must specify a machine name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := validateSwarmDiscovery(c.String("swarm-discovery")); err != nil {
|
||||||
|
log.Fatalf("Error parsing swarm discovery: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
certInfo := getCertPathInfo(c)
|
certInfo := getCertPathInfo(c)
|
||||||
|
|
||||||
if err := setupCertificates(
|
if err := setupCertificates(
|
||||||
|
@ -118,3 +123,20 @@ func trimDriverFlags(driver string, cmds []cli.Command) ([]cli.Command, error) {
|
||||||
|
|
||||||
return filteredCmds, nil
|
return filteredCmds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateSwarmDiscovery(discovery string) error {
|
||||||
|
if discovery == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
matched, err := regexp.MatchString(`[^:]*://.*`, discovery)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if matched {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Swarm Discovery URL was in the wrong format: %s", discovery)
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,22 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateSwarmDiscoveryErrorsGivenInvalidURL(t *testing.T) {
|
||||||
|
err := validateSwarmDiscovery("foo")
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateSwarmDiscoveryAcceptsEmptyString(t *testing.T) {
|
||||||
|
err := validateSwarmDiscovery("")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateSwarmDiscoveryAcceptsValidFormat(t *testing.T) {
|
||||||
|
err := validateSwarmDiscovery("token://deadbeefcafe")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue