Skip to content

Commit 956c405

Browse files
author
epriestley
committed
Add a bin/conduit call support binary
Summary: Ref T13060. See PHI343. Triaging this bug required figuring out where in the pipeline UTF8 was being dropped, and bisecting the pipeline required making calls to Conduit. Currently, there's no easy way to debug/inspect arbitrary Conduit calls, especially when they are `diffusion.*` calls which route to a different host (even if you have a real session and use the web console for these, you just see an HTTP service call to the target host in DarkConsole). Add a `bin/conduit` utility to make this kind of debugging easier, with an eye toward the Phacility production cluster (or other similar clusters) specifically. Test Plan: - Ran `echo '{}' | bin/conduit call --method conduit.ping --input -` and similar. - Used a similar approach to successfully diagnose the UTF8 issue in T13060. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13060 Differential Revision: https://secure.phabricator.com/D18987
1 parent 55f7cdb commit 956c405

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

bin/conduit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_conduit.php

scripts/setup/manage_conduit.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
$root = dirname(dirname(dirname(__FILE__)));
5+
require_once $root.'/scripts/init/init-script.php';
6+
7+
$args = new PhutilArgumentParser($argv);
8+
$args->setTagline(pht('manage Conduit'));
9+
$args->setSynopsis(<<<EOSYNOPSIS
10+
**conduit** __command__ [__options__]
11+
Manage Conduit.
12+
13+
EOSYNOPSIS
14+
);
15+
$args->parseStandardArguments();
16+
17+
$workflows = id(new PhutilClassMapQuery())
18+
->setAncestorClass('PhabricatorConduitManagementWorkflow')
19+
->execute();
20+
$workflows[] = new PhutilHelpArgumentWorkflow();
21+
$args->parseWorkflows($workflows);

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@
24252425
'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php',
24262426
'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php',
24272427
'PhabricatorConduitApplication' => 'applications/conduit/application/PhabricatorConduitApplication.php',
2428+
'PhabricatorConduitCallManagementWorkflow' => 'applications/conduit/management/PhabricatorConduitCallManagementWorkflow.php',
24282429
'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php',
24292430
'PhabricatorConduitConsoleController' => 'applications/conduit/controller/PhabricatorConduitConsoleController.php',
24302431
'PhabricatorConduitContentSource' => 'infrastructure/contentsource/PhabricatorConduitContentSource.php',
@@ -2435,6 +2436,7 @@
24352436
'PhabricatorConduitLogController' => 'applications/conduit/controller/PhabricatorConduitLogController.php',
24362437
'PhabricatorConduitLogQuery' => 'applications/conduit/query/PhabricatorConduitLogQuery.php',
24372438
'PhabricatorConduitLogSearchEngine' => 'applications/conduit/query/PhabricatorConduitLogSearchEngine.php',
2439+
'PhabricatorConduitManagementWorkflow' => 'applications/conduit/management/PhabricatorConduitManagementWorkflow.php',
24382440
'PhabricatorConduitMethodCallLog' => 'applications/conduit/storage/PhabricatorConduitMethodCallLog.php',
24392441
'PhabricatorConduitMethodQuery' => 'applications/conduit/query/PhabricatorConduitMethodQuery.php',
24402442
'PhabricatorConduitRequestExceptionHandler' => 'aphront/handler/PhabricatorConduitRequestExceptionHandler.php',
@@ -7822,6 +7824,7 @@
78227824
'PhabricatorCommonPasswords' => 'Phobject',
78237825
'PhabricatorConduitAPIController' => 'PhabricatorConduitController',
78247826
'PhabricatorConduitApplication' => 'PhabricatorApplication',
7827+
'PhabricatorConduitCallManagementWorkflow' => 'PhabricatorConduitManagementWorkflow',
78257828
'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO',
78267829
'PhabricatorConduitConsoleController' => 'PhabricatorConduitController',
78277830
'PhabricatorConduitContentSource' => 'PhabricatorContentSource',
@@ -7832,6 +7835,7 @@
78327835
'PhabricatorConduitLogController' => 'PhabricatorConduitController',
78337836
'PhabricatorConduitLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
78347837
'PhabricatorConduitLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
7838+
'PhabricatorConduitManagementWorkflow' => 'PhabricatorManagementWorkflow',
78357839
'PhabricatorConduitMethodCallLog' => array(
78367840
'PhabricatorConduitDAO',
78377841
'PhabricatorPolicyInterface',
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
final class PhabricatorConduitCallManagementWorkflow
4+
extends PhabricatorConduitManagementWorkflow {
5+
6+
protected function didConstruct() {
7+
$this
8+
->setName('call')
9+
->setSynopsis(pht('Call a Conduit method..'))
10+
->setArguments(
11+
array(
12+
array(
13+
'name' => 'method',
14+
'param' => 'method',
15+
'help' => pht('Method to call.'),
16+
),
17+
array(
18+
'name' => 'input',
19+
'param' => 'input',
20+
'help' => pht(
21+
'File to read parameters from, or "-" to read from '.
22+
'stdin.'),
23+
),
24+
));
25+
}
26+
27+
public function execute(PhutilArgumentParser $args) {
28+
$viewer = $this->getViewer();
29+
30+
$method = $args->getArg('method');
31+
if (!strlen($method)) {
32+
throw new PhutilArgumentUsageException(
33+
pht('Specify a method to call with "--method".'));
34+
}
35+
36+
$input = $args->getArg('input');
37+
if (!strlen($input)) {
38+
throw new PhutilArgumentUsageException(
39+
pht('Specify a file to read parameters from with "--input".'));
40+
}
41+
42+
if ($input === '-') {
43+
fprintf(STDERR, tsprintf("%s\n", pht('Reading input from stdin...')));
44+
$input_json = file_get_contents('php://stdin');
45+
} else {
46+
$input_json = Filesystem::readFile($input);
47+
}
48+
49+
$params = phutil_json_decode($input_json);
50+
51+
$result = id(new ConduitCall($method, $params))
52+
->setUser($viewer)
53+
->execute();
54+
55+
$output = array(
56+
'result' => $result,
57+
);
58+
59+
echo tsprintf(
60+
"%B\n",
61+
id(new PhutilJSON())->encodeFormatted($output));
62+
63+
return 0;
64+
}
65+
66+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
abstract class PhabricatorConduitManagementWorkflow
4+
extends PhabricatorManagementWorkflow {}

0 commit comments

Comments
 (0)