Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistInstallCertificateWorkflow.php
| Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function run() { | ||||
| $config = $configuration_manager->readUserConfigurationFile(); | $config = $configuration_manager->readUserConfigurationFile(); | ||||
| echo "Trying to connect to server...\n"; | echo "Trying to connect to server...\n"; | ||||
| $conduit = $this->establishConduit()->getConduit(); | $conduit = $this->establishConduit()->getConduit(); | ||||
| try { | try { | ||||
| $conduit->callMethodSynchronous('conduit.ping', array()); | $conduit->callMethodSynchronous('conduit.ping', array()); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Failed to connect to server: ".$ex->getMessage()); | 'Failed to connect to server: '.$ex->getMessage()); | ||||
| } | } | ||||
| echo "Connection OK!\n"; | echo "Connection OK!\n"; | ||||
| $token_uri = new PhutilURI($uri); | $token_uri = new PhutilURI($uri); | ||||
| $token_uri->setPath('/conduit/token/'); | $token_uri->setPath('/conduit/token/'); | ||||
| echo "\n"; | echo "\n"; | ||||
| echo phutil_console_format("**LOGIN TO PHABRICATOR**\n"); | echo phutil_console_format("**LOGIN TO PHABRICATOR**\n"); | ||||
| echo "Open this page in your browser and login to Phabricator if ". | echo "Open this page in your browser and login to Phabricator if ". | ||||
| "necessary:\n"; | "necessary:\n"; | ||||
| echo "\n"; | echo "\n"; | ||||
| echo " {$token_uri}\n"; | echo " {$token_uri}\n"; | ||||
| echo "\n"; | echo "\n"; | ||||
| echo "Then paste the token on that page below."; | echo 'Then paste the token on that page below.'; | ||||
| do { | do { | ||||
| $token = phutil_console_prompt('Paste token from that page:'); | $token = phutil_console_prompt('Paste token from that page:'); | ||||
| $token = trim($token); | $token = trim($token); | ||||
| if (strlen($token)) { | if (strlen($token)) { | ||||
| break; | break; | ||||
| } | } | ||||
| Show All 22 Lines | echo phutil_console_format( | ||||
| "<bg:green>** SUCCESS! **</bg> Certificate installed.\n"); | "<bg:green>** SUCCESS! **</bg> Certificate installed.\n"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| private function determineConduitURI() { | private function determineConduitURI() { | ||||
| $uri = $this->getArgument('uri'); | $uri = $this->getArgument('uri'); | ||||
| if (count($uri) > 1) { | if (count($uri) > 1) { | ||||
| throw new ArcanistUsageException("Specify at most one URI."); | throw new ArcanistUsageException('Specify at most one URI.'); | ||||
| } else if (count($uri) == 1) { | } else if (count($uri) == 1) { | ||||
| $uri = reset($uri); | $uri = reset($uri); | ||||
| } else { | } else { | ||||
| $conduit_uri = $this->getConduitURI(); | $conduit_uri = $this->getConduitURI(); | ||||
| if (!$conduit_uri) { | if (!$conduit_uri) { | ||||
| throw new ArcanistUsageException( | throw new ArcanistUsageException( | ||||
| "Specify an explicit URI or run this command from within a project ". | 'Specify an explicit URI or run this command from within a project '. | ||||
| "which is configured with a .arcconfig."); | 'which is configured with a .arcconfig.'); | ||||
| } | } | ||||
| $uri = $conduit_uri; | $uri = $conduit_uri; | ||||
| } | } | ||||
| $uri = new PhutilURI($uri); | $uri = new PhutilURI($uri); | ||||
| $uri->setPath('/api/'); | $uri->setPath('/api/'); | ||||
| return (string)$uri; | return (string)$uri; | ||||
| } | } | ||||
| } | } | ||||