As it stands, it is very difficult to automate certain workflows that use Acquia Search. In the Acquia Agent settings page there is a button called 'Save Keys'. If you override these values in a settings file (for instance, a staging settings file vs. a production settings file), the 'Save Keys' button needs to be pressed for the new keys to actually work. The fact that this requires human interaction makes it difficult to automate deployment of Drupal sites that use Acquia Search.

I've created a "save-keys" drush command that lets you save your Acquia Network keys and check your subscription. This emulates the 'Save Key's button and makes it automatable.

Patch to follow shortly...

Comments

pifantastic’s picture

StatusFileSize
new1.87 KB

First crack at a patch for this.

pwolanin’s picture

Status: Active » Needs work

thanks sounds like a good idea.

However, there are a couple issues with the patch.

1) do we really need to specify --key? Will you ever save just the key or identifier?

2) Various other actions occur when the form is submitted - for Drupal 6 we might need to simulate that via drupal_execute()

nick_vh’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Needs work » Fixed

We now support to save a variable using drush solr-variable-set. Any variable will be saved in $environment['conf] array.
If you save the derived key as "acquia_search_key" it will overwrite that variable.

You can easily calculate the derived key

// Getting our default ID, can be custom
$identifier = acquia_agent_settings('acquia_identifier');
// Getting our default key, could be set custom
$key = acquia_agent_settings('acquia_key');
$subscription = acquia_agent_settings('acquia_subscription_data');
$salt = isset($subscription['derived_key_salt']) ? $subscription['derived_key_salt'] : '';
$derivation_string = $identifier . 'solr' . $salt;
$derived_key =  hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $key);
apachesolr_environment_variable_set('MYENV', 'acquia_search_key', $derived_key);

This is a risky undertaking, so please understand what you are doing!

pwolanin’s picture

Status: Fixed » Active

I don't think that satisfies the request in the general case?

nick_vh’s picture

No, but it would be a start. We could create a drush command that uses this code or he could. Depending on the time it takes.

I do like the idea of having a way to store a derived key in a sub using a small function and/or drush. This function could be ui-able whenever this is necessary.

nick_vh’s picture

ah I see, I marked it as fixed. Mistake of mine :-)

nick_vh’s picture

StatusFileSize
new1.94 KB

Took a crack at this while on the train towards London drupal.org codesprint.

nick_vh’s picture

hmm, odd - didnt take my drush file with it

nick_vh’s picture

StatusFileSize
new6.38 KB

second time should be better

pwolanin’s picture

Status: Active » Needs work

Thanks for the start on this. I agree this is a better UX than having to get the derived key out of another site.

However, it can't quite work this way because each subscription has a unique salt that returns via xml-rpc for making the derived key.

In order for this to work, we'd need to see if we can make that xml-rpc call and get the response ideally without triggering a heartbeat on the network.

nick_vh’s picture

Status: Needs work » Needs review
StatusFileSize
new5.92 KB

Took the comments in mind and included should be an improved patch with a per-client salt

What it does is simplifying

function acquia_agent_check_subscription($params = array()) {

It now incorporates

function acquia_agent_get_subscription($params = array(), $identifier = NULL, $key = NULL, $acquia_network_address = NULL) {

Using this new function we can easily fetch subscription data

nick_vh’s picture

StatusFileSize
new6.09 KB

Small update

nick_vh’s picture

StatusFileSize
new11.42 KB

now with the drush file..

nick_vh’s picture

Status: Needs review » Needs work
+++ b/acquia_search/drush/acquia_search.drush.incundefined
@@ -0,0 +1,122 @@
+      'drush acquia-search-set-derived-key --env-id acquia_search_server_1_1 --acquia-id AAAA-12345 --acquia-key abcdefgijklmnopqrstuvw12345' => 'Set this environment to use the following keys.',

The example code is still wrong, should correct that. Not sure if the drush command names are appropriate

pwolanin’s picture

Status: Needs work » Needs review

Looks much better - need to check over a little more. So I guess in the (rare) case the salt changes they need to run the command again?

nick_vh’s picture

Yep, they have to run the command again. But if they go this far to set a custom derived key for an environment, they should be aware of the fact that this could change.

We could not change this derived key automatically because we have no clue about the key / id that actually was used to generate the derived key.

nick_vh’s picture

StatusFileSize
new11.42 KB

Seems like I forgot to pass the key when validating the data

nick_vh’s picture

StatusFileSize
new12.18 KB

Friday is a horribly day to submit patches it seems,

trying that again :)

nick_vh’s picture

StatusFileSize
new12.61 KB

Thanks to Irek, he found a bug that I have no idea how that could have gotten in there.

Patch included

nick_vh’s picture

There is still a race condition when enabling the module, so that's a pending task + It might be good if the main acquia search sub cannot be overridden, as a backup to your original subscription.

nick_vh’s picture

StatusFileSize
new12.58 KB

This patch fixes both problems
Please test it with the added environment (acquia_search_server_1) and another one, manually added or cloned

irek02’s picture

Status: Needs review » Reviewed & tested by the community

The patch works properly. While having same subscription for acquia connector and search, I was able to switch the search one to another subscription with no problems. It also didn't let me modify the subscription info for the original search environment, which worked as expected. Thanks to hard work of Nick.
I think it's good to go in the code.

coltrane’s picture

Status: Reviewed & tested by the community » Fixed

Patch works and looks mostly good. Comments should be proper sentences but that can be cleaned up separately. Committed http://drupalcode.org/project/acquia_connector.git/commit/91a055c

nick_vh’s picture

coltrane, you forgot to do git add ., the drush file is not included now...

nick_vh’s picture

Status: Fixed » Needs work
nick_vh’s picture

we also want to push this change to 6.x-2.x and acquia_search-6.x-3.x

nick_vh’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
StatusFileSize
new5.2 KB

Patch for 6.x-2.x

nick_vh’s picture

Status: Needs work » Fixed

Committed to 6.x-2.x-dev and added drush file to 7.x-2.x-dev

nick_vh’s picture

StatusFileSize
new534 bytes

Looks like a very critical part was not seen, the environment is never saved anymore, leading to outdated timestamps

nick_vh’s picture

committed to 6.x-2.x and 7.x-2.x

Automatically closed -- issue fixed for 2 weeks with no activity.