public function determinePrivateKey($vmDetails)
{
// what are we doing?
$log = usingLog()->startAction("determine private key for Vagrant VM '{$vmDetails->hostId}'");
// the key will be in one of two places, in this order:
//
// <test environment folder>/.vagrant/machines/:name/virtualbox/private_key
// $HOME/.vagrant.d/insecure_private_key
//
// we use the first that we can find
$keyFilenames = [$vmDetails->dir . "/.vagrant/machines/{$vmDetails->hostId}/virtualbox/private_key", getenv("HOME") . "/.vagrant.d/insecure_private_key"];
foreach ($keyFilenames as $keyFilename) {
usingLog()->writeToLog("checking if {$keyFilename} exists");
if (file_exists($keyFilename)) {
$log->endAction($keyFilename);
return $keyFilename;
}
}
// if we get here, then we do not know where the private key is
$log->endAction("unable to find Vagrant private key for VM");
throw new E5xx_ActionFailed(__METHOD__);
}