From 90d8e236b5574be1adb92e02fcec9663f1baabd2 Mon Sep 17 00:00:00 2001 From: Fabrizio Branca Date: Wed, 14 Dec 2016 12:46:25 +0000 Subject: [PATCH] Throws exception if bastion selector does not match any instance --- src/AwsInspector/Command/Ec2/SshCommand.php | 2 +- src/AwsInspector/Model/Ec2/Instance.php | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/AwsInspector/Command/Ec2/SshCommand.php b/src/AwsInspector/Command/Ec2/SshCommand.php index bf1752d..ee81cc3 100644 --- a/src/AwsInspector/Command/Ec2/SshCommand.php +++ b/src/AwsInspector/Command/Ec2/SshCommand.php @@ -156,4 +156,4 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } -} \ No newline at end of file +} diff --git a/src/AwsInspector/Model/Ec2/Instance.php b/src/AwsInspector/Model/Ec2/Instance.php index c2fd8f0..047e113 100644 --- a/src/AwsInspector/Model/Ec2/Instance.php +++ b/src/AwsInspector/Model/Ec2/Instance.php @@ -83,13 +83,18 @@ public function getPrivateKey() * Overwrite this method in your inheriting class and return * a \AwsInspector\Model\Ec2\Instance representing your bastion server * - * @return null|Instance + * @return Instance|null + * @throws \Exception */ public function getJumpHost() { if ($config = $this->getInspectorConfiguration('jumptags')) { $ec2Repository = new Repository(); - return $ec2Repository->findEc2InstancesByTags($config)->getFirst(); + $instances = $ec2Repository->findEc2InstancesByTags($config); + if (count($instances) == 0) { + throw new \Exception('Could not fund jump host for: ' . var_export($config, true)); + } + return $instances->getFirst(); } return null; }