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:
parent
65e4927dca
commit
b8a5191e3b
4 changed files with 94 additions and 41 deletions
|
@ -126,6 +126,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistComprehensiveLintEngine' => 'lint/engine/ArcanistComprehensiveLintEngine.php',
|
||||
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConcatenationOperatorXHPASTLinterRule.php',
|
||||
'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConcatenationOperatorXHPASTLinterRuleTestCase.php',
|
||||
'ArcanistConduitAuthenticationException' => 'exception/ArcanistConduitAuthenticationException.php',
|
||||
'ArcanistConduitCallFuture' => 'conduit/ArcanistConduitCallFuture.php',
|
||||
'ArcanistConduitEngine' => 'conduit/ArcanistConduitEngine.php',
|
||||
'ArcanistConduitException' => 'conduit/ArcanistConduitException.php',
|
||||
|
@ -1170,6 +1171,7 @@ phutil_register_library_map(array(
|
|||
'ArcanistComprehensiveLintEngine' => 'ArcanistLintEngine',
|
||||
'ArcanistConcatenationOperatorXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||
'ArcanistConcatenationOperatorXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
||||
'ArcanistConduitAuthenticationException' => 'Exception',
|
||||
'ArcanistConduitCallFuture' => 'FutureProxy',
|
||||
'ArcanistConduitEngine' => 'Phobject',
|
||||
'ArcanistConduitException' => 'Exception',
|
||||
|
|
|
@ -15,61 +15,56 @@ final class ArcanistConduitCallFuture
|
|||
}
|
||||
|
||||
private function raiseLoginRequired() {
|
||||
$conduit_uri = $this->getEngine()->getConduitURI();
|
||||
$conduit_uri = new PhutilURI($conduit_uri);
|
||||
$conduit_uri->setPath('/');
|
||||
$conduit_domain = $this->getConduitDomain();
|
||||
|
||||
$conduit_domain = $conduit_uri->getDomain();
|
||||
|
||||
$block = id(new PhutilConsoleBlock())
|
||||
->addParagraph(
|
||||
$message = array(
|
||||
tsprintf(
|
||||
'**<bg:red> %s </bg>**',
|
||||
pht('LOGIN REQUIRED')))
|
||||
->addParagraph(
|
||||
"\n\n%W\n\n",
|
||||
pht(
|
||||
'You are trying to connect to a server ("%s") that you do not '.
|
||||
'have any stored credentials for, but the command you are '.
|
||||
'running requires authentication.',
|
||||
$conduit_domain))
|
||||
->addParagraph(
|
||||
pht(
|
||||
'To login and save credentials for this server, run this '.
|
||||
'command:'))
|
||||
->addParagraph(
|
||||
$conduit_domain)),
|
||||
tsprintf(
|
||||
" $ arc install-certificate %s\n",
|
||||
$conduit_uri));
|
||||
"%W\n\n",
|
||||
pht(
|
||||
'To log in and save credentials for this server, run this '.
|
||||
'command:')),
|
||||
tsprintf(
|
||||
'%>',
|
||||
$this->getInstallCommand()),
|
||||
);
|
||||
|
||||
throw new PhutilArgumentUsageException($block->drawConsoleString());
|
||||
$this->raiseException(
|
||||
pht('Conduit API login required.'),
|
||||
pht('LOGIN REQUIRED'),
|
||||
$message);
|
||||
}
|
||||
|
||||
private function raiseInvalidAuth() {
|
||||
$conduit_uri = $this->getEngine()->getConduitURI();
|
||||
$conduit_uri = new PhutilURI($conduit_uri);
|
||||
$conduit_uri->setPath('/');
|
||||
$conduit_domain = $this->getConduitDomain();
|
||||
|
||||
$conduit_domain = $conduit_uri->getDomain();
|
||||
|
||||
$block = id(new PhutilConsoleBlock())
|
||||
->addParagraph(
|
||||
$message = array(
|
||||
tsprintf(
|
||||
'**<bg:red> %s </bg>**',
|
||||
pht('INVALID CREDENTIALS')))
|
||||
->addParagraph(
|
||||
"\n\n%W\n\n",
|
||||
pht(
|
||||
'Your stored credentials for this server ("%s") are not valid.',
|
||||
$conduit_domain))
|
||||
->addParagraph(
|
||||
pht(
|
||||
'To login and save valid credentials for this server, run this '.
|
||||
'command:'))
|
||||
->addParagraph(
|
||||
'Your stored credentials for the server you are trying to connect '.
|
||||
'to ("%s") are not valid.',
|
||||
$conduit_domain)),
|
||||
tsprintf(
|
||||
" $ arc install-certificate %s\n",
|
||||
$conduit_uri));
|
||||
"%W\n\n",
|
||||
pht(
|
||||
'To log in and save valid credentials for this server, run this '.
|
||||
'command:')),
|
||||
tsprintf(
|
||||
'%>',
|
||||
$this->getInstallCommand()),
|
||||
);
|
||||
|
||||
throw new PhutilArgumentUsageException($block->drawConsoleString());
|
||||
$this->raiseException(
|
||||
pht('Invalid Conduit API credentials.'),
|
||||
pht('INVALID CREDENTIALS'),
|
||||
$message);
|
||||
}
|
||||
|
||||
protected function didReceiveResult($result) {
|
||||
|
@ -91,4 +86,31 @@ final class ArcanistConduitCallFuture
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
27
src/exception/ArcanistConduitAuthenticationException.php
Normal file
27
src/exception/ArcanistConduitAuthenticationException.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -41,6 +41,8 @@ final class ArcanistRuntime {
|
|||
$log->writeError(pht('USAGE EXCEPTION'), $ex->getMessage());
|
||||
} catch (ArcanistUserAbortException $ex) {
|
||||
$log->writeError(pht('---'), $ex->getMessage());
|
||||
} catch (ArcanistConduitAuthenticationException $ex) {
|
||||
$log->writeError($ex->getTitle(), $ex->getBody());
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue