You are here

function apigee_edge_requirements in Apigee Edge 8

Implements hook_requirements().

File

./apigee_edge.install, line 34
Copyright 2018 Google Inc.

Code

function apigee_edge_requirements($phase) {
  $requirements = [];
  if ($phase === 'install') {

    // This should be checked only if Drupal is installed.
    if (!InstallerKernel::installationAttempted()) {
      $missing_mails = \Drupal::entityQuery('user')
        ->notExists('mail')
        ->condition('uid', '0', '<>')
        ->execute();
      if (!empty($missing_mails)) {
        $requirements['apigee_edge_missing_mail'] = [
          'title' => t('Apigee Edge'),
          'description' => t('The module can be installed only if all users have emails in Drupal, because email is a required attribute on Apigee Edge.'),
          'severity' => REQUIREMENT_ERROR,
        ];
      }
    }
  }
  elseif ($phase === 'runtime') {

    /** @var \Drupal\apigee_edge\SDKConnectorInterface $sdk_connector */
    $sdk_connector = \Drupal::service('apigee_edge.sdk_connector');
    try {
      $sdk_connector
        ->testConnection();
    } catch (\Exception $exception) {
      $requirements['apigee_edge_connection_error'] = [
        'title' => t('Apigee Edge'),
        'value' => $exception
          ->getMessage(),
        'description' => t('Cannot connect to Apigee Edge server. You have either given wrong credential details or the Apigee Edge server is unreachable. Visit the <a href=":url">Apigee Edge general settings</a> page to get more information.', [
          ':url' => Url::fromRoute('apigee_edge.settings', [
            'destination' => 'admin/reports/status',
          ])
            ->toString(),
        ]),
        'severity' => REQUIREMENT_WARNING,
      ];
    }
    $auth_config = \Drupal::config('apigee_edge.auth');
    if ($key_id = $auth_config
      ->get('active_key')) {

      // Warning message if insecure Configuration Key provider is being used.
      $key = \Drupal::service('key.repository')
        ->getKey($key_id);
      if ($key && $key
        ->getKeyProvider()
        ->getPluginId() === "config") {
        $requirements['apigee_edge_insecure_config_key_provider'] = [
          'title' => t('Apigee Edge'),
          'description' => t('Edge connection settings are stored in Drupal’s configuration system, which is not designed to store sensitive information. When installing Kickstart for uses other than local development, we highly recommend changing the Apigee Edge connection key provider to a more secure storage location. <a href="https://www.drupal.org/docs/8/modules/apigee-developer-portal-kickstart/apigee-kickstart-faqs#s-during-installation-a-warning-is-displayed-that-the-apigee-edge-connection-key-provider-is-not-considered-secure-what-should-i-do" target="_blank">Learn more.</a>'),
          'severity' => REQUIREMENT_WARNING,
        ];
      }

      // Warning message in status report if using basic auth.
      try {
        if ($key && $key
          ->getKeyType() instanceof EdgeKeyTypeInterface && $key
          ->getKeyType()
          ->getAuthenticationType($key) === EdgeKeyTypeInterface::EDGE_AUTH_TYPE_BASIC) {
          $requirements['apigee_edge_http_basic_auth'] = [
            'title' => t('Apigee Edge'),
            'description' => t('Apigee Edge HTTP basic authentication will be deprecated. Please choose another authentication method. Visit the <a href=":url">Apigee Edge general settings</a> page to get more information.', [
              ':url' => Url::fromRoute('apigee_edge.settings', [
                'destination' => 'admin/reports/status',
              ])
                ->toString(),
            ]),
            'severity' => REQUIREMENT_WARNING,
          ];
        }
      } catch (Exception $e) {

        // Do nothing.
      }
    }
  }
  return $requirements;
}