Skip to content

Commit

Permalink
source code copied from azure-storage-php for v1.2.0-blob release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinjiang committed Aug 2, 2018
1 parent 9a8c8a8 commit 6a89f27
Show file tree
Hide file tree
Showing 11 changed files with 450 additions and 27 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2018.08 - version 1.2.0

* Updated Azure Storage API version from 2016-05-31 to 2017-04-17.
* Added method `setBlobTier` method in `BlobRestProxy` to set blob tiers.
* Added support setting or getting blob tiers related properties when creating blobs, listing blobs, getting blob properties and copying blobs.
* Set the `getBlobUrl()` method in `BlobRestProxy` visibility to public.

2018.04 - version 1.1.0

* Private method BlobRestProxy::getBlobUrl now preserves primary URI path when exists.
Expand All @@ -12,7 +19,7 @@

* Created `BlobSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
* Added static builder methods `createBlobService` and `createContainerAnonymousAccess` into `BlobRestProxy`.
* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Removed `dataSerializer` parameter from `BlobRestProxy` constructor.
* Added `setUseTransactionalMD5` method for options of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent`. Default false, enabling transactional MD5 validation will take more cpu and memory resources.
* Fixed a bug that CopyBlobFromURLOptions not found.
* Deprecated PHP 5.5 support.
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.1.0",
"version": "1.2.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.1"
"microsoft/azure-storage-common": "~1.2.0"
},
"autoload": {
"psr-4": {
Expand Down
103 changes: 96 additions & 7 deletions src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use MicrosoftAzure\Storage\Blob\Models\CreateBlobSnapshotOptions;
use MicrosoftAzure\Storage\Blob\Models\CreateBlobSnapshotResult;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\CreatePageBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataResult;
Expand All @@ -71,6 +72,7 @@
use MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult;
use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesOptions;
use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesResult;
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\Http\HttpFormatter;
Expand Down Expand Up @@ -376,7 +378,7 @@ private function createPath($container, $blob = '')
*
* @return string
*/
private function getBlobUrl($container, $blob)
public function getBlobUrl($container, $blob)
{
$encodedBlob = $this->createPath($container, $blob);
$uri = $this->getPsrPrimaryUri();
Expand Down Expand Up @@ -1337,6 +1339,82 @@ public function setContainerMetadataAsync(
);
}

/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param Models\SetBlobTierOptions $options optional parameters
*
* @return void
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTier(
$container,
$blob,
Models\SetBlobTierOptions $options = null
) {
$this->setBlobTierAsync($container, $blob, $options)->wait();
}

/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param Models\SetBlobTierOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTierAsync(
$container,
$blob,
Models\SetBlobTierOptions $options = null
)
{
Validate::canCastAsString($container, 'container');
Validate::canCastAsString($blob, 'blob');
Validate::notNullOrEmpty($blob, 'blob');

$method = Resources::HTTP_PUT;
$headers = array();
$postParams = array();
$queryParams = array();
$path = $this->createPath($container, $blob);

if (is_null($options)) {
$options = new SetBlobTierOptions();
}

$this->addOptionalQueryParam(
$queryParams,
Resources::QP_COMP,
'tier'
);

$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);

$options->setLocationMode(LocationMode::PRIMARY_ONLY);

return $this->sendAsync(
$method,
$headers,
$queryParams,
$postParams,
$path,
array(Resources::STATUS_OK, Resources::STATUS_ACCEPTED),
Resources::EMPTY_STRING,
$options
);
}

/**
* Lists all of the blobs in the given container.
*
Expand Down Expand Up @@ -1462,7 +1540,7 @@ public function listBlobsAsync(
* The page blob size must be
* aligned to a 512-byte
* boundary.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
*
Expand All @@ -1472,7 +1550,7 @@ public function createPageBlob(
$container,
$blob,
$length,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobOptions $options = null
) {
return $this->createPageBlobAsync(
$container,
Expand All @@ -1494,7 +1572,7 @@ public function createPageBlob(
* The page blob size must be
* aligned to a 512-byte
* boundary.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -1504,7 +1582,7 @@ public function createPageBlobAsync(
$container,
$blob,
$length,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobOptions $options = null
) {
Validate::canCastAsString($container, 'container');
Validate::canCastAsString($blob, 'blob');
Expand All @@ -1519,7 +1597,7 @@ public function createPageBlobAsync(
$path = $this->createPath($container, $blob);

if (is_null($options)) {
$options = new CreateBlobOptions();
$options = new CreatePageBlobOptions();
}

$this->addOptionalHeader(
Expand All @@ -1537,6 +1615,11 @@ public function createPageBlobAsync(
Resources::X_MS_BLOB_SEQUENCE_NUMBER,
$options->getSequenceNumber()
);
$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);
$headers = $this->addCreateBlobOptionalHeaders($options, $headers);

$options->setLocationMode(LocationMode::PRIMARY_ONLY);
Expand Down Expand Up @@ -3521,7 +3604,7 @@ public function saveBlobToFile(
* @param Models\GetBlobOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @throws \Exception
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx
*/
public function saveBlobToFileAsync(
Expand Down Expand Up @@ -4024,6 +4107,12 @@ public function copyBlobFromURLAsync(
$options->getSourceLeaseId()
);

$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);

$options->setLocationMode(LocationMode::PRIMARY_ONLY);

return $this->sendAsync(
Expand Down
8 changes: 6 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.1.0';
const STORAGE_API_LATEST_VERSION = '2016-05-31';
const BLOB_SDK_VERSION = '1.2.0';
const STORAGE_API_LATEST_VERSION = '2017-04-17';

// Error messages
const INVALID_BTE_MSG = "The blob block type must exist in %s";
Expand Down Expand Up @@ -83,6 +83,10 @@ class BlobResources extends Resources
const X_MS_SERVER_ENCRYPTED = 'x-ms-server-encrypted';
const X_MS_INCREMENTAL_COPY = 'x-ms-incremental-copy';
const X_MS_COPY_DESTINATION_SNAPSHOT = 'x-ms-copy-destination-snapshot';
const X_MS_ACCESS_TIER = 'x-ms-access-tier';
const X_MS_ACCESS_TIER_INFERRED = 'x-ms-access-tier-inferred';
const X_MS_ACCESS_TIER_CHANGE_TIME = 'x-ms-access-tier-change-time';
const X_MS_ARCHIVE_STATUS = 'x-ms-archive-status';
const MAX_BLOB_SIZE = 'x-ms-blob-condition-maxsize';
const MAX_APPEND_POSITION = 'x-ms-blob-condition-appendpos';
const SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL = 'x-ms-if-sequence-number-le';
Expand Down
61 changes: 47 additions & 14 deletions src/Blob/Internal/IBlob.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use MicrosoftAzure\Storage\Blob\Models as BlobModels;
use MicrosoftAzure\Storage\Common\Models\ServiceOptions;
use MicrosoftAzure\Storage\Common\Models\ServiceProperties;
use MicrosoftAzure\Storage\Common\Models\GetServiceStats;
use MicrosoftAzure\Storage\Common\Models\Range;

/**
Expand Down Expand Up @@ -406,7 +405,7 @@ public function listBlobsAsync(
* @param int $length specifies the maximum size
* for the page blob, up to 1 TB. The page blob size must be aligned to
* a 512-byte boundary.
* @param BlobModels\CreateBlobOptions $options optional parameters
* @param BlobModels\CreatePageBlobOptions $options optional parameters
*
* @return BlobModels\CopyBlobResult
*
Expand All @@ -416,7 +415,7 @@ public function createPageBlob(
$container,
$blob,
$length,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobOptions $options = null
);

/**
Expand All @@ -431,7 +430,7 @@ public function createPageBlob(
* 1 TB. The page blob size
* must be aligned to a
* 512-byte boundary.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreatePageBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand All @@ -441,7 +440,7 @@ public function createPageBlobAsync(
$container,
$blob,
$length,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobOptions $options = null
);

/**
Expand All @@ -450,9 +449,9 @@ public function createPageBlobAsync(
*
* @param string $container The container name.
* @param string $blob The blob name.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
* @return BlobModels\PutBlobResult
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx
*/
Expand All @@ -469,7 +468,7 @@ public function createAppendBlob(
*
* @param string $container The container name.
* @param string $blob The blob name.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand Down Expand Up @@ -721,9 +720,9 @@ public function createBlobBlockAsync(
* @param string $container name of the container
* @param string $blob name of the blob
* @param resource|string|StreamInterface $content the blob block contents
* @param Models\AppendBlockOptions $options optional parameters
* @param BlobModels\AppendBlockOptions $options optional parameters
*
* @return Models\AppendBlockResult
* @return BlobModels\AppendBlockResult
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block
*/
Expand All @@ -740,7 +739,7 @@ public function appendBlock(
* @param string $container name of the container
* @param string $blob name of the blob
* @param resource|string|StreamInterface $content the blob block contents
* @param Models\AppendBlockOptions $options optional parameters
* @param BlobModels\AppendBlockOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand Down Expand Up @@ -1021,6 +1020,40 @@ public function listPageBlobRangesDiffAsync(
BlobModels\ListPageBlobRangesOptions $options = null
);

/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param BlobModels\SetBlobTierOptions $options optional parameters
*
* @return void
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTier(
$container,
$blob,
BlobModels\SetBlobTierOptions $options = null
);

/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param BlobModels\SetBlobTierOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTierAsync(
$container,
$blob,
BlobModels\SetBlobTierOptions $options = null
);

/**
* Sets system properties defined for a blob.
*
Expand Down Expand Up @@ -1356,9 +1389,9 @@ public function abortCopyAsync(
* @param int $leaseDuration the lease duration. A non-infinite
* lease can be between 15 and 60 seconds.
* Default is never to expire.
* @param Models\BlobServiceOptions $options optional parameters
* @param BlobModels\BlobServiceOptions $options optional parameters
*
* @return Models\LeaseResult
* @return BlobModels\LeaseResult
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx
*/
Expand All @@ -1380,7 +1413,7 @@ public function acquireLease(
* @param int $leaseDuration the lease duration. A non-infinite
* lease can be between 15 and 60 seconds.
* Default is never to expire.
* @param Models\BlobServiceOptions $options optional parameters
* @param BlobModels\BlobServiceOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
Expand Down
Loading

0 comments on commit 6a89f27

Please sign in to comment.