Skip to content

Commit

Permalink
Accept to create a host using an ip as name by relaxing unix_user con…
Browse files Browse the repository at this point in the history
…straint on name and not splitting on `.` if an ip is detected.
  • Loading branch information
jle64 committed Jun 7, 2019
1 parent cafac0b commit 4adaf83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/bastion/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"os"
"regexp"
"runtime"
"strings"
"time"
Expand Down Expand Up @@ -685,7 +686,16 @@ GLOBAL OPTIONS:
if c.String("password") != "" {
host.Password = c.String("password")
}
host.Name = strings.Split(host.Hostname(), ".")[0]
matched, err := regexp.MatchString(`^([0-9]{1,3}.){3}.([0-9]{1,3})$`, host.Hostname())
if err != nil {
return err
}
if matched {
host.Name = host.Hostname()
} else {
host.Name = strings.Split(host.Hostname(), ".")[0]
}

if c.String("hop") != "" {
hop, err := dbmodels.HostByName(db, c.String("hop"))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dbmodels/dbmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type SSHKey struct {
type Host struct {
// FIXME: use uuid for ID
gorm.Model
Name string `gorm:"size:32" valid:"required,length(1|32),unix_user"`
Name string `gorm:"size:32" valid:"required,length(1|32)"`
Addr string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
User string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
Password string `valid:"optional"` // FIXME: to be removed in a future version in favor of URL
Expand Down

0 comments on commit 4adaf83

Please sign in to comment.