]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Hook up conduit auth.
authorepriestley <epriestley@phabricator.com>
Sun, 6 Feb 2011 06:44:30 +0000 (22:44 -0800)
committerepriestley <epriestley@phabricator.com>
Sun, 6 Feb 2011 06:44:30 +0000 (22:44 -0800)
scripts/arcanist.php

index 7d65b6b8d298dbe4d6a1afc57a1b135f6494a8eb..40787473cb973ad4cfba239f14331dc7d9c23752 100755 (executable)
@@ -66,6 +66,17 @@ try {
       phutil_load_library($library_root);
     }
   }
+  
+  $user_config = array();
+  $user_config_path = getenv('HOME').'/.arcrc';
+  if (Filesystem::pathExists($user_config_path)) {
+    $user_config_data = Filesystem::readFile($user_config_path);
+    $user_config = json_decode($user_config_data, true);
+    if (!is_array($user_config)) {
+      throw new ArcanistUsageException(
+        "Your '~/.arcrc' file is not a valid JSON file.");
+    }
+  }
 
   $config = $working_copy->getConfig('arcanist_configuration');
   if ($config) {
@@ -116,6 +127,11 @@ try {
     $conduit = new ConduitClient($conduit_uri);
     $conduit->setTraceMode($config_trace_mode);
     $workflow->setConduit($conduit);
+    
+    $hosts_config = idx($user_config, 'hosts', array());
+    $host_config = idx($hosts_config, $conduit_uri, array());
+    $user_name = idx($host_config, 'user', getenv('USER'));
+    $certificate = idx($host_config, 'cert');
 
     $description = implode(' ', $argv);
     $connection = $conduit->callMethodSynchronous(
@@ -124,9 +140,15 @@ try {
         'client'            => 'arc',
         'clientVersion'     => 2,
         'clientDescription' => php_uname('n').':'.$description,
-        'user'              => getenv('USER'),
+        'user'              => $user_name,
+        'certificate'       => $certificate,
       ));
-    $conduit->setConnectionID($connection['connectionID']);
+      
+    $workflow->setUserName($user_name);
+    $user_phid = idx($connection, 'userPHID');
+    if ($user_phid) {
+      $workflow->setUserGUID($user_phid);
+    }
   }
 
   if ($need_repository_api) {
@@ -135,7 +157,7 @@ try {
     $workflow->setRepositoryAPI($repository_api);
   }
 
-  if ($need_auth) {
+  if ($need_auth && !$workflow->getUserGUID()) {
     $user_name = getenv('USER');
     $user_find_future = $conduit->callMethod(
       'user.find',