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

Improve login/auth messages from Arcanist toolset workflows

Summary:
See PHI1802. After D21384, "arc land" and similar with no credentials now properly raise a useful exception, but it isn't formatted readably.

Update the display code to make it look prettier.

Test Plan: Ran "arc land" with no and invalid credentials, got properly formatted output.

Differential Revision: https://secure.phabricator.com/D21387
This commit is contained in:
epriestley 2020-07-01 06:12:09 -07:00
parent 65e4927dca
commit b8a5191e3b
4 changed files with 94 additions and 41 deletions

View file

@ -126,6 +126,7 @@ phutil_register_library_map(array(
'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php', 'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php',
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php', 'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php',
'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConcatenationOperatorXHPASTLinterRuleTestCase.php', 'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConcatenationOperatorXHPASTLinterRuleTestCase.php',
'ArcanistConduitAuthenticationException' => 'exception/ArcanistConduitAuthenticationException.php',
'ArcanistConduitCallFuture' => 'conduit/ArcanistConduitCallFuture.php', 'ArcanistConduitCallFuture' => 'conduit/ArcanistConduitCallFuture.php',
'ArcanistConduitEngine' => 'conduit/ArcanistConduitEngine.php', 'ArcanistConduitEngine' => 'conduit/ArcanistConduitEngine.php',
'ArcanistConduitException' => 'conduit/ArcanistConduitException.php', 'ArcanistConduitException' => 'conduit/ArcanistConduitException.php',
@ -1170,6 +1171,7 @@ phutil_register_library_map(array(
'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine', 'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine',
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule', 'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase', 'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistConduitAuthenticationException' => 'Exception',
'ArcanistConduitCallFuture' => 'FutureProxy', 'ArcanistConduitCallFuture' => 'FutureProxy',
'ArcanistConduitEngine' => 'Phobject', 'ArcanistConduitEngine' => 'Phobject',
'ArcanistConduitException' => 'Exception', 'ArcanistConduitException' => 'Exception',

View file

@ -15,61 +15,56 @@ final class ArcanistConduitCallFuture
} }
private function raiseLoginRequired() { private function raiseLoginRequired() {
$conduit_uri = $this->getEngine()->getConduitURI(); $conduit_domain = $this->getConduitDomain();
$conduit_uri = new PhutilURI($conduit_uri);
$conduit_uri->setPath('/');
$conduit_domain = $conduit_uri->getDomain(); $message = array(
tsprintf(
$block = id(new PhutilConsoleBlock()) "\n\n%W\n\n",
->addParagraph(
tsprintf(
'**<bg:red> %s </bg>**',
pht('LOGIN REQUIRED')))
->addParagraph(
pht( pht(
'You are trying to connect to a server ("%s") that you do not '. 'You are trying to connect to a server ("%s") that you do not '.
'have any stored credentials for, but the command you are '. 'have any stored credentials for, but the command you are '.
'running requires authentication.', 'running requires authentication.',
$conduit_domain)) $conduit_domain)),
->addParagraph( tsprintf(
"%W\n\n",
pht( pht(
'To login and save credentials for this server, run this '. 'To log in and save credentials for this server, run this '.
'command:')) 'command:')),
->addParagraph( tsprintf(
tsprintf( '%>',
" $ arc install-certificate %s\n", $this->getInstallCommand()),
$conduit_uri)); );
throw new PhutilArgumentUsageException($block->drawConsoleString()); $this->raiseException(
pht('Conduit API login required.'),
pht('LOGIN REQUIRED'),
$message);
} }
private function raiseInvalidAuth() { private function raiseInvalidAuth() {
$conduit_uri = $this->getEngine()->getConduitURI(); $conduit_domain = $this->getConduitDomain();
$conduit_uri = new PhutilURI($conduit_uri);
$conduit_uri->setPath('/');
$conduit_domain = $conduit_uri->getDomain(); $message = array(
tsprintf(
$block = id(new PhutilConsoleBlock()) "\n\n%W\n\n",
->addParagraph(
tsprintf(
'**<bg:red> %s </bg>**',
pht('INVALID CREDENTIALS')))
->addParagraph(
pht( pht(
'Your stored credentials for this server ("%s") are not valid.', 'Your stored credentials for the server you are trying to connect '.
$conduit_domain)) 'to ("%s") are not valid.',
->addParagraph( $conduit_domain)),
tsprintf(
"%W\n\n",
pht( pht(
'To login and save valid credentials for this server, run this '. 'To log in and save valid credentials for this server, run this '.
'command:')) 'command:')),
->addParagraph( tsprintf(
tsprintf( '%>',
" $ arc install-certificate %s\n", $this->getInstallCommand()),
$conduit_uri)); );
throw new PhutilArgumentUsageException($block->drawConsoleString()); $this->raiseException(
pht('Invalid Conduit API credentials.'),
pht('INVALID CREDENTIALS'),
$message);
} }
protected function didReceiveResult($result) { protected function didReceiveResult($result) {
@ -91,4 +86,31 @@ final class ArcanistConduitCallFuture
throw $exception; throw $exception;
} }
private function getInstallCommand() {
$conduit_uri = $this->getConduitURI();
return csprintf(
'arc install-certificate %s',
$conduit_uri);
}
private function getConduitURI() {
$conduit_uri = $this->getEngine()->getConduitURI();
$conduit_uri = new PhutilURI($conduit_uri);
$conduit_uri->setPath('/');
return $conduit_uri;
}
private function getConduitDomain() {
$conduit_uri = $this->getConduitURI();
return $conduit_uri->getDomain();
}
private function raiseException($summary, $title, $body) {
throw id(new ArcanistConduitAuthenticationException($summary))
->setTitle($title)
->setBody($body);
}
} }

View file

@ -0,0 +1,27 @@
<?php
final class ArcanistConduitAuthenticationException
extends Exception {
private $title;
private $body;
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function getTitle() {
return $this->title;
}
public function setBody($body) {
$this->body = $body;
return $this;
}
public function getBody() {
return $this->body;
}
}

View file

@ -41,6 +41,8 @@ final class ArcanistRuntime {
$log->writeError(pht('USAGE EXCEPTION'), $ex->getMessage()); $log->writeError(pht('USAGE EXCEPTION'), $ex->getMessage());
} catch (ArcanistUserAbortException $ex) { } catch (ArcanistUserAbortException $ex) {
$log->writeError(pht('---'), $ex->getMessage()); $log->writeError(pht('---'), $ex->getMessage());
} catch (ArcanistConduitAuthenticationException $ex) {
$log->writeError($ex->getTitle(), $ex->getBody());
} }
return 1; return 1;