Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/worker/HeraldWebhookWorker.php
Show All 29 Lines | if ($status !== HeraldWebhookRequest::STATUS_QUEUED) { | ||||
$request_phid, | $request_phid, | ||||
HeraldWebhookRequest::STATUS_QUEUED, | HeraldWebhookRequest::STATUS_QUEUED, | ||||
$status)); | $status)); | ||||
} | } | ||||
// If we're in silent mode, permanently fail the webhook request and then | // If we're in silent mode, permanently fail the webhook request and then | ||||
// return to complete this task. | // return to complete this task. | ||||
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | ||||
$this->failRequest($request, 'hook', 'silent'); | $this->failRequest( | ||||
$request, | |||||
HeraldWebhookRequest::ERRORTYPE_HOOK, | |||||
HeraldWebhookRequest::ERROR_SILENT); | |||||
return; | return; | ||||
} | } | ||||
$hook = $request->getWebhook(); | $hook = $request->getWebhook(); | ||||
if ($hook->isDisabled()) { | if ($hook->isDisabled()) { | ||||
$this->failRequest($request, 'hook', 'disabled'); | $this->failRequest( | ||||
$request, | |||||
HeraldWebhookRequest::ERRORTYPE_HOOK, | |||||
HeraldWebhookRequest::ERROR_DISABLED); | |||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
pht( | pht( | ||||
'Associated hook ("%s") for webhook request ("%s") is disabled.', | 'Associated hook ("%s") for webhook request ("%s") is disabled.', | ||||
$hook->getPHID(), | $hook->getPHID(), | ||||
$request_phid)); | $request_phid)); | ||||
} | } | ||||
$uri = $hook->getWebhookURI(); | $uri = $hook->getWebhookURI(); | ||||
try { | try { | ||||
PhabricatorEnv::requireValidRemoteURIForFetch( | PhabricatorEnv::requireValidRemoteURIForFetch( | ||||
$uri, | $uri, | ||||
array( | array( | ||||
'http', | 'http', | ||||
'https', | 'https', | ||||
)); | )); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$this->failRequest($request, 'hook', 'uri'); | $this->failRequest( | ||||
$request, | |||||
HeraldWebhookRequest::ERRORTYPE_HOOK, | |||||
HeraldWebhookRequest::ERROR_URI); | |||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
pht( | pht( | ||||
'Associated hook ("%s") for webhook request ("%s") has invalid '. | 'Associated hook ("%s") for webhook request ("%s") has invalid '. | ||||
'fetch URI: %s', | 'fetch URI: %s', | ||||
$hook->getPHID(), | $hook->getPHID(), | ||||
$request_phid, | $request_phid, | ||||
$ex->getMessage())); | $ex->getMessage())); | ||||
} | } | ||||
$object_phid = $request->getObjectPHID(); | $object_phid = $request->getObjectPHID(); | ||||
$object = id(new PhabricatorObjectQuery()) | $object = id(new PhabricatorObjectQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($object_phid)) | ->withPHIDs(array($object_phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$object) { | if (!$object) { | ||||
$this->failRequest($request, 'hook', 'object'); | $this->failRequest( | ||||
$request, | |||||
HeraldWebhookRequest::ERRORTYPE_HOOK, | |||||
HeraldWebhookRequest::ERROR_OBJECT); | |||||
throw new PhabricatorWorkerPermanentFailureException( | throw new PhabricatorWorkerPermanentFailureException( | ||||
pht( | pht( | ||||
'Unable to load object ("%s") for webhook request ("%s").', | 'Unable to load object ("%s") for webhook request ("%s").', | ||||
$object_phid, | $object_phid, | ||||
$request_phid)); | $request_phid)); | ||||
} | } | ||||
$xaction_query = PhabricatorApplicationTransactionQuery::newQueryForObject( | $xaction_query = PhabricatorApplicationTransactionQuery::newQueryForObject( | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | $future = id(new HTTPSFuture($uri)) | ||||
->addHeader('Content-Type', 'application/json') | ->addHeader('Content-Type', 'application/json') | ||||
->addHeader('X-Phabricator-Webhook-Signature', $signature) | ->addHeader('X-Phabricator-Webhook-Signature', $signature) | ||||
->setTimeout(15) | ->setTimeout(15) | ||||
->setData($payload); | ->setData($payload); | ||||
list($status) = $future->resolve(); | list($status) = $future->resolve(); | ||||
if ($status->isTimeout()) { | if ($status->isTimeout()) { | ||||
$error_type = 'timeout'; | $error_type = HeraldWebhookRequest::ERRORTYPE_TIMEOUT; | ||||
} else { | } else { | ||||
$error_type = 'http'; | $error_type = HeraldWebhookRequest::ERRORTYPE_HTTP; | ||||
} | } | ||||
$error_code = $status->getStatusCode(); | $error_code = $status->getStatusCode(); | ||||
$request | $request | ||||
->setErrorType($error_type) | ->setErrorType($error_type) | ||||
->setErrorCode($error_code) | ->setErrorCode($error_code) | ||||
->setLastRequestEpoch(PhabricatorTime::getNow()); | ->setLastRequestEpoch(PhabricatorTime::getNow()); | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |