From 94233e76ffba1fd9e31992cc63e36b269e3fac82 Mon Sep 17 00:00:00 2001 From: Levi B Date: Tue, 17 Mar 2015 10:45:21 -0700 Subject: [PATCH] Remove experimental .Azure project --- DataProtection.sln | 11 +- .../BlobStorageXmlRepository.cs | 143 ------------------ .../BlobStorageXmlRepositoryOptions.cs | 19 --- .../CryptoUtil.cs | 35 ----- ...icrosoft.AspNet.DataProtection.Azure.xproj | 17 --- .../project.json | 16 -- 6 files changed, 1 insertion(+), 240 deletions(-) delete mode 100644 src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepository.cs delete mode 100644 src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepositoryOptions.cs delete mode 100644 src/Microsoft.AspNet.DataProtection.Azure/CryptoUtil.cs delete mode 100644 src/Microsoft.AspNet.DataProtection.Azure/Microsoft.AspNet.DataProtection.Azure.xproj delete mode 100644 src/Microsoft.AspNet.DataProtection.Azure/project.json diff --git a/DataProtection.sln b/DataProtection.sln index a0e5ba9f50..c0e088b8b7 100644 --- a/DataProtection.sln +++ b/DataProtection.sln @@ -1,14 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22609.0 +VisualStudioVersion = 14.0.22710.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5FCB2DA3-5395-47F5-BCEE-E0EA319448EA}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.DataProtection", "src\Microsoft.AspNet.DataProtection\Microsoft.AspNet.DataProtection.xproj", "{1E570CD4-6F12-44F4-961E-005EE2002BC2}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.DataProtection.Azure", "src\Microsoft.AspNet.DataProtection.Azure\Microsoft.AspNet.DataProtection.Azure.xproj", "{DF3671D7-A9B1-45F1-A195-0AD596001735}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{60336AB3-948D-4D15-A5FB-F32A2B91E814}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.DataProtection.Test", "test\Microsoft.AspNet.DataProtection.Test\Microsoft.AspNet.DataProtection.Test.xproj", "{7A637185-2BA1-437D-9D4C-7CC4F94CF7BF}" @@ -45,12 +43,6 @@ Global {1E570CD4-6F12-44F4-961E-005EE2002BC2}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E570CD4-6F12-44F4-961E-005EE2002BC2}.Release|Any CPU.Build.0 = Release|Any CPU {1E570CD4-6F12-44F4-961E-005EE2002BC2}.Release|x86.ActiveCfg = Release|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Debug|x86.ActiveCfg = Debug|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Release|Any CPU.Build.0 = Release|Any CPU - {DF3671D7-A9B1-45F1-A195-0AD596001735}.Release|x86.ActiveCfg = Release|Any CPU {7A637185-2BA1-437D-9D4C-7CC4F94CF7BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7A637185-2BA1-437D-9D4C-7CC4F94CF7BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A637185-2BA1-437D-9D4C-7CC4F94CF7BF}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -135,7 +127,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {1E570CD4-6F12-44F4-961E-005EE2002BC2} = {5FCB2DA3-5395-47F5-BCEE-E0EA319448EA} - {DF3671D7-A9B1-45F1-A195-0AD596001735} = {5FCB2DA3-5395-47F5-BCEE-E0EA319448EA} {7A637185-2BA1-437D-9D4C-7CC4F94CF7BF} = {60336AB3-948D-4D15-A5FB-F32A2B91E814} {E2779976-A28C-4365-A4BB-4AD854FAF23E} = {5FCB2DA3-5395-47F5-BCEE-E0EA319448EA} {421F0383-34B1-402D-807B-A94542513ABA} = {5FCB2DA3-5395-47F5-BCEE-E0EA319448EA} diff --git a/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepository.cs b/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepository.cs deleted file mode 100644 index 777a9654ea..0000000000 --- a/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepository.cs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Runtime.ExceptionServices; -using System.Xml.Linq; -using Microsoft.AspNet.DataProtection.Repositories; -using Microsoft.Framework.Internal; -using Microsoft.Framework.OptionsModel; -using Microsoft.WindowsAzure.Storage; -using Microsoft.WindowsAzure.Storage.Blob; - -namespace Microsoft.AspNet.DataProtection.Azure -{ - /// - /// An XML repository backed by Azure blob storage. - /// - public class BlobStorageXmlRepository : IXmlRepository - { - private const int MAX_NUM_UPDATE_ATTEMPTS = 10; - - internal static readonly XNamespace XmlNamespace = XNamespace.Get("http://www.asp.net/dataProtection/2014/azure"); - internal static readonly XName KeyRingElementName = XmlNamespace.GetName("keyRing"); - - public BlobStorageXmlRepository([NotNull] IOptions optionsAccessor) - { - Directory = optionsAccessor.Options.Directory; - CryptoUtil.Assert(Directory != null, "Directory != null"); - } - - protected CloudBlobDirectory Directory - { - get; - private set; - } - - // IXmlRepository objects are supposed to be thread-safe, but CloudBlockBlob - // instances do not meet this criterion. We'll create them on-demand so that each - // thread can have its own instance that doesn't impact others. - private CloudBlockBlob GetKeyRingBlockBlobReference() - { - return Directory.GetBlockBlobReference("keyring.xml"); - } - - public virtual IReadOnlyCollection GetAllElements() - { - var blobRef = GetKeyRingBlockBlobReference(); - XDocument document = ReadDocumentFromStorage(blobRef); - return (IReadOnlyCollection)document?.Root.Elements().ToList().AsReadOnly() ?? new XElement[0]; - } - - private XDocument ReadDocumentFromStorage(CloudBlockBlob blobRef) - { - // Try downloading from Azure storage - using (var memoryStream = new MemoryStream()) - { - try - { - blobRef.DownloadToStream(memoryStream); - } - catch (StorageException ex) when (ex.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) - { - // 404s are not a fatal error - empty keyring - return null; - } - - // Rewind the memory stream and read it into an XDocument - memoryStream.Position = 0; - XDocument document = XDocument.Load(memoryStream); - - // Format checks - CryptoUtil.Assert(document.Root.Name == KeyRingElementName, "TODO: Unknown element."); - CryptoUtil.Assert((int)document.Root.Attribute("version") == 1, "TODO: Unknown version."); - return document; - } - } - - public virtual void StoreElement([NotNull] XElement element, string friendlyName) - { - ExceptionDispatchInfo lastException = null; - - // To perform a transactional update of keyring.xml, we first need to get - // the original contents of the blob. - var blobRef = GetKeyRingBlockBlobReference(); - - for (int i = 0; i < MAX_NUM_UPDATE_ATTEMPTS; i++) - { - AccessCondition updateAccessCondition; - XDocument document = ReadDocumentFromStorage(blobRef); - - // Inject the new element into the existing root. - if (document != null) - { - document.Root.Add(element); - - // only update if the contents haven't changed (prevents overwrite) - updateAccessCondition = AccessCondition.GenerateIfMatchCondition(blobRef.Properties.ETag); - } - else - { - document = new XDocument( - new XElement(KeyRingElementName, - new XAttribute("version", 1), - element)); - - // only update if the file doesn't exist (prevents overwrite) - updateAccessCondition = AccessCondition.GenerateIfNoneMatchCondition("*"); - } - - // Write the updated document back out - MemoryStream memoryStream = new MemoryStream(); - document.Save(memoryStream); - try - { - blobRef.UploadFromByteArray(memoryStream.GetBuffer(), 0, checked((int)memoryStream.Length), accessCondition: updateAccessCondition); - return; // success! - } - catch (StorageException ex) - { - switch ((HttpStatusCode)ex.RequestInformation.HttpStatusCode) - { - // If we couldn't update the blob due to a conflict on the server, try again. - case HttpStatusCode.Conflict: - case HttpStatusCode.PreconditionFailed: - lastException = ExceptionDispatchInfo.Capture(ex); - continue; - - default: - throw; - } - } - } - - // If we got this far, too many conflicts occurred while trying to update the blob. - // Just bail. - lastException.Throw(); - } - } -} diff --git a/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepositoryOptions.cs b/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepositoryOptions.cs deleted file mode 100644 index cd3d44a57e..0000000000 --- a/src/Microsoft.AspNet.DataProtection.Azure/BlobStorageXmlRepositoryOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.WindowsAzure.Storage.Blob; - -namespace Microsoft.AspNet.DataProtection.Azure -{ - /// - /// Specifies options for configuring an Azure blob storage-based repository. - /// - public class BlobStorageXmlRepositoryOptions - { - /// - /// The blob storage directory where the key ring will be stored. - /// - public CloudBlobDirectory Directory { get; set; } - } -} diff --git a/src/Microsoft.AspNet.DataProtection.Azure/CryptoUtil.cs b/src/Microsoft.AspNet.DataProtection.Azure/CryptoUtil.cs deleted file mode 100644 index b666b6f5cd..0000000000 --- a/src/Microsoft.AspNet.DataProtection.Azure/CryptoUtil.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; -using System.Security.Cryptography; - -namespace Microsoft.AspNet.DataProtection -{ - internal static class CryptoUtil - { - // This isn't a typical Debug.Assert; the check is always performed, even in retail builds. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Assert(bool condition, string message) - { - if (!condition) - { - Fail(message); - } - } - - // This isn't a typical Debug.Fail; an error always occurs, even in retail builds. - // This method doesn't return, but since the CLR doesn't allow specifying a 'never' - // return type, we mimic it by specifying our return type as Exception. That way - // callers can write 'throw Fail(...);' to make the C# compiler happy, as the - // throw keyword is implicitly of type O. - [MethodImpl(MethodImplOptions.NoInlining)] - public static Exception Fail(string message) - { - Debug.Fail(message); - throw new CryptographicException("Assertion failed: " + message); - } - } -} diff --git a/src/Microsoft.AspNet.DataProtection.Azure/Microsoft.AspNet.DataProtection.Azure.xproj b/src/Microsoft.AspNet.DataProtection.Azure/Microsoft.AspNet.DataProtection.Azure.xproj deleted file mode 100644 index 0279cb8079..0000000000 --- a/src/Microsoft.AspNet.DataProtection.Azure/Microsoft.AspNet.DataProtection.Azure.xproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - DF3671D7-A9B1-45F1-A195-0AD596001735 - ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ - - - 2.0 - - - diff --git a/src/Microsoft.AspNet.DataProtection.Azure/project.json b/src/Microsoft.AspNet.DataProtection.Azure/project.json deleted file mode 100644 index 38fe54a39b..0000000000 --- a/src/Microsoft.AspNet.DataProtection.Azure/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "version": "1.0.0-*", - "description": "ASP.NET 5 blob storage repository for DataProtection.", - "dependencies": { - "Microsoft.AspNet.DataProtection": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, - "WindowsAzure.Storage": "4.3.0" - }, - "frameworks": { - "net451": {}, - "dnx451": {} - }, - "compilationOptions": { - "warningsAsErrors": true - } -}