Skip to content

Commit

Permalink
source code copied from azure-storage-php for v1.5.2-common release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinjiang committed Oct 9, 2021
1 parent e573803 commit 8ca7b1b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
9 changes: 9 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function getDate()
/**
* Gets the response of the failue.
*
* @return string
* @return ResponseInterface
*/
public function getResponse()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Common/Internal/Authentication/SharedKeyAuthScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Internal/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
46 changes: 30 additions & 16 deletions src/Common/Internal/ServiceRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Internal/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

/**
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/Common/SharedAccessSignatureHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8ca7b1b

Please sign in to comment.