Skip to content

Commit

Permalink
Merge pull request aws#573 from aws/v2-snapshot-copy-fix
Browse files Browse the repository at this point in the history
Temporary credentials with cross-region CopySnapshot
  • Loading branch information
jeremeamia committed May 12, 2015
2 parents 2ee4e27 + 51df27a commit 896307a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/Aws/Ec2/CopySnapshotListener.php
Expand Up @@ -59,10 +59,9 @@ private function createPresignedUrl(
) {
// Create a temporary client used to generate the presigned URL
$newClient = Ec2Client::factory(array(
'region' => $command['SourceRegion'],
'signature' => 'v4',
'key' => $client->getCredentials()->getAccessKeyId(),
'secret' => $client->getCredentials()->getSecretKey()
'region' => $command['SourceRegion'],
'signature' => 'v4',
'credentials' => $client->getCredentials(),
));

$preCommand = $newClient->getCommand(
Expand Down
9 changes: 7 additions & 2 deletions tests/Aws/Tests/Ec2/CopySnapshotListenerTest.php
@@ -1,6 +1,7 @@
<?php

namespace Aws\Tests\Ec2;
use Aws\Common\Credentials\Credentials;

/**
* @covers \Aws\Ec2\CopySnapshotListener
Expand All @@ -9,8 +10,11 @@ class CopySnapshotListenerTest extends \Guzzle\Tests\GuzzleTestCase
{
public function testAddsPresignedUrlBeforeSending()
{
$client = $this->getServiceBuilder()->get('ec2');
$client->setRegion('us-east-1');
$client = $this->getServiceBuilder()->get('ec2', array(
'credentials' => new Credentials('foo', 'bar', 'baz', strtotime('+1 hour')),
'region' => 'us-east-1'
));

$command = $client->getCommand('CopySnapshot', array(
'SourceRegion' => 'eu-west-1',
'SourceSnapshotId' => 'foo'
Expand All @@ -20,6 +24,7 @@ public function testAddsPresignedUrlBeforeSending()
$this->assertContains('DestinationRegion=us-east-1', $r);
$this->assertContains('SourceRegion%3Deu-west-1', $r);
$this->assertContains('PresignedUrl=https%3A%2F%2Fec2.eu-west-1.amazonaws.com', $r);
$this->assertContains('X-Amz-Security-Token%3Dbaz', $r);
}

public function testIgnoresOtherOperations()
Expand Down

0 comments on commit 896307a

Please sign in to comment.