You are here

public function StatusController::access in Acquia Connector 8

Same name and namespace in other branches
  1. 8.2 src/Controller/StatusController.php \Drupal\acquia_connector\Controller\StatusController::access()
  2. 3.x src/Controller/StatusController.php \Drupal\acquia_connector\Controller\StatusController::access()

Access callback for json() callback.

1 string reference to 'StatusController::access'
acquia_connector.routing.yml in ./acquia_connector.routing.yml
acquia_connector.routing.yml

File

src/Controller/StatusController.php, line 57

Class

StatusController
Checks the current status of the Acquia Service.

Namespace

Drupal\acquia_connector\Controller

Code

public function access() {
  $request = \Drupal::request();
  $nonce = $request
    ->get('nonce', FALSE);
  $connector_config = $this
    ->config('acquia_connector.settings');

  // If we don't have all the query params, leave now.
  if (!$nonce) {
    return AccessResultForbidden::forbidden();
  }
  $sub_data = $this
    ->state()
    ->get('acquia_subscription_data');
  $sub_uuid = $this
    ->getIdFromSub($sub_data);
  if (!empty($sub_uuid)) {
    $expected_hash = hash('sha1', "{$sub_uuid}:{$nonce}");

    // If the generated hash matches the hash from $_GET['key'], we're good.
    if ($request
      ->get('key', FALSE) === $expected_hash) {
      return AccessResultAllowed::allowed();
    }
  }

  // Log the request if validation failed and debug is enabled.
  if ($connector_config
    ->get('debug')) {
    $info = [
      'sub_data' => $sub_data,
      'sub_uuid_from_data' => $sub_uuid,
      'expected_hash' => $expected_hash,
      'get' => $request->query
        ->all(),
      'server' => $request->server
        ->all(),
      'request' => $request->request
        ->all(),
    ];
    $this
      ->getLogger('acquia_agent')
      ->notice('Site status request: @data', [
      '@data' => var_export($info, TRUE),
    ]);
  }
  return AccessResultForbidden::forbidden();
}