Skip to content

Commit 67d2842

Browse files
committed
Adding check to the Umbraco installer to ensure that the Azure Connection string works before saving the config
1 parent a7e58ed commit 67d2842

File tree

6 files changed

+121
-11
lines changed

6 files changed

+121
-11
lines changed

src/UmbracoFileSystemProviders.Azure.Installer/Configurator/Controllers/Configure.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
configApp.controller("Loader", function ($scope, $http, $log) {
44
var getDataUrl = "/Umbraco/backoffice/FileSystemProviders/Installer/GetParameters";
5-
var postDataUrl = "/Umbraco/backoffice/FileSystemProviders/Installer/PostParameters";
5+
var postDataUrl = "/Umbraco/backoffice/FileSystemProviders/Installer/PostParameters";
66

77
$scope.saved = false;
88

@@ -16,12 +16,16 @@ configApp.controller("Loader", function ($scope, $http, $log) {
1616

1717
$http.post(postDataUrl, $scope.parameters).success(function (data) {
1818
$scope.saved = true;
19-
$scope.status = data;
19+
if (typeof data === 'string') {
20+
$scope.status = JSON.parse(data);
21+
} else {
22+
$scope.status = data;
23+
}
2024
});
2125

2226
}
2327

24-
$scope.capitalizeFirstLetter = function(string) {
28+
$scope.capitalizeFirstLetter = function (string) {
2529
return string.charAt(0).toUpperCase() + string.slice(1);
2630
}
2731
});

src/UmbracoFileSystemProviders.Azure.Installer/Configurator/Views/Configure.ascx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<button preventDefault class="btn btn-primary" ng-disabled="paramForm.$invalid" ng-click="submitForm($event)">Save</button>
2929
</form>
3030
</fieldset>
31-
<div ng-show="saved && status">
31+
<div ng-show="saved && status === 'Ok'">
3232
<h3>The Azure storage provider was sucessfully configured and your media is now as light as candyfloss</h3>
3333
</div>
34-
<div ng-show="saved && !status">
34+
<div ng-show="saved && status != 'Ok'">
3535
<h3>Oh no, something went wrong saving, please check Umbraco log files for exceptions</h3>
3636
</div>
3737
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <copyright file="InstallerStatus.cs" company="James Jackson-South">
3+
// Copyright (c) James Jackson-South. All rights reserved. Licensed under the Apache License, Version 2.0.
4+
// </copyright>
5+
// --------------------------------------------------------------------------------------------------------------------
6+
7+
namespace Our.Umbraco.FileSystemProviders.Azure.Installer.Enums
8+
{
9+
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Converters;
11+
12+
[JsonConverter(typeof(StringEnumConverter))]
13+
public enum InstallerStatus
14+
{
15+
Ok,
16+
SaveXdtError,
17+
SaveConfigError,
18+
ConnectionError
19+
}
20+
}

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
// Copyright (c) James Jackson-South. All rights reserved. Licensed under the Apache License, Version 2.0.
44
// </copyright>
55
// --------------------------------------------------------------------------------------------------------------------
6+
7+
using System.Configuration;
68
using System.Runtime.CompilerServices;
9+
using Microsoft.WindowsAzure.Storage;
10+
using Microsoft.WindowsAzure.Storage.Blob;
11+
using Our.Umbraco.FileSystemProviders.Azure.Installer.Enums;
712

813
[assembly: InternalsVisibleTo("Our.Umbraco.FileSystemProviders.Azure.Tests")]
914
namespace Our.Umbraco.FileSystemProviders.Azure.Installer
@@ -39,17 +44,27 @@ public IEnumerable<Parameter> GetParameters()
3944

4045
// /Umbraco/backoffice/FileSystemProviders/Installer/PostParameters
4146
[HttpPost]
42-
public bool PostParameters(IEnumerable<Parameter> parameters)
47+
public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
4348
{
49+
var connection = parameters.SingleOrDefault(k => k.Key == "connectionString").Value;
50+
var containerName = parameters.SingleOrDefault(k => k.Key == "containerName").Value;
51+
52+
if (!this.TestAzureCredentials(connection, containerName))
53+
{
54+
return InstallerStatus.ConnectionError;
55+
}
56+
4457
if (SaveParametersToXdt(_fileSystemProvidersConfigInstallXdtPath, parameters))
4558
{
46-
if (ExecuteFileSystemConfigTransform() && ExecuteWebConfigTransform())
59+
if (!ExecuteFileSystemConfigTransform() || !ExecuteWebConfigTransform())
4760
{
48-
return true;
61+
return InstallerStatus.SaveConfigError;
4962
}
63+
64+
return InstallerStatus.Ok;
5065
}
5166

52-
return false;
67+
return InstallerStatus.SaveXdtError;
5368
}
5469

5570
internal static bool SaveParametersToXdt(string xdtPath, IEnumerable<Parameter> newParameters)
@@ -149,6 +164,39 @@ internal static IEnumerable<Parameter> GetParametersFromXml(string xmlPath)
149164
return settings;
150165
}
151166

167+
private bool TestAzureCredentials(string connectionString, string containerName)
168+
{
169+
bool useEmulator = ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey] != null
170+
&& ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey]
171+
.Equals("true", StringComparison.InvariantCultureIgnoreCase);
172+
173+
try
174+
{
175+
CloudStorageAccount cloudStorageAccount;
176+
if (useEmulator)
177+
{
178+
cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
179+
}
180+
else
181+
{
182+
cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
183+
}
184+
185+
var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
186+
var blobContainer = cloudBlobClient.GetContainerReference(containerName);
187+
188+
// this should fully check that the connection works
189+
var blobExists = blobContainer.Exists();
190+
}
191+
catch (Exception e)
192+
{
193+
LogHelper.Error<InstallerController>(string.Format("Error validating Azure storage connection: {0}", e.Message), e);
194+
return false;
195+
}
196+
197+
return true;
198+
}
199+
152200
private static bool ExecuteFileSystemConfigTransform()
153201
{
154202
var transFormConfigAction = helper.parseStringToXmlNode("<Action runat=\"install\" undo=\"true\" alias=\"UmbracoFileSystemProviders.Azure.TransformConfig\" file=\"~/Config/FileSystemProviders.config\" xdtfile=\"~/app_plugins/UmbracoFileSystemProviders/Azure/install/FileSystemProviders.config\">" +

src/UmbracoFileSystemProviders.Azure.Installer/UmbracoFileSystemProviders.Azure.Installer.csproj

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
<HintPath>..\packages\UmbracoCms.Core.6.2.5\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
8585
<Private>True</Private>
8686
</Reference>
87+
<Reference Include="Microsoft.Data.Edm, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
88+
<HintPath>..\packages\Microsoft.Data.Edm.5.6.2\lib\net40\Microsoft.Data.Edm.dll</HintPath>
89+
<Private>True</Private>
90+
</Reference>
91+
<Reference Include="Microsoft.Data.OData, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
92+
<HintPath>..\packages\Microsoft.Data.OData.5.6.2\lib\net40\Microsoft.Data.OData.dll</HintPath>
93+
<Private>True</Private>
94+
</Reference>
95+
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
96+
<HintPath>..\packages\Microsoft.Data.Services.Client.5.6.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
97+
<Private>True</Private>
98+
</Reference>
8799
<Reference Include="Microsoft.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
88100
<HintPath>..\packages\UmbracoCms.Core.6.2.5\lib\Microsoft.Web.Helpers.dll</HintPath>
89101
<Private>True</Private>
@@ -100,6 +112,14 @@
100112
<HintPath>..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
101113
<Private>True</Private>
102114
</Reference>
115+
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
116+
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
117+
<Private>True</Private>
118+
</Reference>
119+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
120+
<HintPath>..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
121+
<Private>True</Private>
122+
</Reference>
103123
<Reference Include="MiniProfiler, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL">
104124
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
105125
<Private>True</Private>
@@ -109,7 +129,7 @@
109129
<Private>True</Private>
110130
</Reference>
111131
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
112-
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
132+
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
113133
<Private>True</Private>
114134
</Reference>
115135
<Reference Include="Our.Umbraco.uGoLive, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
@@ -129,6 +149,7 @@
129149
<Private>True</Private>
130150
</Reference>
131151
<Reference Include="System" />
152+
<Reference Include="System.Configuration" />
132153
<Reference Include="System.Core" />
133154
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
134155
<HintPath>..\packages\UmbracoCms.Core.6.2.5\lib\System.Data.SqlServerCe.dll</HintPath>
@@ -143,6 +164,10 @@
143164
<Private>True</Private>
144165
</Reference>
145166
<Reference Include="System.Net.Http.WebRequest" />
167+
<Reference Include="System.Spatial, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
168+
<HintPath>..\packages\System.Spatial.5.6.2\lib\net40\System.Spatial.dll</HintPath>
169+
<Private>True</Private>
170+
</Reference>
146171
<Reference Include="System.Web" />
147172
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
148173
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
@@ -232,6 +257,7 @@
232257
</Reference>
233258
</ItemGroup>
234259
<ItemGroup>
260+
<Compile Include="Enums\InstallerStatus.cs" />
235261
<Compile Include="Properties\AssemblyInfo.cs" />
236262
<Compile Include="Models\Parameter.cs" />
237263
<Compile Include="InstallerController.cs" />
@@ -252,6 +278,12 @@
252278
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta014\analyzers\dotnet\cs\Newtonsoft.Json.dll" />
253279
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta014\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
254280
</ItemGroup>
281+
<ItemGroup>
282+
<ProjectReference Include="..\UmbracoFileSystemProviders.Azure\UmbracoFileSystemProviders.Azure.csproj">
283+
<Project>{749bc432-144a-4250-9066-d1fe170afe42}</Project>
284+
<Name>UmbracoFileSystemProviders.Azure</Name>
285+
</ProjectReference>
286+
</ItemGroup>
255287
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
256288
<Import Project="..\packages\StyleCop.Analyzers.1.0.0-beta014\build\StyleCop.Analyzers.targets" Condition="Exists('..\packages\StyleCop.Analyzers.1.0.0-beta014\build\StyleCop.Analyzers.targets')" />
257289
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/UmbracoFileSystemProviders.Azure.Installer/packages.config

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net45" />
1414
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
1515
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
16+
<package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />
17+
<package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />
18+
<package id="Microsoft.Data.Services.Client" version="5.6.2" targetFramework="net45" />
1619
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
1720
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
1821
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
22+
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net45" />
1923
<package id="MiniProfiler" version="2.1.0" targetFramework="net45" />
2024
<package id="MySql.Data" version="6.6.5" targetFramework="net45" />
21-
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
25+
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
2226
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
2327
<package id="StyleCop.Analyzers" version="1.0.0-beta014" targetFramework="net45" developmentDependency="true" />
28+
<package id="System.Spatial" version="5.6.2" targetFramework="net45" />
2429
<package id="UmbracoCms.Core" version="6.2.5" targetFramework="net45" />
30+
<package id="WindowsAzure.Storage" version="4.3.0" targetFramework="net45" />
2531
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
2632
</packages>

0 commit comments

Comments
 (0)