Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/controller/HeraldWebhookKeyController.php
12262 views
1
<?php
2
3
final class HeraldWebhookKeyController
4
extends HeraldWebhookController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
9
$hook = id(new HeraldWebhookQuery())
10
->setViewer($viewer)
11
->withIDs(array($request->getURIData('id')))
12
->requireCapabilities(
13
array(
14
PhabricatorPolicyCapability::CAN_VIEW,
15
PhabricatorPolicyCapability::CAN_EDIT,
16
))
17
->executeOne();
18
if (!$hook) {
19
return new Aphront404Response();
20
}
21
22
$action = $request->getURIData('action');
23
if ($action === 'cycle') {
24
if (!$request->isFormPost()) {
25
return $this->newDialog()
26
->setTitle(pht('Regenerate HMAC Key'))
27
->appendParagraph(
28
pht(
29
'Regenerate the HMAC key used to sign requests made by this '.
30
'webhook?'))
31
->appendParagraph(
32
pht(
33
'Requests which are currently authenticated with the old key '.
34
'may fail.'))
35
->addCancelButton($hook->getURI())
36
->addSubmitButton(pht('Regnerate Key'));
37
} else {
38
$hook->regenerateHMACKey()->save();
39
}
40
}
41
42
$form = id(new AphrontFormView())
43
->setViewer($viewer)
44
->appendControl(
45
id(new AphrontFormTextControl())
46
->setLabel(pht('HMAC Key'))
47
->setValue($hook->getHMACKey()));
48
49
return $this->newDialog()
50
->setTitle(pht('Webhook HMAC Key'))
51
->appendForm($form)
52
->addCancelButton($hook->getURI(), pht('Done'));
53
}
54
55
56
}
57
58