Skip to content

Commit

Permalink
Move options.ssh-options to ssh.options (#3210)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-1-anderson authored Dec 7, 2017
1 parent 2d3aeae commit d42ea79
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
12 changes: 9 additions & 3 deletions isolation/tests/LegacyAliasConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public function convertLegacyFileTestData()
'options' => [
'db-url' => 'mysql://pantheon:pw@dbserver.dev.site-id.drush.in:21086/pantheon',
'db-allows-remote' => true,
'ssh-options' => '-p 2222 -o "AddressFamily inet"',
],
'ssh' => [
'options' => '-p 2222 -o "AddressFamily inet"',
],
],
'live' =>
Expand All @@ -207,7 +209,9 @@ public function convertLegacyFileTestData()
'options' => [
'db-url' => 'mysql://pantheon:pw@dbserver.live.site-id.drush.in:10516/pantheon',
'db-allows-remote' => true,
'ssh-options' => '-p 2222 -o "AddressFamily inet"',
],
'ssh' => [
'options' => '-p 2222 -o "AddressFamily inet"',
],
],
'test' =>
Expand All @@ -222,7 +226,9 @@ public function convertLegacyFileTestData()
'options' => [
'db-url' => 'mysql://pantheon:pw@dbserver.test.site-id.drush.in:11621/pantheon',
'db-allows-remote' => true,
'ssh-options' => '-p 2222 -o "AddressFamily inet"',
],
'ssh' => [
'options' => '-p 2222 -o "AddressFamily inet"',
],
],
],
Expand Down
40 changes: 39 additions & 1 deletion src/SiteAlias/LegacyAliasConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Drush\SiteAlias;

use Symfony\Component\Yaml\Yaml;
use Dflydev\DotAccessData\Data;

/**
* Find all legacy alias files and convert them to an equivalent '.yml' file.
Expand Down Expand Up @@ -386,9 +387,30 @@ protected function fixSiteData($data)
}
ksort($data);

return $data;
return $this->remapData($data);
}

protected function remapData($data)
{
$converter = new Data($data);

foreach ($this->dataRemap() as $from => $to) {
if ($converter->has($from)) {
$converter->set($to, $converter->get($from));
$converter->remove($from);
}
}

return $converter->export();
}

/**
* Anything in the key of the returned array is converted
* and written to a new top-level item in the result.
*
* Anything NOT identified by the key in the returned array
* is moved to the 'options' element.
*/
protected function keyConversion()
{
return [
Expand All @@ -400,6 +422,22 @@ protected function keyConversion()
];
}

/**
* This table allows for flexible remapping from one location
* in the original alias to any other location in the target
* alias.
*
* n.b. Most arbitrary data from the original alias will have
* been moved into the 'options' element before this remapping
* table is consulted.
*/
protected function dataRemap()
{
return [
'options.ssh-options' => 'ssh.options',
];
}

protected function removePercentFromKey($data)
{
return
Expand Down
2 changes: 1 addition & 1 deletion tests/SiteAliasConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testSiteAliasConvert()
$this->assertObjectHasAttribute('@www-drupalvm.dev', $json);
$dev = $json->{'@drupalvm.dev'};
$this->assertSame('drupalvm.dev', $dev->host);
$this->assertSame('-o PasswordAuthentication=no -i /.vagrant.d/insecure_private_key', $dev->options->{'ssh-options'});
$this->assertSame('-o PasswordAuthentication=no -i /.vagrant.d/insecure_private_key', $dev->ssh->{'options'});
$this->assertSame('/var/www/drupalvm/drupal/vendor/drush/drush/drush', $dev->paths->{'drush-script'});
}
}

0 comments on commit d42ea79

Please sign in to comment.