]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow running `arc patch` without authentication.
authorMarek Sapota <mareksapota@fb.com>
Tue, 1 Nov 2011 19:34:27 +0000 (12:34 -0700)
committerMarek Sapota <mareksapota@fb.com>
Tue, 1 Nov 2011 22:31:04 +0000 (15:31 -0700)
Summary:
Allow `arc patch` without authentication if Phabricator instance has
'differential.anonymous-access' set to true.

Test Plan:
Set 'differential.anonymous-access' in Phabricator to true and run `arc patch`
without installing a certificate.  `arc patch` should work as expected.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley
Differential Revision: 1069

src/workflow/patch/ArcanistPatchWorkflow.php

index 6a4e5e61c5045c03b4cd042f8836b9e620e4a13e..e1a9d6f6f91b6ab3ef7e92c3aaac34436bd59c13 100644 (file)
@@ -135,10 +135,6 @@ EOTEXT
            ($this->getSource() == self::SOURCE_DIFF);
   }
 
-  public function requiresAuthentication() {
-    return $this->requiresConduit();
-  }
-
   public function requiresRepositoryAPI() {
     return true;
   }
@@ -159,33 +155,44 @@ EOTEXT
 
     $source = $this->getSource();
     $param = $this->getSourceParam();
-    switch ($source) {
-      case self::SOURCE_PATCH:
-        if ($param == '-') {
-          $patch = @file_get_contents('php://stdin');
-          if (!strlen($patch)) {
-            throw new ArcanistUsageException(
-              "Failed to read patch from stdin!");
+    try {
+      switch ($source) {
+        case self::SOURCE_PATCH:
+          if ($param == '-') {
+            $patch = @file_get_contents('php://stdin');
+            if (!strlen($patch)) {
+              throw new ArcanistUsageException(
+                "Failed to read patch from stdin!");
+            }
+          } else {
+            $patch = Filesystem::readFile($param);
           }
-        } else {
-          $patch = Filesystem::readFile($param);
-        }
-        $bundle = ArcanistBundle::newFromDiff($patch);
-        break;
-      case self::SOURCE_BUNDLE:
-        $path = $this->getArgument('arcbundle');
-        $bundle = ArcanistBundle::newFromArcBundle($path);
-        break;
-      case self::SOURCE_REVISION:
-        $bundle = $this->loadRevisionBundleFromConduit(
-          $this->getConduit(),
-          $param);
-        break;
-      case self::SOURCE_DIFF:
-        $bundle = $this->loadDiffBundleFromConduit(
-          $this->getConduit(),
-          $param);
-        break;
+          $bundle = ArcanistBundle::newFromDiff($patch);
+          break;
+        case self::SOURCE_BUNDLE:
+          $path = $this->getArgument('arcbundle');
+          $bundle = ArcanistBundle::newFromArcBundle($path);
+          break;
+        case self::SOURCE_REVISION:
+          $bundle = $this->loadRevisionBundleFromConduit(
+            $this->getConduit(),
+            $param);
+          break;
+        case self::SOURCE_DIFF:
+          $bundle = $this->loadDiffBundleFromConduit(
+            $this->getConduit(),
+            $param);
+          break;
+      }
+    } catch (Exception $ex) {
+      if ($ex->getErrorCode() == 'ERR-INVALID-SESSION') {
+        // Phabricator is not configured to allow anonymos access to
+        // Differential.
+        $this->authenticateConduit();
+        return $this->run();
+      } else {
+        throw $ex;
+      }
     }
 
     $repository_api = $this->getRepositoryAPI();