'uri', ); } public function shouldShellComplete() { return false; } public function requiresConduit() { return false; } public function requiresWorkingCopy() { return false; } public function run() { $uri = $this->determineConduitURI(); echo "Installing certificate for '{$uri}'...\n"; $config = self::readUserConfigurationFile(); echo "Trying to connect to server...\n"; $conduit = new ConduitClient($uri); $conduit->setTimeout(5); try { $conduit->callMethodSynchronous('conduit.ping', array()); } catch (Exception $ex) { throw new ArcanistUsageException( "Failed to connect to server: ".$ex->getMessage()); } echo "Connection OK!\n"; $token_uri = new PhutilURI($uri); $token_uri->setPath('/conduit/token/'); echo "\n"; echo phutil_console_format("**LOGIN TO PHABRICATOR**\n"); echo "Open this page in your browser and login to Phabricator if ". "necessary:\n"; echo "\n"; echo " {$token_uri}\n"; echo "\n"; echo "Then paste the token on that page below."; do { $token = phutil_console_prompt('Paste token from that page:'); $token = trim($token); if (strlen($token)) { break; } } while (true); echo "\n"; echo "Downloading authentication certificate...\n"; $info = $conduit->callMethodSynchronous( 'conduit.getcertificate', array( 'token' => $token, )); $user = $info['username']; echo "Installing certificate for '{$user}'...\n"; $config['hosts'][$uri] = array( 'user' => $user, 'cert' => $info['certificate'], ); $json_encoder = new PhutilJSON(); $json = $json_encoder->encodeFormatted($config); echo "Writing ~/.arcconfig...\n"; $path = self::getUserConfigurationFileLocation(); Filesystem::writeFile($path, $json); execx('chmod 600 %s', $path); echo phutil_console_format( "** SUCCESS! ** Certificate installed.\n"); return 0; } private function determineConduitURI() { $uri = $this->getArgument('uri'); if (count($uri) > 1) { throw new ArcanistUsageException("Specify at most one URI."); } else if (count($uri) == 1) { $uri = reset($uri); } else { $working_copy = ArcanistWorkingCopyIdentity::newFromPath( $this->getWorkingDirectory()); if (!$working_copy->getProjectRoot()) { throw new ArcanistUsageException( "Specify an explicit URI or run this command from within a project ". "which is configured with a .arcconfig."); } $conduit_uri = $working_copy->getConduitURI(); if (!$conduit_uri) { throw new ArcanistUsageException( "This project's .arcconfig does not specify a Conduit URI."); } $uri = $conduit_uri; } $uri = new PhutilURI($uri); $uri->setPath('/api/'); return (string)$uri; } }