Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Soft-Delete Updated Server Changes + CR
Browse files Browse the repository at this point in the history
  • Loading branch information
erezvani1529 committed Dec 11, 2017
1 parent 2012e30 commit d5c2071
Show file tree
Hide file tree
Showing 24 changed files with 1,049 additions and 329 deletions.
114 changes: 7 additions & 107 deletions Lib/ClassLibraryCommon/Blob/CloudBlob.cs

Large diffs are not rendered by default.

47 changes: 0 additions & 47 deletions Lib/ClassLibraryCommon/Blob/Protocol/BlobHttpWebRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,6 @@ private static void AddSnapshot(UriQueryBuilder builder, DateTimeOffset? snapsho
}
}

/// <summary>
/// Adds the snapshot.
/// </summary>
/// <param name="builder">An object of type <see cref="UriQueryBuilder"/> that contains additional parameters to add to the URI query string.</param>
/// <param name="isPermenantDelete">A boolean value indicating whether to set the <i>deletetype=permanent</i> HTTP header.</param>
private static void AddDeleteType(UriQueryBuilder builder, bool isPermenantDelete)
{
if (isPermenantDelete)
{
builder.Add(Constants.QueryConstants.DeleteType, "permanent");
}
}

/// <summary>
/// Constructs a web request to commit a block to an append blob.
/// </summary>
Expand Down Expand Up @@ -648,21 +635,6 @@ public static void AddMetadata(HttpWebRequest request, string name, string value
HttpWebRequestFactory.AddMetadata(request, name, value);
}

/// <summary>
/// Constructs a web request to delete a blob.
/// </summary>
/// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the blob.</param>
/// <param name="timeout">An integer specifying the server timeout interval.</param>
/// <param name="snapshot">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the blob is a snapshot.</param>
/// <param name="deleteSnapshotsOption">A <see cref="DeleteSnapshotsOption"/> object indicating whether to delete only blobs, only snapshots, or both.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
/// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns>
public static HttpWebRequest Delete(Uri uri, int? timeout, DateTimeOffset? snapshot, DeleteSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, OperationContext operationContext)
{
return BlobHttpWebRequestFactory.Delete(uri, timeout, snapshot, deleteSnapshotsOption, accessCondition, true /* useVersionHeader */, operationContext);
}

/// <summary>
/// Constructs a web request to delete a blob.
/// </summary>
Expand All @@ -675,23 +647,6 @@ public static HttpWebRequest Delete(Uri uri, int? timeout, DateTimeOffset? snaps
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
/// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns>
public static HttpWebRequest Delete(Uri uri, int? timeout, DateTimeOffset? snapshot, DeleteSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, bool useVersionHeader, OperationContext operationContext)
{
return BlobHttpWebRequestFactory.Delete(uri, timeout, snapshot, false /* isPermenantDelete */, deleteSnapshotsOption, accessCondition, useVersionHeader, operationContext);
}

/// <summary>
/// Constructs a web request to delete a blob.
/// </summary>
/// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the blob.</param>
/// <param name="timeout">An integer specifying the server timeout interval.</param>
/// <param name="snapshot">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the blob is a snapshot.</param>
/// <param name="isPermenantDelete">A boolean value indicating whether to set the <i>deletetype=permanent</i> HTTP header.</param>
/// <param name="deleteSnapshotsOption">A <see cref="DeleteSnapshotsOption"/> object indicating whether to delete only blobs, only snapshots, or both.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed.</param>
/// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
/// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns>
public static HttpWebRequest Delete(Uri uri, int? timeout, DateTimeOffset? snapshot, bool isPermenantDelete, DeleteSnapshotsOption deleteSnapshotsOption, AccessCondition accessCondition, bool useVersionHeader, OperationContext operationContext)
{
if ((snapshot != null) && (deleteSnapshotsOption != DeleteSnapshotsOption.None))
{
Expand All @@ -700,8 +655,6 @@ public static HttpWebRequest Delete(Uri uri, int? timeout, DateTimeOffset? snaps

UriQueryBuilder builder = new UriQueryBuilder();
BlobHttpWebRequestFactory.AddSnapshot(builder, snapshot);
BlobHttpWebRequestFactory.AddDeleteType(builder, isPermenantDelete);


HttpWebRequest request = HttpWebRequestFactory.Delete(uri, builder, timeout, useVersionHeader, operationContext);

Expand Down
2 changes: 1 addition & 1 deletion Lib/Common/Blob/CloudBlob.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public bool IsSnapshot
/// <summary>
/// Gets a value indicating whether or not this blob has been deleted.
/// </summary>
/// <value>A bool representing if the has been deleted.</value>
/// <value>A bool representing if the blob has been deleted.</value>
public bool IsDeleted
{
get
Expand Down
2 changes: 1 addition & 1 deletion Lib/Common/Blob/Protocol/BlobHttpResponseParsers.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static bool GetIncrementalCopyStatus(string incrementalCopyHeader)
/// <summary>
/// Determines if a blob has been deleted.
/// </summary>
/// <param name="deletedHeader">String giving the deletion copy status of the blob</param>
/// <param name="deletedHeader">String giving the deletion status of the blob</param>
/// <returns><c>true</c> if blob has been deleted or <c>false</c> if not.</returns>
public static bool GetDeletionStatus(string deletedHeader)
{
Expand Down
3 changes: 1 addition & 2 deletions Lib/Common/Core/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ internal class SR
public const string InvalidLoggingLevel = "Invalid logging operations specified.";
public const string InvalidMetricsLevel = "Invalid metrics level specified.";
public const string InvalidBlockSize = "Append block data should not exceed the maximum blob size condition value.";
public const string InvalidDeleteRetentionDaysValue = "The delete retention policy is enabled but the RetentionDays property is not specified or has an invalid value. The specified value must be between 1 and 365.";
public const string InvalidRetainedVersionsPerBlobValue = "The delete retention policy is enabled but the RetainedVersionsPerBlob value is not specified or has an invalid value. The specified value must be between 1 and 10.";
public const string InvalidDeleteRetentionDaysValue = "The delete retention policy is enabled but the RetentionDays property is not specified or has an invalid value. RetentionDays must be greater than 0 and less than or equal to 365 days.";
public const string InvalidPageSize = "Page data must be a multiple of 512 bytes.";
public const string InvalidProtocolsInSAS = "Invalid value {0} for the SharedAccessProtocol parameter when creating a SharedAccessSignature. Use 'null' if you do not wish to include a SharedAccessProtocol.";
public const string InvalidResourceName = "Invalid {0} name. Check MSDN for more information about valid {0} naming.";
Expand Down
10 changes: 5 additions & 5 deletions Lib/Common/Shared/Protocol/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ static class Constants
/// </summary>
public const int MinLargeBlockSize = (int)(4 * Constants.MB) + 1;

/// <summary>
/// The maximum number of retained versions per blob.
/// </summary>
public const int MaxRetainedVersionsPerBlob = 10;

/// <summary>
/// Constant for the max value of MaximumExecutionTime.
/// </summary>
Expand All @@ -112,6 +107,11 @@ static class Constants
/// </summary>
public static readonly TimeSpan MaximumAllowedTimeout = TimeSpan.FromSeconds(int.MaxValue);

/// <summary>
/// Maximum allowed value for Delete Retention Days.
/// </summary>
internal static readonly int MaximumAllowedRetentionDays = 365;

/// <summary>
/// Default size of buffer for unknown sized requests.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Microsoft.WindowsAzure.Storage.Shared.Protocol
/// <summary>
/// Class representing the service properties pertaining to DeleteRetentionPolicy
/// </summary>
public sealed class DeleteRetentionPolicyProperties
public sealed class DeleteRetentionPolicy
{
/// <summary>
/// Gets or sets the Enabled flag of the DeleteRetentionPolicy.
Expand All @@ -36,17 +36,7 @@ public bool Enabled
/// Gets or Sets the number of days on the DeleteRetentionPolicy.
/// </summary>
/// <value>Indicates the number of days that the deleted blob should be retained. The minimum specified value can be 1 and the maximum value can be 365. </value>
public int? Days
{
get;
set;
}

/// <summary>
/// Gets or Sets the number of
/// </summary>
/// <value>Indicates the number of deleted versions of each blob to be retained. The minimum specified value can be 1 and the maximum value can be 10.</value>
public int? RetainedVersionsPerBlob
public int? RetentionDays
{
get;
set;
Expand Down
61 changes: 23 additions & 38 deletions Lib/Common/Shared/Protocol/ServiceProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ public sealed class ServiceProperties
/// </summary>
internal const string AllowedHeadersName = "AllowedHeaders";

/// <summary>
/// The name of the RetainedVersionsPerBlob XML element.
/// </summary>
internal const string RetainedVersionsPerBlob = "RetainedVersionsPerBlob";

/// <summary>
/// Initializes a new instance of the ServiceProperties class.
/// </summary>
Expand All @@ -153,13 +148,13 @@ public ServiceProperties()
/// <summary>
/// Initializes a new instance of the ServiceProperties class.
/// </summary>
public ServiceProperties(LoggingProperties logging = null, MetricsProperties hourMetrics = null, MetricsProperties minuteMetrics = null, CorsProperties cors = null, DeleteRetentionPolicyProperties deleteRetentionProperties = null)
public ServiceProperties(LoggingProperties logging = null, MetricsProperties hourMetrics = null, MetricsProperties minuteMetrics = null, CorsProperties cors = null, DeleteRetentionPolicy deleteRetentionPolicy = null)
{
this.Logging = logging;
this.HourMetrics = hourMetrics;
this.MinuteMetrics = minuteMetrics;
this.Cors = cors;
this.DeleteRetentionProperties = deleteRetentionProperties;
this.DeleteRetentionPolicy = deleteRetentionPolicy;
}

/// <summary>
Expand Down Expand Up @@ -213,10 +208,10 @@ public string DefaultServiceVersion
}

/// <summary>
/// Gets or sets the delete retention policy properties.
/// Gets or sets the delete retention policy.
/// </summary>
/// <value>The delete retention policy properties.</value>
public DeleteRetentionPolicyProperties DeleteRetentionProperties
/// <value>The delete retention policy.</value>
public DeleteRetentionPolicy DeleteRetentionPolicy
{
get;
set;
Expand All @@ -236,7 +231,7 @@ internal static ServiceProperties FromServiceXml(XDocument servicePropertiesDocu
HourMetrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(HourMetricsName)),
MinuteMetrics = ReadMetricsPropertiesFromXml(servicePropertiesElement.Element(MinuteMetricsName)),
Cors = ReadCorsPropertiesFromXml(servicePropertiesElement.Element(CorsName)),
DeleteRetentionProperties = ReadDeleteRetentionPolicyFromXml(servicePropertiesElement.Element(DeleteRetentionPolicyName))
DeleteRetentionPolicy = ReadDeleteRetentionPolicyFromXml(servicePropertiesElement.Element(DeleteRetentionPolicyName))
};

XElement defaultServiceVersionXml = servicePropertiesElement.Element(DefaultServiceVersionName);
Expand All @@ -255,7 +250,7 @@ internal static ServiceProperties FromServiceXml(XDocument servicePropertiesDocu
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "SetServiceProperties", Justification = "API name is properly spelled")]
internal XDocument ToServiceXml()
{
if (this.Logging == null && this.HourMetrics == null && this.MinuteMetrics == null && this.Cors == null && this.DeleteRetentionProperties == null && this.DefaultServiceVersion == null)
if (this.Logging == null && this.HourMetrics == null && this.MinuteMetrics == null && this.Cors == null && this.DeleteRetentionPolicy == null && this.DefaultServiceVersion == null)
{
throw new InvalidOperationException(SR.SetServicePropertiesRequiresNonNullSettings);
}
Expand Down Expand Up @@ -286,10 +281,9 @@ internal XDocument ToServiceXml()
{
storageServiceElement.Add(new XElement(DefaultServiceVersionName, this.DefaultServiceVersion));
}

if (this.DeleteRetentionProperties != null)
if (this.DeleteRetentionPolicy != null)
{
storageServiceElement.Add(GenerateDeleteRetentionPolicyXml(this.DeleteRetentionProperties));
storageServiceElement.Add(GenerateDeleteRetentionPolicyXml(this.DeleteRetentionPolicy));
}

return new XDocument(storageServiceElement);
Expand Down Expand Up @@ -410,32 +404,25 @@ private static XElement GenerateCorsXml(CorsProperties cors)
/// <summary>
/// Generates XML representing the given delete retention policy.
/// </summary>
/// <param name="deleteRetentionProperties">The DeleteRetentionPolicy properties.</param>
/// <param name="deleteRetentionPolicy">The DeleteRetentionPolicy properties.</param>
/// <returns>An XML logging element.</returns>
private static XElement GenerateDeleteRetentionPolicyXml(DeleteRetentionPolicyProperties deleteRetentionProperties)
private static XElement GenerateDeleteRetentionPolicyXml(DeleteRetentionPolicy deleteRetentionPolicy)
{
CommonUtility.AssertNotNull("deleteRetentionProperties", deleteRetentionProperties);
CommonUtility.AssertNotNull("deleteRetentionPolicy", deleteRetentionPolicy);

bool enabled = deleteRetentionProperties.Enabled;
bool enabled = deleteRetentionPolicy.Enabled;
var xml = new XElement(DeleteRetentionPolicyName, new XElement(EnabledName, enabled));

if (!enabled) return xml;

if (!deleteRetentionProperties.Days.HasValue || deleteRetentionProperties.Days.Value < 1)
{
throw new InvalidOperationException(SR.InvalidDeleteRetentionDaysValue);
}

xml.Add(new XElement(DaysName, (int)deleteRetentionProperties.Days));

if (!deleteRetentionProperties.RetainedVersionsPerBlob.HasValue ||
deleteRetentionProperties.RetainedVersionsPerBlob.Value < 1 ||
deleteRetentionProperties.RetainedVersionsPerBlob.Value > Constants.MaxRetainedVersionsPerBlob)
if (!deleteRetentionPolicy.RetentionDays.HasValue || deleteRetentionPolicy.RetentionDays.Value < 1
|| deleteRetentionPolicy.RetentionDays > Constants.MaximumAllowedRetentionDays)
{
throw new InvalidOperationException(SR.InvalidRetainedVersionsPerBlobValue);
throw new ArgumentException(SR.InvalidDeleteRetentionDaysValue);
}

xml.Add(new XElement(RetainedVersionsPerBlob , (int)deleteRetentionProperties.RetainedVersionsPerBlob));
xml.Add(new XElement(DaysName, (int)deleteRetentionPolicy.RetentionDays));

return xml;
}
Expand Down Expand Up @@ -552,30 +539,28 @@ internal static CorsProperties ReadCorsPropertiesFromXml(XElement element)
}

/// <summary>
/// Constructs a <c>DeleteRetentionPolicyProperties</c> object from an XML element.
/// Constructs a <c>DeleteRetentionPolicy</c> object from an XML element.
/// </summary>
/// <param name="element">the XML element</param>
/// <returns>A <c>DeleteRetentionPolicyProperties</c> object containing the properties in the element</returns>
internal static DeleteRetentionPolicyProperties ReadDeleteRetentionPolicyFromXml(XElement element)
/// <returns>A <c>DeleteRetentionPolicy</c> object containing the properties in the element</returns>
internal static DeleteRetentionPolicy ReadDeleteRetentionPolicyFromXml(XElement element)
{
if (element == null)
{
return null;
}

var deleteRetentionPolicy = new DeleteRetentionPolicyProperties()
var deleteRetentionPolicy = new DeleteRetentionPolicy()
{
Enabled = false,
Days = null,
RetainedVersionsPerBlob = null
RetentionDays = null
};

deleteRetentionPolicy.Enabled = bool.Parse(element.Element(EnabledName).Value);

if (deleteRetentionPolicy.Enabled)
{
deleteRetentionPolicy.Days = int.Parse(element.Element(DaysName).Value, CultureInfo.InvariantCulture);
deleteRetentionPolicy.RetainedVersionsPerBlob = int.Parse(element.Element(RetainedVersionsPerBlob).Value, CultureInfo.InvariantCulture);
deleteRetentionPolicy.RetentionDays = int.Parse(element.Element(DaysName).Value, CultureInfo.InvariantCulture);
}

return deleteRetentionPolicy;
Expand Down
Loading

0 comments on commit d5c2071

Please sign in to comment.