From b25247ce25f9d3e1e6b59c2db7355830fa7e4780 Mon Sep 17 00:00:00 2001 From: Fabrizio Branca Date: Fri, 10 Feb 2017 19:32:56 +0000 Subject: [PATCH] Added fallback for $HOME/keys/ --- src/AwsInspector/Model/Ec2/Instance.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AwsInspector/Model/Ec2/Instance.php b/src/AwsInspector/Model/Ec2/Instance.php index 66e5131..48d38fc 100644 --- a/src/AwsInspector/Model/Ec2/Instance.php +++ b/src/AwsInspector/Model/Ec2/Instance.php @@ -5,6 +5,7 @@ use AwsInspector\Helper\Curl; use AwsInspector\Ssh\Connection; use AwsInspector\Ssh\PrivateKey; +use Symfony\Component\Filesystem\Exception\FileNotFoundException; /** * Class Instance @@ -74,7 +75,11 @@ public function getPrivateKey() return null; // throw new \Exception('No KeyName found'); } - return PrivateKey::get('keys/' . $keyName . '.pem'); + try { + return PrivateKey::get('keys/' . $keyName . '.pem'); + } catch(FileNotFoundException $e) { + return PrivateKey::get($_SERVER['HOME'] . '/keys/' . $keyName . '.pem'); + } } /**