4
* Installs arcanist certificates.
6
final class ArcanistInstallCertificateWorkflow extends ArcanistWorkflow {
8
public function getWorkflowName() {
9
return 'install-certificate';
12
public function getCommandSynopses() {
13
return phutil_console_format(<<<EOTEXT
14
**install-certificate** [uri]
19
public function getCommandHelp() {
20
return phutil_console_format(<<<EOTEXT
22
Installs Conduit credentials into your ~/.arcrc for the given install
23
of Phabricator. You need to do this before you can use 'arc', as it
24
enables 'arc' to link your command-line activity with your account on
25
the web. Run this command from within a project directory to install
26
that project's certificate, or specify an explicit URI (like
27
"https://phabricator.example.com/").
32
public function getArguments() {
38
public function shouldShellComplete() {
42
public function requiresConduit() {
46
public function requiresWorkingCopy() {
50
public function run() {
51
$uri = $this->determineConduitURI();
52
$this->setConduitURI($uri);
53
$configuration_manager = $this->getConfigurationManager();
55
echo "Installing certificate for '{$uri}'...\n";
57
$config = $configuration_manager->readUserConfigurationFile();
59
echo "Trying to connect to server...\n";
60
$conduit = $this->establishConduit()->getConduit();
62
$conduit->callMethodSynchronous('conduit.ping', array());
63
} catch (Exception $ex) {
64
throw new ArcanistUsageException(
65
'Failed to connect to server: '.$ex->getMessage());
67
echo "Connection OK!\n";
69
$token_uri = new PhutilURI($uri);
70
$token_uri->setPath('/conduit/token/');
73
echo phutil_console_format("**LOGIN TO PHABRICATOR**\n");
74
echo "Open this page in your browser and login to Phabricator if ".
77
echo " {$token_uri}\n";
79
echo 'Then paste the token on that page below.';
83
$token = phutil_console_prompt('Paste token from that page:');
84
$token = trim($token);
91
echo "Downloading authentication certificate...\n";
92
$info = $conduit->callMethodSynchronous(
93
'conduit.getcertificate',
99
$user = $info['username'];
100
echo "Installing certificate for '{$user}'...\n";
101
$config['hosts'][$uri] = array(
103
'cert' => $info['certificate'],
106
echo "Writing ~/.arcrc...\n";
107
$configuration_manager->writeUserConfigurationFile($config);
109
echo phutil_console_format(
110
"<bg:green>** SUCCESS! **</bg> Certificate installed.\n");
115
private function determineConduitURI() {
116
$uri = $this->getArgument('uri');
117
if (count($uri) > 1) {
118
throw new ArcanistUsageException('Specify at most one URI.');
119
} else if (count($uri) == 1) {
122
$conduit_uri = $this->getConduitURI();
124
throw new ArcanistUsageException(
125
'Specify an explicit URI or run this command from within a project '.
126
'which is configured with a .arcconfig.');
131
$uri = new PhutilURI($uri);
132
$uri->setPath('/api/');