Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/ssh/DiffusionSSHWorkflow.php
<?php | <?php | ||||
abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow { | abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow { | ||||
private $args; | private $args; | ||||
private $repository; | private $repository; | ||||
private $hasWriteAccess; | private $hasWriteAccess; | ||||
private $proxyURI; | private $shouldProxy; | ||||
private $baseRequestPath; | private $baseRequestPath; | ||||
public function getRepository() { | public function getRepository() { | ||||
if (!$this->repository) { | if (!$this->repository) { | ||||
throw new Exception(pht('Repository is not available yet!')); | throw new Exception(pht('Repository is not available yet!')); | ||||
} | } | ||||
return $this->repository; | return $this->repository; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | protected function getCurrentDeviceName() { | ||||
$device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
if ($device) { | if ($device) { | ||||
return $device->getName(); | return $device->getName(); | ||||
} | } | ||||
return php_uname('n'); | return php_uname('n'); | ||||
} | } | ||||
protected function getTargetDeviceName() { | protected function shouldProxy() { | ||||
// TODO: This should use the correct device identity. | return $this->shouldProxy; | ||||
$uri = new PhutilURI($this->proxyURI); | |||||
return $uri->getDomain(); | |||||
} | } | ||||
protected function shouldProxy() { | protected function getProxyCommand($for_write) { | ||||
return (bool)$this->proxyURI; | $viewer = $this->getSSHUser(); | ||||
$repository = $this->getRepository(); | |||||
$is_cluster_request = $this->getIsClusterRequest(); | |||||
$uri = $repository->getAlmanacServiceURI( | |||||
$viewer, | |||||
array( | |||||
'neverProxy' => $is_cluster_request, | |||||
'protocols' => array( | |||||
'ssh', | |||||
), | |||||
'writable' => $for_write, | |||||
)); | |||||
if (!$uri) { | |||||
throw new Exception( | |||||
pht( | |||||
'Failed to generate an intracluster proxy URI even though this '. | |||||
'request was routed as a proxy request.')); | |||||
} | } | ||||
protected function getProxyCommand() { | $uri = new PhutilURI($uri); | ||||
$uri = new PhutilURI($this->proxyURI); | |||||
$username = AlmanacKeys::getClusterSSHUser(); | $username = AlmanacKeys::getClusterSSHUser(); | ||||
if ($username === null) { | if ($username === null) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unable to determine the username to connect with when trying '. | 'Unable to determine the username to connect with when trying '. | ||||
'to proxy an SSH request within the Phabricator cluster.')); | 'to proxy an SSH request within the Phabricator cluster.')); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (!$have_diffusion) { | ||||
pht( | pht( | ||||
'You do not have permission to access the Diffusion application, '. | 'You do not have permission to access the Diffusion application, '. | ||||
'so you can not interact with repositories over SSH.')); | 'so you can not interact with repositories over SSH.')); | ||||
} | } | ||||
$repository = $this->identifyRepository(); | $repository = $this->identifyRepository(); | ||||
$this->setRepository($repository); | $this->setRepository($repository); | ||||
// NOTE: Here, we're just figuring out if this is a proxyable request to | |||||
// a clusterized repository or not. We don't (and can't) use the URI we get | |||||
// back directly. | |||||
// For example, we may get a read-only URI here but be handling a write | |||||
// request. We only care if we get back `null` (which means we should | |||||
// handle the request locally) or anything else (which means we should | |||||
// proxy it to an appropriate device). | |||||
$is_cluster_request = $this->getIsClusterRequest(); | $is_cluster_request = $this->getIsClusterRequest(); | ||||
$uri = $repository->getAlmanacServiceURI( | $uri = $repository->getAlmanacServiceURI( | ||||
$viewer, | $viewer, | ||||
array( | array( | ||||
'neverProxy' => $is_cluster_request, | 'neverProxy' => $is_cluster_request, | ||||
'protocols' => array( | 'protocols' => array( | ||||
'ssh', | 'ssh', | ||||
), | ), | ||||
)); | )); | ||||
$this->shouldProxy = (bool)$uri; | |||||
if ($uri) { | |||||
$this->proxyURI = $uri; | |||||
} | |||||
try { | try { | ||||
return $this->executeRepositoryOperations(); | return $this->executeRepositoryOperations(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$this->writeError(get_class($ex).': '.$ex->getMessage()); | $this->writeError(get_class($ex).': '.$ex->getMessage()); | ||||
return 1; | return 1; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |