Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -2,9 +2,7 @@
namespace Aws\Credentials;
use Aws\Exception\CredentialsException;
use GuzzleHttp\Promise;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Promise\PromiseInterface;
use Psr\Http\Message\ResponseInterface;
@@ -14,19 +12,24 @@ use Psr\Http\Message\ResponseInterface;
*/
class EcsCredentialProvider
{
const SERVER_URI = 'http://169.254.170.2/';
const SERVER_URI = 'http://169.254.170.2';
const ENV_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
/** @var callable */
private $client;
/**
* The constructor accepts following options:
* - timeout: (optional) Connection timeout, in seconds, default 1.0
* - client: An EcsClient to make request from
*
* @param array $config Configuration options
*/
public function __construct(array $config = [])
{
$this->timeout = isset($config['timeout']) ? $config['timeout'] : 1.0;
$this->client = isset($config['client'])
? $config['client'] // internal use only
? $config['client']
: \Aws\default_http_handler();
}
@@ -36,39 +39,16 @@ class EcsCredentialProvider
* @return PromiseInterface
*/
public function __invoke()
{
return $this->request($this->getEcsUri());
}
/**
* Fetch credential URI from ECS environment variable
*
* @return string Returns ECS URI
* @throws CredentialsException If the credential URI path cannot be found
*/
private function getEcsUri()
{
$creds_uri = getenv(self::ENV_URI);
if (!$creds_uri) {
throw new CredentialsException(
"Unable to find an ECS environment variable value for "
. self::ENV_URI
);
}
return $creds_uri;
}
/**
* @param string $url
* @return PromiseInterface Returns a promise that is fulfilled with the
* body of the response as a string.
*/
private function request($url)
{
$client = $this->client;
$request = new Request('GET', new Uri(self::SERVER_URI . $url));
return $client($request)->then(function (ResponseInterface $response) {
$request = new Request('GET', self::getEcsUri());
return $client(
$request,
[
'timeout' => $this->timeout,
'proxy' => '',
]
)->then(function (ResponseInterface $response) {
$result = $this->decodeResult((string) $response->getBody());
return new Credentials(
$result['AccessKeyId'],
@@ -77,6 +57,7 @@ class EcsCredentialProvider
strtotime($result['Expiration'])
);
})->otherwise(function ($reason) {
$reason = is_array($reason) ? $reason['exception'] : $reason;
$msg = $reason->getMessage();
throw new CredentialsException(
"Error retrieving credential from ECS ($msg)"
@@ -84,6 +65,17 @@ class EcsCredentialProvider
});
}
/**
* Fetch credential URI from ECS environment variable
*
* @return string Returns ECS URI
*/
private function getEcsUri()
{
$creds_uri = getenv(self::ENV_URI);
return self::SERVER_URI . $creds_uri;
}
private function decodeResult($response)
{
$result = json_decode($response, true);