Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using SshConfigFileConfiguration if the configuration has not defined "identityfile" #35

Open
rkmax opened this issue Oct 5, 2014 · 3 comments

Comments

@rkmax
Copy link
Contributor

rkmax commented Oct 5, 2014

I suggets use the same behavior the SSH if i have a host configurate in ~/.ssh/config file like this

Host mytest
Hostname ssh.mytest.com
User testing
Port 5022

the method SshConfigFileConfiguration::getAuthentication must check first if a ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub exist and use at last Authentication\None

modifing the method SshConfigFileConfiguration::getConfigForHost like this

class SshConfigFileConfiguration extends Configuration
{
     const DEFAULT_FILE = '~/.ssh/id_rsa';
     // ...
     public function getConfigForHost($host)
    {
        $matches = array();
        foreach ($this->configs as $config) {
            if (fnmatch($config['host'], $host)) {
                $matches[] = $config;
            }
        }
        if (count($matches) == 0) {
            throw new RuntimeException("Unable to find configuration for host '{$host}'");
        }
        usort($matches, function ($a, $b) {
            return strlen($a['host']) > strlen($b['host']);
        });
        $result = array();
        foreach ($matches as $match) {
            $result = array_merge($result, $match);
        }
        unset($result['host']);
        if (isset($result['identityfile'])) {
            $result['identityfile'] = $this->processPath($result['identityfile']);
        } else if (file_exists($file = $this->processPath(self::DEFAULT_FILE))) {
            $result['identityfile'] = $file;
        }

        return $result;
    }
}

solves the problem quickly

@Herzult
Copy link
Owner

Herzult commented Oct 5, 2014

It would be awesome if you could do a PR.

@rkmax
Copy link
Contributor Author

rkmax commented Oct 5, 2014

@Herzult i made it, can you merge please, i have other PR to send you ;)

@CharlyP
Copy link

CharlyP commented Oct 8, 2014

@Herzult would really appreciate this related PR to be merged, need the feature ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants