Skip to content

Support soft-delete feature in storge dataplane cmdlet #5457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public class AzureStorageBlob : AzureStorageBase
/// </summary>
public long Length { get; private set; }

/// <summary>
/// Blob IsDeleted
/// </summary>
public bool IsDeleted { get; private set; }

/// <summary>
/// Blob IsDeleted
/// </summary>
public int? RemainingDaysBeforePermanentDelete { get; private set; }

/// <summary>
/// Blob content type
/// </summary>
Expand Down Expand Up @@ -67,6 +77,8 @@ public AzureStorageBlob(CloudBlob blob)
ICloudBlob = blob;
BlobType = blob.BlobType;
Length = blob.Properties.Length;
IsDeleted = blob.IsDeleted;
RemainingDaysBeforePermanentDelete = blob.Properties.RemainingDaysBeforePermanentDelete;
ContentType = blob.Properties.ContentType;
LastModified = blob.Properties.LastModified;
SnapshotTime = blob.SnapshotTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@
<HintPath>..\..\..\packages\Microsoft.Data.Services.Client.5.8.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=8.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\WindowsAzure.Storage.8.1.1\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\WindowsAzure.Storage.9.0.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<packages>
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Storage" version="7.1.0-preview" targetFramework="net452" />
<package id="WindowsAzure.Storage" version="8.1.1" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
<package id="WindowsAzure.Storage" version="9.0.0" targetFramework="net452" />
</packages>
9 changes: 6 additions & 3 deletions src/Storage/Azure.Storage.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ CmdletsToExport = 'Get-AzureStorageTable', 'New-AzureStorageTableSASToken',
'New-AzureStorageAccountSASToken', 'Set-AzureStorageCORSRule',
'Get-AzureStorageCORSRule',
'Get-AzureStorageServiceLoggingProperty',
'Get-AzureStorageServiceMetricsProperty',
'Get-AzureStorageServiceMetricsProperty',
'Remove-AzureStorageCORSRule',
'Set-AzureStorageServiceLoggingProperty',
'Set-AzureStorageServiceMetricsProperty', 'New-AzureStorageContext',
Expand All @@ -116,14 +116,17 @@ CmdletsToExport = 'Get-AzureStorageTable', 'New-AzureStorageTableSASToken',
'Start-AzureStorageBlobCopy',
'Start-AzureStorageBlobIncrementalCopy',
'Stop-AzureStorageBlobCopy', 'Update-AzureStorageServiceProperty',
'Get-AzureStorageServiceProperty'
'Get-AzureStorageServiceProperty',
'Enable-AzureStorageDeleteRetentionPolicy',
'Disable-AzureStorageDeleteRetentionPolicy'

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = 'Get-AzureStorageContainerAcl', 'Start-CopyAzureStorageBlob',
'Stop-CopyAzureStorageBlob'
'Stop-CopyAzureStorageBlob','Enable-AzureStorageSoftDelete',
'Disable-AzureStorageSoftDelete'

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down
4 changes: 4 additions & 0 deletions src/Storage/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Additional information about change #1
-->
## Current Release
* Support Soft-Delete feature
- Enable-AzureStorageDeleteRetentionPolicy
- Disable-AzureStorageDeleteRetentionPolicy
- Get-AzureStorageBlob

## Version 4.1.1
* Fix Get Blob Container cmdlet execute fail with Accout SAS credential issue
Expand Down
13 changes: 7 additions & 6 deletions src/Storage/Commands.Storage.Test/Commands.Storage.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@
<Reference Include="Microsoft.WindowsAzure.Management">
<HintPath>..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=8.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\WindowsAzure.Storage.8.6.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\WindowsAzure.Storage.9.0.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage.DataMovement, Version=0.6.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Storage.DataMovement.0.6.5\lib\net45\Microsoft.WindowsAzure.Storage.DataMovement.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage.DataMovement, Version=0.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Storage.DataMovement.0.7.1\lib\net45\Microsoft.WindowsAzure.Storage.DataMovement.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to wait until our runtime change is in. ETA is next week, which means this will likely not make it in for this release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See, waiting for your fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fixed

<HintPath>..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -280,6 +280,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need remove this line, or build will fail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will raise a commit to remove it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it back since the app.config already check in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is merged, please help to review and merge this PR.

<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void ValidateParseServicePropertiesTest()
serviceProperties.Logging.LoggingOperations = LoggingOperations.All;
serviceProperties.Logging.RetentionDays = 5;
serviceProperties.DefaultServiceVersion = "2017-04-17";
serviceProperties.DeleteRetentionPolicy = new DeleteRetentionPolicy();
serviceProperties.DeleteRetentionPolicy.Enabled = true;
serviceProperties.DeleteRetentionPolicy.RetentionDays = 5;
PSSeriviceProperties pSSeriviceProperties = new PSSeriviceProperties(serviceProperties);
CompareServiceProperties(pSSeriviceProperties, serviceProperties);

Expand Down Expand Up @@ -111,6 +114,11 @@ static private void CompareServiceProperties(PSSeriviceProperties pSSeriviceProp
{
Assert.AreEqual(serviceProperties.DefaultServiceVersion, pSSeriviceProperties.DefaultServiceVersion);
}
if ((pSSeriviceProperties != null && pSSeriviceProperties.DeleteRetentionPolicy != null) || (serviceProperties != null && serviceProperties.DeleteRetentionPolicy != null))
{
Assert.AreEqual(serviceProperties.DeleteRetentionPolicy.Enabled, pSSeriviceProperties.DeleteRetentionPolicy.Enabled);
Assert.AreEqual(serviceProperties.DeleteRetentionPolicy.RetentionDays, pSSeriviceProperties.DeleteRetentionPolicy.RetentionDays);
}
}

/// <summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Storage/Commands.Storage.Test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /></startup></configuration>
6 changes: 3 additions & 3 deletions src/Storage/Commands.Storage.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Microsoft.Azure.Common.Dependencies" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.Resources" version="2.18.11-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Storage.DataMovement" version="0.6.5" targetFramework="net452" />
<package id="Microsoft.Azure.Storage.DataMovement" version="0.7.1" targetFramework="net452" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.6.7-preview" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
Expand All @@ -19,13 +19,13 @@
<package id="Microsoft.Rest.ClientRuntime.Azure.Authentication" version="2.2.9-preview" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.0" targetFramework="net45" />
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net452" />
<package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net45" />
<package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net45" />
<package id="System.Linq.Queryable" version="4.0.0" targetFramework="net45" />
<package id="System.Net.Requests" version="4.0.11" targetFramework="net45" />
<package id="System.Spatial" version="5.8.2" targetFramework="net45" />
<package id="WindowsAzure.Storage" version="8.6.0" targetFramework="net452" />
<package id="WindowsAzure.Storage" version="9.0.0" targetFramework="net452" />
<package id="xunit" version="2.1.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
Expand Down
2 changes: 2 additions & 0 deletions src/Storage/Commands.Storage/AzureStorageStartup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $script:aliases = @{
"Get-AzureStorageContainerAcl" = "Get-AzureStorageContainer";
"Start-CopyAzureStorageBlob" = "Start-AzureStorageBlobCopy";
"Stop-CopyAzureStorageBlob" = "Stop-AzureStorageBlobCopy";
"Enable-AzureStorageDeleteRetentionPolicy" = "Enable-AzureStorageSoftDelete";
"Disable-AzureStorageDeleteRetentionPolicy" = "Disable-AzureStorageSoftDelete";
}

$aliases.GetEnumerator() | Select @{Name='Name'; Expression={$_.Key}}, @{Name='Value'; Expression={$_.Value}} | New-Alias -Description "AzureAlias"
20 changes: 14 additions & 6 deletions src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public string Container
}

private string containerName = String.Empty;

[Parameter(Mandatory = false, HelpMessage = "Include deleted blobs, by default get blob won't include deleted blobs")]
[ValidateNotNullOrEmpty]
public SwitchParameter IncludeDeleted { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The max count of the blobs that can return.")]
public int? MaxCount
Expand Down Expand Up @@ -161,15 +165,15 @@ internal async Task<CloudBlobContainer> GetCloudBlobContainerByName(IStorageBlob
/// <param name="containerName">container name</param>
/// <param name="blobName">blob name pattern</param>
/// <returns>An enumerable collection of IListBlobItem</returns>
internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName)
internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName, bool includeDeleted = false)
{
CloudBlobContainer container = null;
BlobRequestOptions requestOptions = RequestOptions;
AccessCondition accessCondition = null;

string prefix = string.Empty;

if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName))
if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName) || includeDeleted)
{
container = await GetCloudBlobContainerByName(localChannel, containerName).ConfigureAwait(false);
prefix = NameUtil.GetNonWildcardPrefix(blobName);
Expand All @@ -182,7 +186,7 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
}

Func<CloudBlob, bool> blobFilter = (blob) => wildcard == null || wildcard.IsMatch(blob.Name);
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter).ConfigureAwait(false);
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter, includeDeleted).ConfigureAwait(false);
}
else
{
Expand Down Expand Up @@ -212,13 +216,17 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
/// <param name="containerName">container name</param>
/// <param name="prefix">blob preifx</param>
/// <returns>An enumerable collection of IListBlobItem</returns>
internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localChannel, string containerName, string prefix, Func<CloudBlob, bool> blobFilter = null)
internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localChannel, string containerName, string prefix, Func<CloudBlob, bool> blobFilter = null, bool includeDeleted = false)
{
CloudBlobContainer container = await GetCloudBlobContainerByName(localChannel, containerName).ConfigureAwait(false);

BlobRequestOptions requestOptions = RequestOptions;
bool useFlatBlobListing = true;
BlobListingDetails details = BlobListingDetails.Snapshots | BlobListingDetails.Metadata | BlobListingDetails.Copy;
if (includeDeleted)
{
details = details | BlobListingDetails.Deleted;
}

int listCount = InternalMaxCount;
int MaxListCount = 5000;
Expand Down Expand Up @@ -272,13 +280,13 @@ public override void ExecuteCmdlet()
{
string localContainerName = containerName;
string localPrefix = blobPrefix;
taskGenerator = (taskId) => ListBlobsByPrefix(taskId, localChannel, localContainerName, localPrefix);
taskGenerator = (taskId) => ListBlobsByPrefix(taskId, localChannel, localContainerName, localPrefix, includeDeleted: IncludeDeleted.IsPresent);
}
else
{
string localContainerName = containerName;
string localBlobName = blobName;
taskGenerator = (taskId) => ListBlobsByName(taskId, localChannel, localContainerName, localBlobName);
taskGenerator = (taskId) => ListBlobsByName(taskId, localChannel, localContainerName, localBlobName, includeDeleted: IncludeDeleted.IsPresent);
}

RunTask(taskGenerator);
Expand Down
14 changes: 10 additions & 4 deletions src/Storage/Commands.Storage/Commands.Storage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=8.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\WindowsAzure.Storage.8.6.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\WindowsAzure.Storage.9.0.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage.DataMovement, Version=0.6.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Storage.DataMovement.0.6.5\lib\net45\Microsoft.WindowsAzure.Storage.DataMovement.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage.DataMovement, Version=0.7.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Azure.Storage.DataMovement.0.7.1\lib\net45\Microsoft.WindowsAzure.Storage.DataMovement.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See, waiting for your fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fixed

<HintPath>..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -121,6 +125,7 @@
<Compile Include="Blob\Cmdlet\StartAzureStorageBlobCopy.cs" />
<Compile Include="Blob\Cmdlet\StopAzureStorageBlobCopy.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageServiceProperties.cs" />
<Compile Include="Common\Cmdlet\DisableAzureStorageDeleteRetentionPolicy.cs" />
<Compile Include="Common\Cmdlet\NewAzureStorageAccountSasToken.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageCORSRule.cs" />
Expand All @@ -129,6 +134,7 @@
<Compile Include="Common\Cmdlet\RemoveAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceProperties.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceLogging.cs" />
<Compile Include="Common\Cmdlet\EnableAzureStorageDeleteRetentionPolicy.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageServiceMetrics.cs" />
<Compile Include="Common\ConfirmTaskCompletionSource.cs" />
<Compile Include="Common\DataManagementWrapper.cs" />
Expand Down
Loading