You are here

function _acquia_search_derived_key in Acquia Connector 7.2

Same name and namespace in other branches
  1. 7.3 acquia_search/acquia_search.module \_acquia_search_derived_key()
  2. 7 acquia_search/acquia_search.module \_acquia_search_derived_key()

Get the derived key for the solr hmac using the information shared with acquia.com.

2 calls to _acquia_search_derived_key()
acquia_search_authenticator in acquia_search/acquia_search.module
Creates an authenticator based on a data string and HMAC-SHA1.
acquia_search_valid_response in acquia_search/acquia_search.module
Validate the authenticity of returned data using a nonce and HMAC-SHA1.

File

acquia_search/acquia_search.module, line 676
Integration between Acquia Drupal and Acquia's hosted solr search service.

Code

function _acquia_search_derived_key($env_id = NULL) {
  static $derived_key = array();
  if (empty($env_id)) {
    $env_id = 0;
  }
  if (!isset($derived_key[$env_id])) {

    // If we set an explicit environment, check if this needs to overridden
    // Use the default
    $identifier = acquia_agent_settings('acquia_identifier');
    $key = acquia_agent_settings('acquia_key');

    // See if we need to overwrite these values
    if ($env_id) {

      // Load the explicit environment and a manually set search key.
      if ($search_key = apachesolr_environment_variable_get($env_id, 'acquia_search_key')) {
        $derived_key[$env_id] = $search_key;
      }
    }

    // In any case, this is equal for all subscriptions. Also
    // even if the search sub is different, the main subscription should be
    // active
    $derived_key_salt = acquia_search_derived_key_salt();

    // We use a salt from acquia.com in key derivation since this is a shared
    // value that we could change on the AN side if needed to force any
    // or all clients to use a new derived key.  We also use a string
    // ('solr') specific to the service, since we want each service using a
    // derived key to have a separate one.
    if (empty($derived_key_salt) || empty($key) || empty($identifier)) {

      // Expired or invalid subscription - don't continue.
      $derived_key[$env_id] = '';
    }
    elseif (!isset($derived_key[$env_id])) {

      // Get the Solr core identifier from the URL, to build the correct derived key.
      $environment = apachesolr_environment_load($env_id);
      if (isset($environment['url'])) {
        $core_id = acquia_search_extract_core_id_from_environment_url($environment['url']);
        $derived_key[$env_id] = _acquia_search_create_derived_key($derived_key_salt, $core_id, $key);
      }
    }
  }
  return $derived_key[$env_id];
}