From 8ca7b1bf4c9ca7c663e75a02a0035b05b37196a0 Mon Sep 17 00:00:00 2001 From: Vincent Jiang Date: Sat, 9 Oct 2021 11:03:47 +0800 Subject: [PATCH] source code copied from azure-storage-php for v1.5.2-common release --- ChangeLog.md | 9 ++++ composer.json | 2 +- src/Common/Exceptions/ServiceException.php | 2 +- .../Authentication/SharedKeyAuthScheme.php | 3 +- src/Common/Internal/Resources.php | 2 +- src/Common/Internal/ServiceRestProxy.php | 46 ++++++++++++------- src/Common/Internal/Utilities.php | 4 +- src/Common/SharedAccessSignatureHelper.php | 2 +- 8 files changed, 47 insertions(+), 23 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 0f3418b..00885e9 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,12 @@ +2021.09 - version 1.5.2 +* Added support for guzzle 7.3. +* Resolve some warnings when calling `Psr7\stream_for`, uses `Utils::streamFor` instead. +* Added colon to non-UTC timestamps. +* Fixed type hint for `ServiceException::getResponse()`. +* Fixed random number range that might cause an overflow in the guid generation. +* Added logic to convert to exception when promise is rejected with string. +* Compares `strlen` result with an integer instead of string. + 2020.12 - version 1.5.1 * Guzzle version is now updated to support both 6.x and 7.x. diff --git a/composer.json b/composer.json index 8afe15c..84db042 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "microsoft/azure-storage-common", - "version": "1.5.1", + "version": "1.5.2", "description": "This project provides a set of common code shared by Azure Storage Blob, Table, Queue and File PHP client libraries.", "keywords": [ "php", "azure", "storage", "sdk", "common" ], "license": "MIT", diff --git a/src/Common/Exceptions/ServiceException.php b/src/Common/Exceptions/ServiceException.php index 040e346..f262a3e 100644 --- a/src/Common/Exceptions/ServiceException.php +++ b/src/Common/Exceptions/ServiceException.php @@ -168,7 +168,7 @@ public function getDate() /** * Gets the response of the failue. * - * @return string + * @return ResponseInterface */ public function getResponse() { diff --git a/src/Common/Internal/Authentication/SharedKeyAuthScheme.php b/src/Common/Internal/Authentication/SharedKeyAuthScheme.php index afc23fc..7a7be4a 100644 --- a/src/Common/Internal/Authentication/SharedKeyAuthScheme.php +++ b/src/Common/Internal/Authentication/SharedKeyAuthScheme.php @@ -24,6 +24,7 @@ namespace MicrosoftAzure\Storage\Common\Internal\Authentication; +use GuzzleHttp\Psr7\Query; use GuzzleHttp\Psr7\Request; use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter; use MicrosoftAzure\Storage\Common\Internal\Resources; @@ -305,7 +306,7 @@ public function signRequest(Request $request) $signedKey = $this->getAuthorizationHeader( $requestHeaders, $request->getUri(), - \GuzzleHttp\Psr7\parse_query( + Query::parse( $request->getUri()->getQuery() ), $request->getMethod() diff --git a/src/Common/Internal/Resources.php b/src/Common/Internal/Resources.php index 48128d4..d3eff1c 100644 --- a/src/Common/Internal/Resources.php +++ b/src/Common/Internal/Resources.php @@ -241,7 +241,7 @@ class Resources const BEARER = 'Bearer '; // Header values - const COMMON_SDK_VERSION = '1.5.1'; + const COMMON_SDK_VERSION = '1.5.2'; const INT32_MAX = 2147483647; const INT32_MIN = -2147483648; diff --git a/src/Common/Internal/ServiceRestProxy.php b/src/Common/Internal/ServiceRestProxy.php index 1b911e5..15ef327 100644 --- a/src/Common/Internal/ServiceRestProxy.php +++ b/src/Common/Internal/ServiceRestProxy.php @@ -297,7 +297,7 @@ protected function createRequest( // add query parameters into headers if ($queryParams != null) { - $queryString = Psr7\build_query($queryParams); + $queryString = Psr7\Query::build($queryParams); $uri = $uri->withQuery($queryString); } @@ -306,7 +306,7 @@ protected function createRequest( if (empty($body)) { if (empty($headers[Resources::CONTENT_TYPE])) { $headers[Resources::CONTENT_TYPE] = Resources::URL_ENCODED_CONTENT_TYPE; - $actualBody = Psr7\build_query($postParameters); + $actualBody = Psr7\Query::build($postParameters); } } else { $actualBody = $body; @@ -402,24 +402,38 @@ function ($response) use ($expected, $requestOptions) { ); }, function ($reason) use ($expected) { - if (!($reason instanceof RequestException)) { - throw $reason; - } - $response = $reason->getResponse(); - if ($response != null) { - self::throwIfError( - $response, - $expected - ); - } else { - //if could not get response but promise rejected, throw reason. - throw $reason; - } - return $response; + return $this->onRejected($reason, $expected); } ); } + /** + * @param string|\Exception $reason Rejection reason. + * @param array|int $expected Expected Status Codes. + * + * @return ResponseInterface + */ + protected function onRejected($reason, $expected) + { + if (!($reason instanceof \Exception)) { + throw new \RuntimeException($reason); + } + if (!($reason instanceof RequestException)) { + throw $reason; + } + $response = $reason->getResponse(); + if ($response != null) { + self::throwIfError( + $response, + $expected + ); + } else { + //if could not get response but promise rejected, throw reason. + throw $reason; + } + return $response; + } + /** * Generate the request options using the given service options and stored * information. diff --git a/src/Common/Internal/Utilities.php b/src/Common/Internal/Utilities.php index 158e920..5765e4f 100644 --- a/src/Common/Internal/Utilities.php +++ b/src/Common/Internal/Utilities.php @@ -433,7 +433,7 @@ public static function convertToEdmDateTime($value) $cloned = clone $value; $cloned->setTimezone(new \DateTimeZone('UTC')); - return str_replace('+0000', 'Z', $cloned->format("Y-m-d\TH:i:s.u0O")); + return str_replace('+00:00', 'Z', $cloned->format("Y-m-d\TH:i:s.u0P")); } /** @@ -562,7 +562,7 @@ public static function getGuid() mt_rand(0, 64) + 128, // 8 bits for "clock_seq_hi", with // the most significant 2 bits being 10, // required by version 4 GUIDs. - mt_rand(0, 256), // 8 bits for "clock_seq_low" + mt_rand(0, 255), // 8 bits for "clock_seq_low" mt_rand(0, 65535), // 16 bits for "node 0" and "node 1" mt_rand(0, 65535), // 16 bits for "node 2" and "node 3" mt_rand(0, 65535) // 16 bits for "node 4" and "node 5" diff --git a/src/Common/SharedAccessSignatureHelper.php b/src/Common/SharedAccessSignatureHelper.php index 2031821..d5cc81f 100644 --- a/src/Common/SharedAccessSignatureHelper.php +++ b/src/Common/SharedAccessSignatureHelper.php @@ -291,7 +291,7 @@ protected function validateAndSanitizeStringWithArray($input, array $array) } Validate::isTrue( - strlen($input) == '', + strlen($input) == 0, sprintf( Resources::STRING_NOT_WITH_GIVEN_COMBINATION, implode(', ', $array)