2011-06-14 21:18:40 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs arcanist certificates.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
final class ArcanistInstallCertificateWorkflow extends ArcanistBaseWorkflow {
|
2011-06-14 21:18:40 +02:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'install-certificate';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-06-14 21:18:40 +02:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**install-certificate** [uri]
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2011-06-14 21:18:40 +02:00
|
|
|
Supports: http, https
|
|
|
|
Installs Conduit credentials into your ~/.arcrc for the given install
|
|
|
|
of Phabricator. You need to do this before you can use 'arc', as it
|
|
|
|
enables 'arc' to link your command-line activity with your account on
|
|
|
|
the web. Run this command from within a project directory to install
|
|
|
|
that project's certificate, or specify an explicit URI (like
|
|
|
|
"https://phabricator.example.com/").
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'*' => 'uri',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldShellComplete() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$uri = $this->determineConduitURI();
|
2013-01-03 18:23:20 +01:00
|
|
|
$this->setConduitURI($uri);
|
2011-06-14 21:18:40 +02:00
|
|
|
|
|
|
|
echo "Installing certificate for '{$uri}'...\n";
|
|
|
|
|
|
|
|
$config = self::readUserConfigurationFile();
|
|
|
|
|
|
|
|
echo "Trying to connect to server...\n";
|
2012-12-18 02:58:53 +01:00
|
|
|
$conduit = $this->establishConduit()->getConduit();
|
2011-06-14 21:18:40 +02:00
|
|
|
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,
|
2011-07-05 16:19:30 +02:00
|
|
|
'host' => $uri,
|
2011-06-14 21:18:40 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$user = $info['username'];
|
|
|
|
echo "Installing certificate for '{$user}'...\n";
|
|
|
|
$config['hosts'][$uri] = array(
|
|
|
|
'user' => $user,
|
|
|
|
'cert' => $info['certificate'],
|
|
|
|
);
|
|
|
|
|
2011-06-22 01:03:02 +02:00
|
|
|
echo "Writing ~/.arcrc...\n";
|
2012-02-21 22:16:52 +01:00
|
|
|
self::writeUserConfigurationFile($config);
|
2011-06-14 21:18:40 +02:00
|
|
|
|
|
|
|
echo phutil_console_format(
|
|
|
|
"<bg:green>** SUCCESS! **</bg> 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 {
|
2012-01-24 00:31:56 +01:00
|
|
|
$conduit_uri = $this->getConduitURI();
|
|
|
|
if (!$conduit_uri) {
|
2011-06-14 21:18:40 +02:00
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Specify an explicit URI or run this command from within a project ".
|
|
|
|
"which is configured with a .arcconfig.");
|
|
|
|
}
|
|
|
|
$uri = $conduit_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri = new PhutilURI($uri);
|
|
|
|
$uri->setPath('/api/');
|
|
|
|
|
|
|
|
return (string)$uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|