Add an "--as" flag to "bin/conduit call ..." to improve flexibility and ease of profiling
Summary:
Ref T13164. In PHI801, an install reported a particular slow Conduit method call.
Conduit calls aren't easily profilable with normal tools (for example, `arc call-conduit --xprofile ...` gives you a profile of the //client//). They can be profiled most easily with `bin/conduit call ... --xprofile`.
However, `bin/conduit call` currently doesn't let you pick a user to execute the command on behalf of, so it's not terribly useful for profiling `*.edit`-style methods which do a write: these need a real acting user.
Test Plan:
Ran `bin/conduit call --method user.whoami --as epriestley ...` with valid, invalid, and no acting users.
```
$ echo '{}' | ./bin/conduit call --method user.whoami --as epriestley --input -
Reading input from stdin...
{
"result": {
"phid": "PHID-USER-icyixzkx3f4ttv67avbn",
"userName": "epriestley",
"realName": "Evan Priestley",
...
```
Reviewers: amckinley
Reviewed By: amckinley
Maniphest Tasks: T13164
Differential Revision: https://secure.phabricator.com/D19566
This commit is contained in:
@@ -21,6 +21,13 @@ final class PhabricatorConduitCallManagementWorkflow
|
|||||||
'File to read parameters from, or "-" to read from '.
|
'File to read parameters from, or "-" to read from '.
|
||||||
'stdin.'),
|
'stdin.'),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'as',
|
||||||
|
'param' => 'username',
|
||||||
|
'help' => pht(
|
||||||
|
'Execute the call as the given user. (If omitted, the call will '.
|
||||||
|
'be executed as an omnipotent user.)'),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +46,22 @@ final class PhabricatorConduitCallManagementWorkflow
|
|||||||
pht('Specify a file to read parameters from with "--input".'));
|
pht('Specify a file to read parameters from with "--input".'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$as = $args->getArg('as');
|
||||||
|
if (strlen($as)) {
|
||||||
|
$actor = id(new PhabricatorPeopleQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withUsernames(array($as))
|
||||||
|
->executeOne();
|
||||||
|
if (!$actor) {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht(
|
||||||
|
'No such user "%s" exists.',
|
||||||
|
$as));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$actor = $viewer;
|
||||||
|
}
|
||||||
|
|
||||||
if ($input === '-') {
|
if ($input === '-') {
|
||||||
fprintf(STDERR, tsprintf("%s\n", pht('Reading input from stdin...')));
|
fprintf(STDERR, tsprintf("%s\n", pht('Reading input from stdin...')));
|
||||||
$input_json = file_get_contents('php://stdin');
|
$input_json = file_get_contents('php://stdin');
|
||||||
@@ -49,7 +72,7 @@ final class PhabricatorConduitCallManagementWorkflow
|
|||||||
$params = phutil_json_decode($input_json);
|
$params = phutil_json_decode($input_json);
|
||||||
|
|
||||||
$result = id(new ConduitCall($method, $params))
|
$result = id(new ConduitCall($method, $params))
|
||||||
->setUser($viewer)
|
->setUser($actor)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$output = array(
|
$output = array(
|
||||||
|
|||||||
Reference in New Issue
Block a user