Changeset View
Changeset View
Standalone View
Standalone View
src/conduit/ArcanistConduitCallFuture.php
Show All 9 Lines | public function setEngine(ArcanistConduitEngine $engine) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getEngine() { | public function getEngine() { | ||||
return $this->engine; | return $this->engine; | ||||
} | } | ||||
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(); | |||||
$block = id(new PhutilConsoleBlock()) | $message = array( | ||||
->addParagraph( | |||||
tsprintf( | tsprintf( | ||||
'**<bg:red> %s </bg>**', | "\n\n%W\n\n", | ||||
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", | '%>', | ||||
$conduit_uri)); | $this->getInstallCommand()), | ||||
); | |||||
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(); | |||||
$block = id(new PhutilConsoleBlock()) | $message = array( | ||||
->addParagraph( | |||||
tsprintf( | tsprintf( | ||||
'**<bg:red> %s </bg>**', | "\n\n%W\n\n", | ||||
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", | '%>', | ||||
$conduit_uri)); | $this->getInstallCommand()), | ||||
); | |||||
throw new PhutilArgumentUsageException($block->drawConsoleString()); | |||||
$this->raiseException( | |||||
pht('Invalid Conduit API credentials.'), | |||||
pht('INVALID CREDENTIALS'), | |||||
$message); | |||||
} | } | ||||
protected function didReceiveResult($result) { | protected function didReceiveResult($result) { | ||||
return $result; | return $result; | ||||
} | } | ||||
protected function didReceiveException($exception) { | protected function didReceiveException($exception) { | ||||
switch ($exception->getErrorCode()) { | switch ($exception->getErrorCode()) { | ||||
case 'ERR-INVALID-SESSION': | case 'ERR-INVALID-SESSION': | ||||
if (!$this->getEngine()->getConduitToken()) { | if (!$this->getEngine()->getConduitToken()) { | ||||
$this->raiseLoginRequired(); | $this->raiseLoginRequired(); | ||||
} | } | ||||
break; | break; | ||||
case 'ERR-INVALID-AUTH': | case 'ERR-INVALID-AUTH': | ||||
$this->raiseInvalidAuth(); | $this->raiseInvalidAuth(); | ||||
break; | break; | ||||
} | } | ||||
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); | |||||
} | |||||
} | } |