From 7c7e6d555b3fe82159b066b7d2541249529a1371 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 12 Apr 2018 06:10:32 -0700 Subject: [PATCH] Give getAlmanacServiceURI() an "options" parameter to prepare for read-only devices Summary: Depends on D19355. Ref T10883. Ref T13120. Rather than adding a million parameters here, wrap the selector-parameters in an `$options`. The next change adds a new "writable" option to support forcing selection of writable hosts. Test Plan: Pulled and pushed via HTTP and SSH, viewed repositories via Diffusion. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13120, T10883 Differential Revision: https://secure.phabricator.com/D19356 --- .../controller/DiffusionServeController.php | 8 ++++--- .../diffusion/ssh/DiffusionSSHWorkflow.php | 6 +++-- .../storage/PhabricatorRepository.php | 24 +++++++++++++------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/applications/diffusion/controller/DiffusionServeController.php b/src/applications/diffusion/controller/DiffusionServeController.php index ac0b993b2f..6b9c5c6802 100644 --- a/src/applications/diffusion/controller/DiffusionServeController.php +++ b/src/applications/diffusion/controller/DiffusionServeController.php @@ -431,10 +431,12 @@ final class DiffusionServeController extends DiffusionController { $uri = $repository->getAlmanacServiceURI( $viewer, - $is_cluster_request, array( - 'http', - 'https', + 'neverProxy' => $is_cluster_request, + 'protocols' => array( + 'http', + 'https', + ), )); if ($uri) { $future = $this->getRequest()->newClusterProxyFuture($uri); diff --git a/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php b/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php index baf1749252..2a3841892f 100644 --- a/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php +++ b/src/applications/diffusion/ssh/DiffusionSSHWorkflow.php @@ -151,9 +151,11 @@ abstract class DiffusionSSHWorkflow extends PhabricatorSSHWorkflow { $is_cluster_request = $this->getIsClusterRequest(); $uri = $repository->getAlmanacServiceURI( $viewer, - $is_cluster_request, array( - 'ssh', + 'neverProxy' => $is_cluster_request, + 'protocols' => array( + 'ssh', + ), )); if ($uri) { diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index 334867cc85..37dd5f1ec5 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -1897,14 +1897,22 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO * services, returning raw URIs. * * @param PhabricatorUser Viewing user. - * @param bool `true` to throw if a remote URI would be returned. - * @param list List of allowable protocols. + * @param map Constraints on selectable services. * @return string|null URI, or `null` for local repositories. */ public function getAlmanacServiceURI( PhabricatorUser $viewer, - $never_proxy, - array $protocols) { + array $options) { + + PhutilTypeSpec::checkMap( + $options, + array( + 'neverProxy' => 'bool', + 'protocols' => 'list', + )); + + $never_proxy = $options['neverProxy']; + $protocols = $options['protocols']; $cache_key = $this->getAlmanacServiceCacheKey(); if (!$cache_key) { @@ -2077,10 +2085,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO $uri = $this->getAlmanacServiceURI( $viewer, - $never_proxy, array( - 'http', - 'https', + 'neverProxy' => $never_proxy, + 'protocols' => array( + 'http', + 'https', + ), )); if ($uri === null) { return null;