You are here

function acquia_lift_get_account_info in Acquia Lift Connector 7.2

Retrieve the Acquia Lift Credentials.

Return value

array The value of the acquia_lift_account_info variable together with acquia connector credentials.

12 calls to acquia_lift_get_account_info()
AcquiaLiftLearn::getAPIInstance in plugins/agent_types/AcquiaLiftLearn.inc
Implements AcquiaLiftLearningAgentInterface::getAPIInstance().
acquia_lift_admin_form in ./acquia_lift.admin.inc
Admin form for configuring personalization backends.
acquia_lift_get_sync_operations_for_agent in ./acquia_lift.batch.inc
Returns all operations required to sync the testing components of an agent.
acquia_lift_is_configured in ./acquia_lift.module
Checks whether or not Acquia Lift has been properly configured.
acquia_lift_library in ./acquia_lift.module
Implements hook_library().

... See full list

File

./acquia_lift.module, line 459
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_get_account_info() {
  $account_info = array(
    'public_key' => '',
    'private_key' => '',
    'profiles' => array(
      'account_name' => variable_get('acquia_lift_profiles_account_name', ''),
      'hostname' => '',
      'public_key' => '',
      'secret_key' => '',
    ),
  );

  // Get Acquia Subscription Data
  $subscription_data = acquia_agent_settings('acquia_subscription_data');
  $acquia_lift_data = array();
  if (isset($subscription_data['heartbeat_data']['acquia_lift'])) {
    $acquia_lift_data = $subscription_data['heartbeat_data']['acquia_lift'];
    $default_lift_data = array(
      'status' => false,
      'decision' => array(
        'public_key' => '',
        'private_key' => '',
        'api_url' => '',
      ),
      'profile' => array(
        'js_path' => '',
        'account_name' => '',
        'hostname' => '',
        'private_key' => '',
        'secret_key' => '',
      ),
    );

    // make sure there is always the base set that we can rely on. This
    // prevents us from forcing an isset before working with the data.
    $acquia_lift_data = array_merge($default_lift_data, $acquia_lift_data);
  }

  // Set default url
  $account_info['api_url'] = variable_get('acquia_lift_api_url', '');

  // Find out if there is Acquia Lift information in the provided subscription information.
  if (isset($acquia_lift_data['status']) && $acquia_lift_data['status'] == TRUE) {
    foreach ($acquia_lift_data['decision'] as $key => $value) {
      switch ($key) {
        case "public_key":
        case "private_key":

          // If it was overridden in settings.php - do not override again
          // with Acquia Network creds.
          $account_info[$key] = empty($account_info[$key]) ? $value : $account_info[$key];
          break;
      }
    }
    if (empty($account_info['api_url'])) {
      if (empty($acquia_lift_data['decision']['hostname'])) {
        $account_info['api_url'] = 'us-east-1-decision.lift.acquia.com';
      }
      else {
        $account_info['api_url'] = $acquia_lift_data['decision']['hostname'];
      }
    }
    foreach ($acquia_lift_data['profile'] as $key => $value) {
      switch ($key) {
        case "js_path":
          $variable_name = 'acquia_lift_profiles_js_path';

          // Strip any http/https prefix
          $value = preg_replace('/(^[a-z]+:\\/\\/)/i', '', $value);

          // js path is a special case as we require it also for regular
          // Acquia Lift. Therefor we add it to our main data set as an
          // exception. If it was overridden in settings.php - do not
          // override again with Acquia Network creds.
          $account_info[$key] = empty($account_info[$key]) ? $value : $account_info[$key];
          break;
        case "account_name":
          $variable_name = 'acquia_lift_profiles_account_name';
          break;
        case "hostname":
          $variable_name = 'acquia_lift_profiles_api_url';
          break;
        case "public_key":
          $variable_name = 'acquia_lift_profiles_access_key';
          break;
        case "secret_key":
          $variable_name = 'acquia_lift_profiles_secret_key';
          break;
        default:
          $variable_name = false;
          break;
      }

      // Set variable if it was not set.
      if ($variable_name) {
        _acquia_lift_set_variable_if_not_set($variable_name, $value);
        $account_info['profiles'][$key] = empty($account_info['profiles'][$key]) ? $value : $account_info['profiles'][$key];
      }
    }

    // unset the js_path from profiles since that is a special case
    // @todo Get rid of the special case...
    unset($account_info['profiles']['js_path']);
  }

  // Whether or not to check the response value.
  $account_info['validate_response'] = variable_get('acquia_lift_validate_response', TRUE);
  return $account_info;
}