Skip to content

Instantly share code, notes, and snippets.

@paullinney
Last active July 13, 2016 08:29
Show Gist options
  • Save paullinney/32ceb492b07c09ef282cc95a8dfc0d6b to your computer and use it in GitHub Desktop.
Save paullinney/32ceb492b07c09ef282cc95a8dfc0d6b to your computer and use it in GitHub Desktop.
Acquia Auth to Selenium Client for Update (post)
/**
* Update a Solarium client object for an 'Update' query
* with acquia authentication
*
* Needs to add following to, Solarium\Plugin\BufferedAdd\BufferedAdd.php:flush()
* after addDocuments call, so all flush queries get auth cookies:
*
* $sdsSolrBase = new SolrBase();
* $this->client = $sdsSolrBase->clientAttachAuth($this->client, $this->updateQuery);
*
* @param $client
*
* @param $update
*
* @return $client
*/
function clientAttachAuth($client, $update) {
$request = $client->createRequest($update);
$endpoint = $client->getEndpoint();
// Acquia bit
$signature = new Signature($endpoint->getKey());
$acquia_solr_hmac = $signature->generate($request->getRawData());
$acquia_solr_time = $signature->getRequestTime();
$acquia_solr_nonce = $signature->getNonce();
// Add cookies to request through Solarium adapter Zend2Http
$client->setAdapter('Solarium\Core\Client\Adapter\Zend2Http');
$zendHttp = $client->getAdapter()->getZendHttp();
$zendHttp->addCookie('acquia_solr_time', $acquia_solr_time);
$zendHttp->addCookie('acquia_solr_nonce', $acquia_solr_nonce);
$zendHttp->addCookie('acquia_solr_hmac', $acquia_solr_hmac);
return $client;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment