Skip to content

Commit

Permalink
source code copied from azure-storage-php for v1.4.0-blob release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinjiang committed Apr 26, 2019
1 parent 6fcef8b commit 8310c2e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2019.04 - version 1.4.0
* Added support for OAuth authentication.
* Resolved some issues on Linux platform.

2019.03 - version 1.3.0
* Fixed a bug where blob name '0' cannot be created.
* Documentation refinement.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ BlobEndpoint=[myBlobEndpoint];SharedAccessSignature=[sasToken]
```php
$blobClient = BlobRestProxy::createBlobService($connectionString);
```
Or for token authentication:
```php
$blobClient = BlobRestProxy::createBlobServiceWithTokenCredential($token, $connectionString);
```
### Using Middlewares
To specify the middlewares, user have to create an array with middlewares
and put it in the `$requestOptions` with key 'middlewares'. The sequence of
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microsoft/azure-storage-blob",
"version": "1.3.0",
"version": "1.4.0",
"description": "This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Blob APIs.",
"keywords": [ "php", "azure", "storage", "sdk", "blob" ],
"license": "MIT",
Expand All @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.6.0",
"microsoft/azure-storage-common": "~1.3.0"
"microsoft/azure-storage-common": "~1.4"
},
"autoload": {
"psr-4": {
Expand Down
61 changes: 61 additions & 0 deletions src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
use MicrosoftAzure\Storage\Blob\Models\SetBlobTierOptions;
use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\Authentication\TokenAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter;
use MicrosoftAzure\Storage\Common\Internal\Middlewares\CommonRequestMiddleware;
use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer;
Expand Down Expand Up @@ -171,6 +172,66 @@ public static function createBlobService(
return $blobWrapper;
}

/**
* Builds a blob service object, it accepts the following
* options:
*
* - http: (array) the underlying guzzle options. refer to
* http://docs.guzzlephp.org/en/latest/request-options.html for detailed available options
* - middlewares: (mixed) the middleware should be either an instance of a sub-class that
* implements {@see MicrosoftAzure\Storage\Common\Middlewares\IMiddleware}, or a
* `callable` that follows the Guzzle middleware implementation convention
*
* Please refer to
* https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad
* for authenticate access to Azure blobs and queues using Azure Active Directory.
*
* @param string $token The bearer token passed as reference.
* @param string $connectionString The configuration connection string.
* @param array $options Array of options to pass to the service
*
* @return BlobRestProxy
*/
public static function createBlobServiceWithTokenCredential(
&$token,
$connectionString,
array $options = []
) {
$settings = StorageServiceSettings::createFromConnectionStringForTokenCredential(
$connectionString
);

$primaryUri = Utilities::tryAddUrlScheme(
$settings->getBlobEndpointUri()
);

$secondaryUri = Utilities::tryAddUrlScheme(
$settings->getBlobSecondaryEndpointUri()
);

$blobWrapper = new BlobRestProxy(
$primaryUri,
$secondaryUri,
$settings->getName(),
$options
);

// Getting authentication scheme
$authScheme = new TokenAuthScheme(
$token
);

// Adding common request middleware
$commonRequestMiddleware = new CommonRequestMiddleware(
$authScheme,
Resources::STORAGE_API_LATEST_VERSION,
Resources::BLOB_SDK_VERSION
);
$blobWrapper->pushMiddleware($commonRequestMiddleware);

return $blobWrapper;
}

/**
* Builds an anonymous access object with given primary service
* endpoint. The service endpoint should contain a scheme and a
Expand Down
4 changes: 2 additions & 2 deletions src/Blob/Internal/BlobResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class BlobResources extends Resources
{
// @codingStandardsIgnoreStart

const BLOB_SDK_VERSION = '1.3.0';
const STORAGE_API_LATEST_VERSION = '2017-04-17';
const BLOB_SDK_VERSION = '1.4.0';
const STORAGE_API_LATEST_VERSION = '2017-11-09';

// Error messages
const INVALID_BTE_MSG = "The blob block type must exist in %s";
Expand Down

0 comments on commit 8310c2e

Please sign in to comment.