From 82f506f175b10a397fdb48f71b915e9b5e665a73 Mon Sep 17 00:00:00 2001 From: James Rhodes Date: Wed, 28 Jan 2015 23:40:34 +0000 Subject: [PATCH] Check to make sure credential is not null in SSH command interface Summary: This adds a check to make sure the credential exists when loading it in the Drydock SSH interface. This effectively turns a fatal error (calling a method on a non-object) into a catchable exception. Test Plan: Had a badly configured resource, saw the exception appear instead of daemon fataling. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11530 --- .../interface/command/DrydockSSHCommandInterface.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php index cde5f4a4ee..1ec2c124f5 100644 --- a/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php +++ b/src/applications/drydock/interface/command/DrydockSSHCommandInterface.php @@ -16,6 +16,12 @@ final class DrydockSSHCommandInterface extends DrydockCommandInterface { ->needSecrets(true) ->executeOne(); + if ($credential === null) { + throw new Exception(pht( + 'There is no credential with ID %d.', + $this->getConfig('credential'))); + } + if ($credential->getProvidesType() !== PassphraseCredentialTypeSSHPrivateKey::PROVIDES_TYPE) { throw new Exception('Only private key credentials are supported.');