diff --git a/src/Identity/S3/S3ExpressIdentityProvider.php b/src/Identity/S3/S3ExpressIdentityProvider.php index 007968b33d..100bc228ab 100644 --- a/src/Identity/S3/S3ExpressIdentityProvider.php +++ b/src/Identity/S3/S3ExpressIdentityProvider.php @@ -23,22 +23,20 @@ public function __construct(string $clientRegion, array $config = []) public function __invoke($command) { - return function () use ($command) { - $bucket = $command['Bucket']; - if ($identity = $this->cache->get($bucket)) { - if (!$identity->isExpired()) { - return Promise\Create::promiseFor($identity); - } + $bucket = $command['Bucket']; + if ($identity = $this->cache->get($bucket)) { + if (!$identity->isExpired()) { + return Promise\Create::promiseFor($identity); } - $response = $this->s3Client->createSession(['Bucket' => $bucket]); - $identity = new Aws\Identity\S3\S3ExpressIdentity( - $response['Credentials']['AccessKeyId'], - $response['Credentials']['SecretAccessKey'], - $response['Credentials']['SessionToken'], - $response['Credentials']['Expiration']->getTimestamp() - ); - $this->cache->set($bucket, $identity); - return Promise\Create::promiseFor($identity); - }; + } + $response = $this->s3Client->createSession(['Bucket' => $bucket]); + $identity = new Aws\Identity\S3\S3ExpressIdentity( + $response['Credentials']['AccessKeyId'], + $response['Credentials']['SecretAccessKey'], + $response['Credentials']['SessionToken'], + $response['Credentials']['Expiration']->getTimestamp() + ); + $this->cache->set($bucket, $identity); + return Promise\Create::promiseFor($identity); } } diff --git a/src/Middleware.php b/src/Middleware.php index 3a779e47b0..dec46c096b 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -147,7 +147,7 @@ function (TokenInterface $token) } if ($signer instanceof S3ExpressSignature) { - $credentialPromise = $config['s3_express_identity_provider']($command)(); + $credentialPromise = $config['s3_express_identity_provider']($command); } else { $credentialPromise = $credProvider(); } diff --git a/src/S3/S3Client.php b/src/S3/S3Client.php index 99e048b24e..c4e239c959 100644 --- a/src/S3/S3Client.php +++ b/src/S3/S3Client.php @@ -516,7 +516,7 @@ public function createPresignedRequest(CommandInterface $command, $expires, arra ); if ($signature_version == 'v4-s3express') { $provider = $this->getConfig('s3_express_identity_provider'); - $credentials = $provider($command)()->wait(); + $credentials = $provider($command)->wait(); } else { $credentials = $this->getCredentials()->wait(); } diff --git a/tests/Identity/S3Express/S3ExpressIdentityProviderTest.php b/tests/Identity/S3Express/S3ExpressIdentityProviderTest.php index 66ba98efdd..54d96ab904 100644 --- a/tests/Identity/S3Express/S3ExpressIdentityProviderTest.php +++ b/tests/Identity/S3Express/S3ExpressIdentityProviderTest.php @@ -45,7 +45,7 @@ public function testProvidesIdentity() 'region', ['client' => $client] ); - $identity = $provider($cmd)()->wait(); + $identity = $provider($cmd)->wait(); self::assertSame('foo', $identity->getAccessKeyId()); self::assertSame('bar', $identity->getSecretKey()); self::assertSame('baz', $identity->getSecurityToken()); @@ -65,8 +65,8 @@ public function testCachesIdentity() 'region', ['client' => $client] ); - $provider($cmd)()->wait(); - $identity = $provider($cmd)()->wait(); + $provider($cmd)->wait(); + $identity = $provider($cmd)->wait(); self::assertSame('foo', $identity->getAccessKeyId()); self::assertSame('bar', $identity->getSecretKey()); self::assertSame('baz', $identity->getSecurityToken()); @@ -88,8 +88,8 @@ public function testRefreshesCache() 'region', ['client' => $client] ); - $provider($cmd)()->wait(); - $identity = $provider($cmd)()->wait(); + $provider($cmd)->wait(); + $identity = $provider($cmd)->wait(); self::assertSame($after, $identity->getExpiration()); } } diff --git a/tests/S3/S3ClientTest.php b/tests/S3/S3ClientTest.php index 3df9a2938c..cf54918ad3 100644 --- a/tests/S3/S3ClientTest.php +++ b/tests/S3/S3ClientTest.php @@ -1229,15 +1229,13 @@ public function testS3ExpressAuth() $client = new S3Client([ 'region' => 'us-east-1', 's3_express_identity_provider' => function ($command) { - return static function () { - $identity = new S3ExpressIdentity( - 'foo', - 'bar', - 'baz', - time() + 4000 - ); - return Promise\Create::promiseFor($identity); - }; + $identity = new S3ExpressIdentity( + 'foo', + 'bar', + 'baz', + time() + 4000 + ); + return Promise\Create::promiseFor($identity); }, 'http_handler' => function (RequestInterface $r) { $this->assertSame('baz', $r->getHeaderLine('x-amz-s3session-token')); @@ -1302,15 +1300,13 @@ public function testS3ExpressPresignedUrl() 'version' => 'latest', 'region' => 'us-east-1', 's3_express_identity_provider' => function ($command) { - return static function () { - $identity = new S3ExpressIdentity( - 'foo', - 'bar', - 'baz', - time() + 4000 - ); - return Promise\Create::promiseFor($identity); - }; + $identity = new S3ExpressIdentity( + 'foo', + 'bar', + 'baz', + time() + 4000 + ); + return Promise\Create::promiseFor($identity); }, ]); $client->getHandlerList()->appendBuild(