From b5b1fd62dc64d327b862d748f1fe5822d5938dba Mon Sep 17 00:00:00 2001 From: Brennan Taylor Date: Mon, 17 Dec 2012 17:58:53 -0800 Subject: [PATCH] Support http basic auth and related configuration This adds the http basic auth username and password if found in the configuration to the ConduitClient. Reviewed by: epriestley --- src/configuration/ArcanistSettings.php | 12 ++++++++++ src/workflow/ArcanistBaseWorkflow.php | 23 +++++++++++++++++++ .../ArcanistInstallCertificateWorkflow.php | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/configuration/ArcanistSettings.php b/src/configuration/ArcanistSettings.php index c8ecb2e6..e2057ed7 100644 --- a/src/configuration/ArcanistSettings.php +++ b/src/configuration/ArcanistSettings.php @@ -82,6 +82,18 @@ final class ArcanistSettings { 'help' => 'List of event listener classes to install at startup.', 'example' => '["ExampleEventListener"]', ), + 'http.basicauth.user' => array( + 'type' => 'string', + 'help' => + "Username to use for basic auth over http transports", + 'example' => '"bob"', + ), + 'http.basicauth.pass' => array( + 'type' => 'string', + 'help' => + "Password to use for basic auth over http transports", + 'example' => '"bobhasasecret"', + ), ); } diff --git a/src/workflow/ArcanistBaseWorkflow.php b/src/workflow/ArcanistBaseWorkflow.php index fa62c6e6..37ea3f6f 100644 --- a/src/workflow/ArcanistBaseWorkflow.php +++ b/src/workflow/ArcanistBaseWorkflow.php @@ -171,9 +171,32 @@ abstract class ArcanistBaseWorkflow { $this->conduit->setTimeout($this->conduitTimeout); } + $user = $this->getConfigFromWhateverSourceAvailiable('http.basicauth.user'); + $pass = $this->getConfigFromWhateverSourceAvailiable('http.basicauth.pass'); + if ($user !== null && $pass !== null) { + $this->conduit->setBasicAuthCredentials($user, $pass); + } + return $this; } + final public function getConfigFromWhateverSourceAvailiable($key) { + if ($this->requiresWorkingCopy()) { + $working_copy = $this->getWorkingCopy(); + return $working_copy->getConfigFromAnySource($key); + } else { + $global_config = self::readGlobalArcConfig(); + $pval = idx($global_config, $key); + + if ($pval === null) { + $system_config = self::readSystemArcConfig(); + $pval = idx($system_config, $key); + } + + return $pval; + } + } + /** * Set credentials which will be used to authenticate against Conduit. These diff --git a/src/workflow/ArcanistInstallCertificateWorkflow.php b/src/workflow/ArcanistInstallCertificateWorkflow.php index 5d05892a..dc48684d 100644 --- a/src/workflow/ArcanistInstallCertificateWorkflow.php +++ b/src/workflow/ArcanistInstallCertificateWorkflow.php @@ -58,7 +58,7 @@ EOTEXT $config = self::readUserConfigurationFile(); echo "Trying to connect to server...\n"; - $conduit = new ConduitClient($uri); + $conduit = $this->establishConduit()->getConduit(); try { $conduit->callMethodSynchronous('conduit.ping', array()); } catch (Exception $ex) {