Path: blob/master/src/applications/herald/controller/HeraldWebhookKeyController.php
12262 views
<?php12final class HeraldWebhookKeyController3extends HeraldWebhookController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();78$hook = id(new HeraldWebhookQuery())9->setViewer($viewer)10->withIDs(array($request->getURIData('id')))11->requireCapabilities(12array(13PhabricatorPolicyCapability::CAN_VIEW,14PhabricatorPolicyCapability::CAN_EDIT,15))16->executeOne();17if (!$hook) {18return new Aphront404Response();19}2021$action = $request->getURIData('action');22if ($action === 'cycle') {23if (!$request->isFormPost()) {24return $this->newDialog()25->setTitle(pht('Regenerate HMAC Key'))26->appendParagraph(27pht(28'Regenerate the HMAC key used to sign requests made by this '.29'webhook?'))30->appendParagraph(31pht(32'Requests which are currently authenticated with the old key '.33'may fail.'))34->addCancelButton($hook->getURI())35->addSubmitButton(pht('Regnerate Key'));36} else {37$hook->regenerateHMACKey()->save();38}39}4041$form = id(new AphrontFormView())42->setViewer($viewer)43->appendControl(44id(new AphrontFormTextControl())45->setLabel(pht('HMAC Key'))46->setValue($hook->getHMACKey()));4748return $this->newDialog()49->setTitle(pht('Webhook HMAC Key'))50->appendForm($form)51->addCancelButton($hook->getURI(), pht('Done'));52}535455}565758