1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 16:02:39 +01:00

Add a --conduit-token parameter to arc

Summary: Ref T5955. This makes it easier to write scripts which call Conduit via `arc call-conduit`.

Test Plan: Used `arc --conduit-token ... call-conduit user.whoami` to make calls as various users.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: mbishopim3, epriestley

Maniphest Tasks: T5955

Differential Revision: https://secure.phabricator.com/D12717
This commit is contained in:
epriestley 2015-05-05 14:02:54 -07:00
parent 8919a9c5b5
commit 111b9b035a
3 changed files with 36 additions and 1 deletions

View file

@ -30,6 +30,11 @@ $base_args->parsePartial(
'param' => 'uri',
'help' => pht('Connect to Phabricator install specified by __uri__.'),
),
array(
'name' => 'conduit-token',
'param' => 'token',
'help' => pht('Use a specific authentication token.'),
),
array(
'name' => 'conduit-version',
'param' => 'version',
@ -54,6 +59,7 @@ $base_args->parsePartial(
$config_trace_mode = $base_args->getArg('trace');
$force_conduit = $base_args->getArg('conduit-uri');
$force_token = $base_args->getArg('conduit-token');
$force_conduit_version = $base_args->getArg('conduit-version');
$conduit_timeout = $base_args->getArg('conduit-timeout');
$skip_arcconfig = $base_args->getArg('skip-arcconfig');
@ -198,6 +204,9 @@ try {
if ($force_conduit_version) {
$workflow->forceConduitVersion($force_conduit_version);
}
if ($force_token) {
$workflow->forceConduitToken($force_token);
}
if ($conduit_timeout) {
$workflow->setConduitTimeout($conduit_timeout);
}

View file

@ -189,6 +189,9 @@ EOTEXT
Ignore configured Conduit URI and use an explicit one instead. Mostly
useful for Arcanist development.
__--conduit-token__ __token__
Ignore configured credentials and use an explicit API token instead.
__--conduit-version__ __version__
Ignore software version and claim to be running some other version
instead. Mostly useful for Arcanist development. May cause bad things

View file

@ -48,6 +48,7 @@ abstract class ArcanistWorkflow extends Phobject {
private $conduitCredentials;
private $conduitAuthenticated;
private $forcedConduitVersion;
private $forcedConduitToken;
private $conduitTimeout;
private $userPHID;
@ -251,6 +252,21 @@ abstract class ArcanistWorkflow extends Phobject {
}
/**
* Force use of a specific API token.
*
* Controlled by the --conduit-token flag.
*
* @param string API token to use.
* @return this
* @task conduit
*/
final public function forceConduitToken($token) {
$this->forcedConduitToken = $token;
return $this;
}
/**
* Get the protocol version the client should identify with.
*
@ -325,10 +341,17 @@ abstract class ArcanistWorkflow extends Phobject {
// If we have `token`, this server supports the simpler, new-style
// token-based authentication. Use that instead of all the certificate
// stuff.
$token = null;
if (isset($credentials['token'])) {
$token = $credentials['token'];
}
if ($this->forcedConduitToken) {
$token = $this->forcedConduitToken;
}
if (strlen($token)) {
$conduit = $this->getConduit();
$conduit->setConduitToken($credentials['token']);
$conduit->setConduitToken($token);
try {
$result = $this->getConduit()->callMethodSynchronous(