mirror of https://github.com/docker/docs.git
Merge pull request #859 from nathanleclaire/validate_hostname
Fix location of validating hostname functionality
This commit is contained in:
commit
aa031ec759
|
@ -92,11 +92,8 @@ func LoadHost(name string, StorePath string) (*Host, error) {
|
||||||
return host, nil
|
return host, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateHostName(name string) (string, error) {
|
func ValidateHostName(name string) bool {
|
||||||
if !validHostNamePattern.MatchString(name) {
|
return validHostNamePattern.MatchString(name)
|
||||||
return name, ErrInvalidHostname
|
|
||||||
}
|
|
||||||
return name, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Host) Create(name string) error {
|
func (h *Host) Create(name string) error {
|
||||||
|
|
|
@ -122,13 +122,9 @@ func TestValidateHostnameValid(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range hosts {
|
for _, v := range hosts {
|
||||||
h, err := ValidateHostName(v)
|
isValid := ValidateHostName(v)
|
||||||
if err != nil {
|
if !isValid {
|
||||||
t.Fatal("Invalid hostname")
|
t.Fatal("Thought a valid hostname was invalid: %s", v)
|
||||||
}
|
|
||||||
|
|
||||||
if h != v {
|
|
||||||
t.Fatal("Hostname doesn't match")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,9 +137,9 @@ func TestValidateHostnameInvalid(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range hosts {
|
for _, v := range hosts {
|
||||||
_, err := ValidateHostName(v)
|
isValid := ValidateHostName(v)
|
||||||
if err == nil {
|
if isValid {
|
||||||
t.Fatal("No error returned")
|
t.Fatal("Thought an invalid hostname was valid: %s", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,10 @@ func New(store Store) (*Machine, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) {
|
func (m *Machine) Create(name string, driverName string, hostOptions *HostOptions, driverConfig drivers.DriverOptions) (*Host, error) {
|
||||||
|
validName := ValidateHostName(name)
|
||||||
|
if !validName {
|
||||||
|
return nil, ErrInvalidHostname
|
||||||
|
}
|
||||||
exists, err := m.store.Exists(name)
|
exists, err := m.store.Exists(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue