Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func main() {

app.HelpName = "help"
app.Flags = []cli.Flag{
cli.BoolTFlag{
Name: "non-strict",
EnvVar: "SSHED_NON_STRICT",
Usage: "disable strict mode, does not check the commented hosts only",
},
cli.StringFlag{
Name: "keychain",
EnvVar: "SSHED_KEYCHAIN",
Expand Down Expand Up @@ -60,7 +65,7 @@ func main() {
}

var err error
ssh.Config, err = ssh.Parse(context.String("config"))
ssh.Config, err = ssh.Parse(context.String("config"), context.IsSet("non-strict") && context.Bool("non-strict") == true))
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ func (cmds *Commands) createCommand(c *cli.Context, srv *host.Host, options *opt
args = append(args, cmds.bin)
args = append(args, fmt.Sprintf("-F %s", ssh.Config.Path))

if len(srv.Options) > 0 {
for k, v := range srv.Options {
if options.verbose == true {
fmt.Printf("%s: %s\r\n", ansi.Color(k, "green"), v)
}
args = append(args, fmt.Sprintf("-o %s=%s", k, v))
}
}

if pk := srv.PrivateKey(); pk != "" {
tf, err := ioutil.TempFile("", "")
defer os.Remove(tf.Name())
Expand Down Expand Up @@ -192,6 +201,7 @@ func (cmds *Commands) createCommand(c *cli.Context, srv *host.Host, options *opt
args = append(args, fmt.Sprintf("-i %s", srv.IdentityFile))
}


if options.verbose == true {
args = append(args, "-v")
}
Expand Down
48 changes: 25 additions & 23 deletions ssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type sshConfig struct {
cfg *ssh_config.Config
}

func Parse(path string) (conf *sshConfig, err error) {
func Parse(path string, nonStrict bool) (conf *sshConfig, err error) {
conf = &sshConfig{Path: path}

if _, err := os.Stat(conf.Path); os.IsNotExist(err) == false {
Expand All @@ -48,32 +48,34 @@ func Parse(path string) (conf *sshConfig, err error) {
}

for _, h := range conf.cfg.Hosts {
for _, pattern := range h.Patterns {
if maskPatternRegexp.MatchString(pattern.String()) == false {
conf.Hosts = append(conf.Hosts, pattern.String())
if h.EOLComment == " -- added by sshed" || nonStrict == true {
for _, pattern := range h.Patterns {
if maskPatternRegexp.MatchString(pattern.String()) == false {
conf.Hosts = append(conf.Hosts, pattern.String())
}
}
}

for _, node := range h.Nodes {
switch node.(type) {
case *ssh_config.KV:
key := node.(*ssh_config.KV).Key
if key != "IdentityFile" {
continue
}
for _, node := range h.Nodes {
switch node.(type) {
case *ssh_config.KV:
key := node.(*ssh_config.KV).Key
if key != "IdentityFile" {
continue
}

path = node.(*ssh_config.KV).Value
exists := false
for _, v := range conf.Keys {
v = convertTilde(v)
path = convertTilde(path)
if v == path {
exists = true
break
path = node.(*ssh_config.KV).Value
exists := false
for _, v := range conf.Keys {
v = convertTilde(v)
path = convertTilde(path)
if v == path {
exists = true
break
}
}
if exists == false {
conf.Keys = append(conf.Keys, path)
}
}
if exists == false {
conf.Keys = append(conf.Keys, path)
}
}
}
Expand Down