You are here

public function ContentHubWebhookController::registerWebhook in Acquia Content Hub 8

Processing the registration of a webhook.

Parameters

array $webhook: The webhook coming from Plexus.

Return value

\Acquia\ContentHubClient\hmacv1\ResponseSigner|\Symfony\Component\HttpFoundation\Response The Response.

1 call to ContentHubWebhookController::registerWebhook()
ContentHubWebhookController::receiveWebhook in src/Controller/ContentHubWebhookController.php
Process a webhook.

File

src/Controller/ContentHubWebhookController.php, line 304

Class

ContentHubWebhookController
Controller for Content Hub Imported Entities.

Namespace

Drupal\acquia_contenthub\Controller

Code

public function registerWebhook(array $webhook) {
  $uuid = isset($webhook['uuid']) ? $webhook['uuid'] : FALSE;
  $origin = $this->config
    ->get('origin');
  $api_key = $this->config
    ->get('api_key');
  if ($uuid && $webhook['initiator'] == $origin && $webhook['publickey'] == $api_key) {
    $secret = $this->config
      ->get('secret_key');

    // Creating a response.
    $response = new ResponseSigner($api_key, $secret);
    $response
      ->setContent('{}');
    $response
      ->setResource('');
    $response
      ->setStatusCode(ResponseSigner::HTTP_OK);
    $response
      ->signWithCustomHeaders(FALSE);
    $response
      ->signResponse();
    return $response;
  }
  else {
    $ip_address = $this->request
      ->getClientIp();
    $message = new FormattableMarkup('Webhook [from IP = @IP] rejected (initiator and/or publickey do not match local settings): @whook', [
      '@IP' => $ip_address,
      '@whook' => print_r($webhook, TRUE),
    ]);
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->debug($message);
    return new Response('');
  }
}