@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Consolidate handling of SSH usernames

Summary:
Ref T4292. This consolidates code for figuring out which user we should connect to hosts with.

Also narrows a lock window.

Test Plan: Browsed Diffusion, pulled and pushed through an SSH proxy.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4292

Differential Revision: https://secure.phabricator.com/D15754

+33 -13
+18
src/applications/almanac/util/AlmanacKeys.php
··· 48 48 return $device; 49 49 } 50 50 51 + public static function getClusterSSHUser() { 52 + // NOTE: When instancing, we currently use the SSH username to figure out 53 + // which instance you are connecting to. We can't use the host name because 54 + // we have no way to tell which host you think you're reaching: the SSH 55 + // protocol does not have a mechanism like a "Host" header. 56 + $username = PhabricatorEnv::getEnvConfig('cluster.instance'); 57 + if (strlen($username)) { 58 + return $username; 59 + } 60 + 61 + $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 62 + if (strlen($username)) { 63 + return $username; 64 + } 65 + 66 + return null; 67 + } 68 + 51 69 }
+6 -9
src/applications/diffusion/ssh/DiffusionSSHWorkflow.php
··· 62 62 protected function getProxyCommand() { 63 63 $uri = new PhutilURI($this->proxyURI); 64 64 65 - $username = PhabricatorEnv::getEnvConfig('cluster.instance'); 66 - if (!strlen($username)) { 67 - $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 68 - if (!strlen($username)) { 69 - throw new Exception( 70 - pht( 71 - 'Unable to determine the username to connect with when trying '. 72 - 'to proxy an SSH request within the Phabricator cluster.')); 73 - } 65 + $username = AlmanacKeys::getClusterSSHUser(); 66 + if ($username === null) { 67 + throw new Exception( 68 + pht( 69 + 'Unable to determine the username to connect with when trying '. 70 + 'to proxy an SSH request within the Phabricator cluster.')); 74 71 } 75 72 76 73 $port = $uri->getPort();
+8 -3
src/applications/repository/storage/PhabricatorRepository.php
··· 1348 1348 $uri->setPath($uri->getPath().$this->getCloneName().'/'); 1349 1349 } 1350 1350 1351 - $ssh_user = PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 1352 - if ($ssh_user) { 1351 + $ssh_user = AlmanacKeys::getClusterSSHUser(); 1352 + if ($ssh_user !== null) { 1353 1353 $uri->setUser($ssh_user); 1354 1354 } 1355 1355 ··· 2324 2324 'refusing new writes.')); 2325 2325 } 2326 2326 2327 - $max_version = $this->synchronizeWorkingCopyBeforeRead(); 2327 + try { 2328 + $max_version = $this->synchronizeWorkingCopyBeforeRead(); 2329 + } catch (Exception $ex) { 2330 + $write_lock->unlock(); 2331 + throw $ex; 2332 + } 2328 2333 2329 2334 PhabricatorRepositoryWorkingCopyVersion::willWrite( 2330 2335 $repository_phid,
+1 -1
src/applications/repository/storage/PhabricatorRepositoryURI.php
··· 227 227 private function getForcedUser() { 228 228 switch ($this->getBuiltinProtocol()) { 229 229 case self::BUILTIN_PROTOCOL_SSH: 230 - return PhabricatorEnv::getEnvConfig('diffusion.ssh-user'); 230 + return AlmanacKeys::getClusterSSHUser(); 231 231 default: 232 232 return null; 233 233 }