Skip to content

Commit 6cc2fb1

Browse files
authored
[SimpleS3] Dont use presignUrl, use parent::getEndpoint() (#637)
* [SimpleS3] Dont use presignUrl, use parent::getEndpoint() * Fixes * Bump min-version
1 parent 0e56c17 commit 6cc2fb1

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": "^7.2.5",
1515
"ext-json": "*",
16-
"async-aws/s3": "^1.0"
16+
"async-aws/s3": "^1.2"
1717
},
1818
"extra": {
1919
"branch-alias": {

src/SimpleS3Client.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace AsyncAws\SimpleS3;
66

7-
use AsyncAws\S3\Input\GetObjectRequest;
87
use AsyncAws\S3\S3Client;
98

109
/**
@@ -17,20 +16,9 @@ class SimpleS3Client extends S3Client
1716
{
1817
public function getUrl(string $bucket, string $key): string
1918
{
20-
$input = new GetObjectRequest([
21-
'Bucket' => $bucket,
22-
'Key' => $key,
23-
]);
19+
$uri = sprintf('/%s/%s', urlencode($bucket), str_replace('%2F', '/', rawurlencode($key)));
2420

25-
$url = $this->presign($input, new \DateTimeImmutable('+10minutes'));
26-
27-
// remove all query parameters.
28-
if (false === $pos = strpos($url, '?')) {
29-
// If the client didn't have any credentials, there will not be any query string
30-
return $url;
31-
}
32-
33-
return substr($url, 0, $pos);
21+
return $this->getEndpoint($uri, [], null);
3422
}
3523

3624
/*

tests/Unit/SimpleS3ClientTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,23 @@
44

55
namespace AsyncAws\SimpleS3\Tests\Unit;
66

7-
use AsyncAws\Core\Configuration;
8-
use AsyncAws\Core\Credentials\Credentials;
97
use AsyncAws\Core\Credentials\NullProvider;
108
use AsyncAws\SimpleS3\SimpleS3Client;
119
use PHPUnit\Framework\TestCase;
1210
use Symfony\Component\HttpClient\MockHttpClient;
1311

1412
class SimpleS3ClientTest extends TestCase
1513
{
16-
public function testGetUrl()
14+
public function testGetUrlHostStyle()
1715
{
18-
$options = ['region' => 'eu-central-1'];
19-
if (\is_callable([Configuration::class, 'optionExists']) && Configuration::optionExists('pathStyleEndpoint')) {
20-
$options += ['pathStyleEndpoint' => true];
21-
}
22-
$client = new SimpleS3Client($options, new Credentials('id', 'secret'), new MockHttpClient());
16+
$client = new SimpleS3Client(['region' => 'eu-central-1'], new NullProvider(), new MockHttpClient());
2317
$url = $client->getUrl('bucket', 'images/file.jpg');
24-
self::assertSame('https://s3.eu-central-1.amazonaws.com/bucket/images/file.jpg', $url);
18+
self::assertSame('https://bucket.s3.eu-central-1.amazonaws.com/images/file.jpg', $url);
2519
}
2620

27-
public function testGetUrlWithNoCredentials()
21+
public function testGetUrlPathStyle()
2822
{
29-
$options = ['region' => 'eu-central-1'];
30-
if (\is_callable([Configuration::class, 'optionExists']) && Configuration::optionExists('pathStyleEndpoint')) {
31-
$options += ['pathStyleEndpoint' => true];
32-
}
33-
$client = new SimpleS3Client($options, new NullProvider(), new MockHttpClient());
23+
$client = new SimpleS3Client(['region' => 'eu-central-1', 'pathStyleEndpoint' => true], new NullProvider(), new MockHttpClient());
3424
$url = $client->getUrl('bucket', 'images/file.jpg');
3525
self::assertSame('https://s3.eu-central-1.amazonaws.com/bucket/images/file.jpg', $url);
3626
}

0 commit comments

Comments
 (0)