Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistInstallCertificateWorkflow.php
| Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | try { | ||||
| if (in_array('token', $auth)) { | if (in_array('token', $auth)) { | ||||
| $token_uri->setPath('/conduit/login/'); | $token_uri->setPath('/conduit/login/'); | ||||
| $is_token_auth = true; | $is_token_auth = true; | ||||
| } | } | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| // Ignore. | // Ignore. | ||||
| } | } | ||||
| echo phutil_console_format("**LOGIN TO PHABRICATOR**\n"); | echo phutil_console_format("**%s**\n", pht('LOGIN TO PHABRICATOR')); | ||||
| echo "Open this page in your browser and login to Phabricator if ". | echo phutil_console_format( | ||||
| "necessary:\n"; | "%s\n\n%s\n\n%s", | ||||
| echo "\n"; | pht( | ||||
| echo " {$token_uri}\n"; | 'Open this page in your browser and login to '. | ||||
| echo "\n"; | 'Phabricator if necessary:'), | ||||
| echo 'Then paste the API Token on that page below.'; | $token_uri, | ||||
| pht('Then paste the API Token on that page below.')); | |||||
| do { | do { | ||||
| $token = phutil_console_prompt('Paste API Token from that page:'); | $token = phutil_console_prompt(pht('Paste API Token from that page:')); | ||||
| $token = trim($token); | $token = trim($token); | ||||
| if (strlen($token)) { | if (strlen($token)) { | ||||
| break; | break; | ||||
| } | } | ||||
| } while (true); | } while (true); | ||||
| if ($is_token_auth) { | if ($is_token_auth) { | ||||
| if (strlen($token) != 32) { | if (strlen($token) != 32) { | ||||
| Show All 26 Lines | if ($is_token_auth) { | ||||
| $ex->getMessage())); | $ex->getMessage())); | ||||
| } | } | ||||
| $config['hosts'][$uri] = array( | $config['hosts'][$uri] = array( | ||||
| 'token' => $token, | 'token' => $token, | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| echo "\n"; | echo "\n"; | ||||
| echo "Downloading authentication certificate...\n"; | echo pht('Downloading authentication certificate...')."\n"; | ||||
| $info = $conduit->callMethodSynchronous( | $info = $conduit->callMethodSynchronous( | ||||
| 'conduit.getcertificate', | 'conduit.getcertificate', | ||||
| array( | array( | ||||
| 'token' => $token, | 'token' => $token, | ||||
| 'host' => $uri, | 'host' => $uri, | ||||
| )); | )); | ||||
| $user = $info['username']; | $user = $info['username']; | ||||
| echo "Installing certificate for '{$user}'...\n"; | echo pht("Installing certificate for '%s'...", $user)."\n"; | ||||
| $config['hosts'][$uri] = array( | $config['hosts'][$uri] = array( | ||||
| 'user' => $user, | 'user' => $user, | ||||
| 'cert' => $info['certificate'], | 'cert' => $info['certificate'], | ||||
| ); | ); | ||||
| } | } | ||||
| echo "Writing ~/.arcrc...\n"; | echo pht('Writing %s...', '~/.arcrc')."\n"; | ||||
| $configuration_manager->writeUserConfigurationFile($config); | $configuration_manager->writeUserConfigurationFile($config); | ||||
| if ($is_token_auth) { | if ($is_token_auth) { | ||||
| echo phutil_console_format( | echo phutil_console_format( | ||||
| "<bg:green>** SUCCESS! **</bg> API Token installed.\n"); | "<bg:green>** %s **</bg> %s\n", | ||||
| pht('SUCCESS!'), | |||||
| pht('API Token installed.')); | |||||
| } else { | } else { | ||||
| echo phutil_console_format( | echo phutil_console_format( | ||||
| "<bg:green>** SUCCESS! **</bg> Certificate installed.\n"); | "<bg:green>** %s **</bg> %s\n", | ||||
| pht('SUCCESS!'), | |||||
| pht('Certificate installed.')); | |||||
| } | } | ||||
| 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(pht('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 '. | pht( | ||||
| 'which is configured with a .arcconfig.'); | 'Specify an explicit URI or run this command from within a '. | ||||
| 'project which is configured with a %s.', | |||||
| '.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; | ||||
| } | } | ||||
| } | } | ||||