Skip to content

Commit

Permalink
source code copied from azure-storage-php for v1.5.0-blob release
Browse files Browse the repository at this point in the history
  • Loading branch information
vinjiang committed Jan 2, 2020
1 parent 8310c2e commit 6a333cd
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 9 deletions.
11 changes: 10 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
2020.01 - version 1.5.0

* Added support to include deleted in blob list.
* Added support to undelete a blob.
* Fixed the issue in SAS token where special characters were not correctly encoded.
* Samples no longer uses ‘BlobRestProxy’ directly, instead, ‘ServicesBuilder’ is used.

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.
* `ListContainer` now can have ETag more robustly fetched from response header.
Expand Down Expand Up @@ -31,4 +40,4 @@
* 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.
* Deprecated PHP 5.5 support.
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-blob",
"version": "1.4.0",
"version": "1.5.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 Down
83 changes: 82 additions & 1 deletion src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use MicrosoftAzure\Storage\Blob\Models\CreateBlobSnapshotResult;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\CreatePageBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\UndeleteBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataResult;
Expand Down Expand Up @@ -1544,13 +1545,15 @@ public function listBlobsAsync(
$includeSnapshots = $options->getIncludeSnapshots();
$includeUncommittedBlobs = $options->getIncludeUncommittedBlobs();
$includecopy = $options->getIncludeCopy();
$includeDeleted = $options->getIncludeDeleted();

$includeValue = static::groupQueryValues(
array(
$includeMetadata ? 'metadata' : null,
$includeSnapshots ? 'snapshots' : null,
$includeUncommittedBlobs ? 'uncommittedblobs' : null,
$includecopy ? 'copy' : null
$includecopy ? 'copy' : null,
$includeDeleted ? 'deleted' : null,
)
);

Expand Down Expand Up @@ -3788,6 +3791,84 @@ public function getBlobAsync(
);
});
}

/**
* Undeletes a blob.
*
* @param string $container name of the container
* @param string $blob name of the blob
* @param Models\UndeleteBlobOptions $options optional parameters
*
* @return void
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/undelete-blob
*/
public function undeleteBlob(
$container,
$blob,
Models\UndeleteBlobOptions $options = null
) {
$this->undeleteBlobAsync($container, $blob, $options)->wait();
}

/**
* Undeletes a blob.
*
* @param string $container name of the container
* @param string $blob name of the blob
* @param Models\UndeleteBlobOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/undelete-blob
*/
public function undeleteBlobAsync(
$container,
$blob,
Models\UndeleteBlobOptions $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 UndeleteBlobOptions();
}

$leaseId = $options->getLeaseId();

$headers = $this->addOptionalAccessConditionHeader(
$headers,
$options->getAccessConditions()
);

$this->addOptionalHeader(
$headers,
Resources::X_MS_LEASE_ID,
$leaseId
);

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

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

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

/**
* Deletes a blob or blob snapshot.
Expand Down
2 changes: 1 addition & 1 deletion src/Blob/BlobSharedAccessSignatureHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function generateBlobServiceSharedAccessSignatureToken(
$parameters[] = $contentType;

// implode the parameters into a string
$stringToSign = utf8_encode(implode("\n", $parameters));
$stringToSign = implode("\n", $parameters);
// decode the account key from base64
$decodedAccountKey = base64_decode($this->accountKey);
// create the signature with hmac sha256
Expand Down
2 changes: 1 addition & 1 deletion src/Blob/Internal/BlobResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BlobResources extends Resources
{
// @codingStandardsIgnoreStart

const BLOB_SDK_VERSION = '1.4.0';
const BLOB_SDK_VERSION = '1.5.0';
const STORAGE_API_LATEST_VERSION = '2017-11-09';

// Error messages
Expand Down
96 changes: 92 additions & 4 deletions src/Blob/Models/BlobProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class BlobProperties
{
private $lastModified;
private $creationTime;
private $etag;
private $contentType;
private $contentLength;
Expand All @@ -65,6 +66,8 @@ class BlobProperties
private $accessTierInferred;
private $accessTierChangeTime;
private $archiveStatus;
private $deletedTime;
private $remainingRetentionDays;

/**
* Creates BlobProperties object from $parsed response in array representation of XML elements
Expand Down Expand Up @@ -104,16 +107,33 @@ public static function createFromXml(array $parsed)
)
);

$date = Utilities::tryGetValue($clean, 'accesstierchangetime');
if (!is_null($date)) {
$date = Utilities::rfc1123ToDateTime($date);
$result->setAccessTierChangeTime($date);
$accesstierchangetime = Utilities::tryGetValue($clean, 'accesstierchangetime');
if (!is_null($accesstierchangetime)) {
$accesstierchangetime = Utilities::rfc1123ToDateTime($accesstierchangetime);
$result->setAccessTierChangeTime($accesstierchangetime);
}

$result->setArchiveStatus(
Utilities::tryGetValue($clean, 'archivestatus')
);

$deletedtime = Utilities::tryGetValue($clean, 'deletedtime');
if (!is_null($deletedtime)) {
$deletedtime = Utilities::rfc1123ToDateTime($deletedtime);
$result->setDeletedTime($deletedtime);
}

$remainingretentiondays = Utilities::tryGetValue($clean, 'remainingretentiondays');
if (!is_null($remainingretentiondays)) {
$result->setRemainingRetentionDays((int) $remainingretentiondays);
}

$creationtime = Utilities::tryGetValue($clean, 'creation-time');
if (!is_null($creationtime)) {
$creationtime = Utilities::rfc1123ToDateTime($creationtime);
$result->setCreationTime($creationtime);
}

return $result;
}

Expand Down Expand Up @@ -217,6 +237,29 @@ public function setLastModified(\DateTime $lastModified)
$this->lastModified = $lastModified;
}

/**
* Gets blob creationTime.
*
* @return \DateTime
*/
public function getCreationTime()
{
return $this->creationTime;
}

/**
* Sets blob creationTime.
*
* @param \DateTime $creationTime value.
*
* @return void
*/
public function setCreationTime(\DateTime $creationTime)
{
Validate::isDate($creationTime);
$this->creationTime = $creationTime;
}

/**
* Gets blob etag.
*
Expand Down Expand Up @@ -371,7 +414,52 @@ public function setArchiveStatus($archiveStatus)
{
$this->archiveStatus = $archiveStatus;
}

/**
* Gets blob deleted time.
*
* @return string
*/
public function getDeletedTime()
{
return $this->deletedTime;
}

/**
* Sets blob deleted time.
*
* @param \DateTime $deletedTime value.
*
* @return void
*/
public function setDeletedTime(\DateTime $deletedTime)
{
$this->deletedTime = $deletedTime;
}

/**
* Gets blob remaining retention days.
*
* @return integer
*/
public function getRemainingRetentionDays()
{
return $this->remainingRetentionDays;
}

/**
* Sets blob remaining retention days.
*
* @param integer $remainingRetentionDays value.
*
* @return void
*/
public function setRemainingRetentionDays($remainingRetentionDays)
{
$this->remainingRetentionDays = $remainingRetentionDays;
}


/**
* Gets blob access inferred.
*
Expand Down
24 changes: 24 additions & 0 deletions src/Blob/Models/ListBlobsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ListBlobsOptions extends BlobServiceOptions
private $_includeSnapshots;
private $_includeUncommittedBlobs;
private $_includeCopy;
private $_includeDeleted;

/**
* Gets prefix.
Expand Down Expand Up @@ -209,4 +210,27 @@ public function setIncludeCopy($includeCopy)
Validate::isBoolean($includeCopy);
$this->_includeCopy = $includeCopy;
}

/**
* Indicates if deleted is included or not.
*
* @return boolean
*/
public function getIncludeDeleted()
{
return $this->_includeDeleted;
}

/**
* Sets the include deleted flag.
*
* @param bool $includeDeleted value.
*
* @return void
*/
public function setIncludeDeleted($includeDeleted)
{
Validate::isBoolean($includeDeleted);
$this->_includeDeleted = $includeDeleted;
}
}
39 changes: 39 additions & 0 deletions src/Blob/Models/UndeleteBlobOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* LICENSE: The MIT License (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://github.com/azure/azure-storage-php/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <[email protected]>
* @copyright 2016 Microsoft Corporation
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/

namespace MicrosoftAzure\Storage\Blob\Models;

/**
* Optional parameters for deleteBlob wrapper
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <[email protected]>
* @copyright 2016 Microsoft Corporation
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
class UndeleteBlobOptions extends BlobServiceOptions
{
}

0 comments on commit 6a333cd

Please sign in to comment.