@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+96
+1
bin/conduit
··· 1 + ../scripts/setup/manage_conduit.php
+21
scripts/setup/manage_conduit.php
··· 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);
+4
src/__phutil_library_map__.php
··· 2425 2425 'PhabricatorCommonPasswords' => 'applications/auth/constants/PhabricatorCommonPasswords.php', 2426 2426 'PhabricatorConduitAPIController' => 'applications/conduit/controller/PhabricatorConduitAPIController.php', 2427 2427 'PhabricatorConduitApplication' => 'applications/conduit/application/PhabricatorConduitApplication.php', 2428 + 'PhabricatorConduitCallManagementWorkflow' => 'applications/conduit/management/PhabricatorConduitCallManagementWorkflow.php', 2428 2429 'PhabricatorConduitCertificateToken' => 'applications/conduit/storage/PhabricatorConduitCertificateToken.php', 2429 2430 'PhabricatorConduitConsoleController' => 'applications/conduit/controller/PhabricatorConduitConsoleController.php', 2430 2431 'PhabricatorConduitContentSource' => 'infrastructure/contentsource/PhabricatorConduitContentSource.php', ··· 2435 2436 'PhabricatorConduitLogController' => 'applications/conduit/controller/PhabricatorConduitLogController.php', 2436 2437 'PhabricatorConduitLogQuery' => 'applications/conduit/query/PhabricatorConduitLogQuery.php', 2437 2438 'PhabricatorConduitLogSearchEngine' => 'applications/conduit/query/PhabricatorConduitLogSearchEngine.php', 2439 + 'PhabricatorConduitManagementWorkflow' => 'applications/conduit/management/PhabricatorConduitManagementWorkflow.php', 2438 2440 'PhabricatorConduitMethodCallLog' => 'applications/conduit/storage/PhabricatorConduitMethodCallLog.php', 2439 2441 'PhabricatorConduitMethodQuery' => 'applications/conduit/query/PhabricatorConduitMethodQuery.php', 2440 2442 'PhabricatorConduitRequestExceptionHandler' => 'aphront/handler/PhabricatorConduitRequestExceptionHandler.php', ··· 7822 7824 'PhabricatorCommonPasswords' => 'Phobject', 7823 7825 'PhabricatorConduitAPIController' => 'PhabricatorConduitController', 7824 7826 'PhabricatorConduitApplication' => 'PhabricatorApplication', 7827 + 'PhabricatorConduitCallManagementWorkflow' => 'PhabricatorConduitManagementWorkflow', 7825 7828 'PhabricatorConduitCertificateToken' => 'PhabricatorConduitDAO', 7826 7829 'PhabricatorConduitConsoleController' => 'PhabricatorConduitController', 7827 7830 'PhabricatorConduitContentSource' => 'PhabricatorContentSource', ··· 7832 7835 'PhabricatorConduitLogController' => 'PhabricatorConduitController', 7833 7836 'PhabricatorConduitLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7834 7837 'PhabricatorConduitLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 7838 + 'PhabricatorConduitManagementWorkflow' => 'PhabricatorManagementWorkflow', 7835 7839 'PhabricatorConduitMethodCallLog' => array( 7836 7840 'PhabricatorConduitDAO', 7837 7841 'PhabricatorPolicyInterface',
+66
src/applications/conduit/management/PhabricatorConduitCallManagementWorkflow.php
··· 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 + }
+4
src/applications/conduit/management/PhabricatorConduitManagementWorkflow.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorConduitManagementWorkflow 4 + extends PhabricatorManagementWorkflow {}