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
|
||||
}
|
||||
|
||||
func ValidateHostName(name string) (string, error) {
|
||||
if !validHostNamePattern.MatchString(name) {
|
||||
return name, ErrInvalidHostname
|
||||
}
|
||||
return name, nil
|
||||
func ValidateHostName(name string) bool {
|
||||
return validHostNamePattern.MatchString(name)
|
||||
}
|
||||
|
||||
func (h *Host) Create(name string) error {
|
||||
|
|
|
@ -122,13 +122,9 @@ func TestValidateHostnameValid(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, v := range hosts {
|
||||
h, err := ValidateHostName(v)
|
||||
if err != nil {
|
||||
t.Fatal("Invalid hostname")
|
||||
}
|
||||
|
||||
if h != v {
|
||||
t.Fatal("Hostname doesn't match")
|
||||
isValid := ValidateHostName(v)
|
||||
if !isValid {
|
||||
t.Fatal("Thought a valid hostname was invalid: %s", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,9 +137,9 @@ func TestValidateHostnameInvalid(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, v := range hosts {
|
||||
_, err := ValidateHostName(v)
|
||||
if err == nil {
|
||||
t.Fatal("No error returned")
|
||||
isValid := ValidateHostName(v)
|
||||
if isValid {
|
||||
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) {
|
||||
validName := ValidateHostName(name)
|
||||
if !validName {
|
||||
return nil, ErrInvalidHostname
|
||||
}
|
||||
exists, err := m.store.Exists(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue