Skip to content

Commit eed94ae

Browse files
Allow independent container and path
Should allow for a different container name while still using media as the route prefix. Needs double checking.
1 parent 3e48bb7 commit eed94ae

15 files changed

+106
-53
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ configApp.controller("Loader", function ($scope, $http, $log) {
3636
$scope.capitalizeFirstLetter = function (string) {
3737
return string.charAt(0).toUpperCase() + string.slice(1);
3838
}
39+
40+
$scope.getInputType = function (param) {
41+
return param.toUpperCase() === "USEDEFAULTROUTE" ? "checkbox" : "text";
42+
}
3943
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<input
4141
class ="input-block-level"
4242
dynamic-name="param.Key"
43-
type="text"
43+
type="{{ getInputType(param.Key) }}"
4444
ng-model="param.Value"
4545
required
4646
>

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ public IEnumerable<Parameter> GetParameters()
6262
[HttpPost]
6363
public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
6464
{
65-
var connection = parameters.SingleOrDefault(k => k.Key == "connectionString").Value;
66-
var containerName = parameters.SingleOrDefault(k => k.Key == "containerName").Value;
67-
var rootUrl = parameters.SingleOrDefault(k => k.Key == "rootUrl").Value;
65+
var newParameters = parameters as IList<Parameter> ?? parameters.ToList();
66+
var connection = newParameters.SingleOrDefault(k => k.Key == "connectionString").Value;
67+
var containerName = newParameters.SingleOrDefault(k => k.Key == "containerName").Value;
68+
bool useDefaultRoute = bool.Parse(newParameters.SingleOrDefault(k => k.Key == "useDefaultRoute").Value);
69+
var rootUrl = newParameters.SingleOrDefault(k => k.Key == "rootUrl").Value;
6870

6971
if (!TestAzureCredentials(connection, containerName))
7072
{
7173
return InstallerStatus.ConnectionError;
7274
}
7375

74-
if (SaveParametersToFileSystemProvidersXdt(this.fileSystemProvidersConfigInstallXdtPath, parameters) && SaveContainerNameToWebConfigXdt(this.webConfigXdtPath, containerName))
76+
if (SaveParametersToFileSystemProvidersXdt(this.fileSystemProvidersConfigInstallXdtPath, newParameters) && SaveContainerNameToWebConfigXdt(this.webConfigXdtPath, containerName))
7577
{
7678
if (!ExecuteFileSystemConfigTransform() || !ExecuteWebConfigTransform())
7779
{
@@ -85,7 +87,11 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
8587
else
8688
{
8789
// merge in storage url to ImageProcessor security.config xdt
88-
SaveBlobPathToImageProcessorSecurityXdt(ImageProcessorSecurityInstallXdtPath, rootUrl, containerName);
90+
string prefix = useDefaultRoute
91+
? Azure.Constants.DefaultMediaRoute
92+
: containerName;
93+
94+
SaveBlobPathToImageProcessorSecurityXdt(ImageProcessorSecurityInstallXdtPath, rootUrl, prefix, containerName);
8995

9096
// transform ImageProcessor security.config
9197
if (ExecuteImageProcessorSecurityConfigTransform())
@@ -180,7 +186,10 @@ internal static bool SaveContainerNameToWebConfigXdt(string xdtPath, string cont
180186
nsMgr.AddNamespace("xdt", strNamespace);
181187

182188
var locationElement = document.SelectSingleNode(string.Format("//location"));
183-
if (locationElement != null) locationElement.Attributes["path"].Value = containerName;
189+
if (locationElement != null)
190+
{
191+
locationElement.Attributes["path"].Value = containerName;
192+
}
184193

185194
try
186195
{
@@ -199,7 +208,7 @@ internal static bool SaveContainerNameToWebConfigXdt(string xdtPath, string cont
199208
return result;
200209
}
201210

202-
internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, string rootUrl, string containerName)
211+
internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, string rootUrl, string prefix, string containerName)
203212
{
204213
var result = false;
205214

@@ -214,7 +223,7 @@ internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, str
214223

215224
foreach (XmlElement service in rawServices)
216225
{
217-
service.SetAttribute("prefix", $"{containerName}/");
226+
service.SetAttribute("prefix", $"{prefix}/");
218227
}
219228

220229
// Set the settings within the InsertIfMissing action
@@ -249,14 +258,14 @@ internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, str
249258
internal static IEnumerable<Parameter> GetParametersFromXdt(string xdtPath, string configPath)
250259
{
251260
// For package upgrades check for configured values in existing FileSystemProviders.config and merge with the Parameters from the XDT file (there could be new ones)
252-
var xdtParameters = GetParametersFromXml(xdtPath);
253-
var currentConfigParameters = GetParametersFromXml(configPath);
261+
List<Parameter> xdtParameters = GetParametersFromXml(xdtPath).ToList();
262+
List<Parameter> currentConfigParameters = GetParametersFromXml(configPath).ToList();
254263

255-
foreach (var parameter in xdtParameters)
264+
foreach (Parameter parameter in xdtParameters)
256265
{
257266
if (currentConfigParameters.Select(k => k.Key).Contains(parameter.Key))
258267
{
259-
var currentParameter = currentConfigParameters.SingleOrDefault(k => k.Key == parameter.Key);
268+
Parameter currentParameter = currentConfigParameters.SingleOrDefault(k => k.Key == parameter.Key);
260269
if (currentParameter != null)
261270
{
262271
parameter.Value = currentParameter.Value;

src/UmbracoFileSystemProviders.Azure.Tests/AzureBlobFileSystemTestsBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public AzureBlobFileSystem CreateAzureBlobFileSystem(bool disableVirtualPathProv
4545
Mock<ILogHelper> logHelper = new Mock<ILogHelper>();
4646
Mock<IMimeTypeResolver> mimeTypeHelper = new Mock<IMimeTypeResolver>();
4747

48-
return new AzureBlobFileSystem(containerName, rootUrl, connectionString, maxDays)
48+
return new AzureBlobFileSystem(containerName, rootUrl, connectionString, maxDays, true)
4949
{
5050
FileSystem =
5151
{

src/UmbracoFileSystemProviders.Azure.Tests/FileSystemProviders.config.install.xdt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</Provider>
99

1010
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure" xdt:Locator="Match(type)" xdt:Transform="InsertIfMissing">
11-
<Parameters xdt:Transform="InsertIfMissing">
11+
<Parameters xdt:Transform="InsertIfMissing">
1212
<add key="containerName" value="media" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1313
<add key="rootUrl" value="http://[myAccountName].blob.core.windows.net/" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
1414
<add key="connectionString" value="DefaultEndpointsProtocol=https;AccountName=[myAccountName];AccountKey=[myAccountKey]" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
@@ -17,6 +17,11 @@
1717
Defaults to 365 days.
1818
-->
1919
<add key="maxDays" value="365" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
20+
<!--
21+
When true this allows the VirtualPathProvider to use the deafult "media" route prefix regardless
22+
of the container name.
23+
-->
24+
<add key="useDefaultRoute" value="true" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
2025
</Parameters>
2126
</Provider>
2227
<!--
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<?xml version="1.0"?>
22
<FileSystemProviders>
3-
3+
44
<!-- Media -->
55
<Provider alias="media" type="Our.Umbraco.FileSystemProviders.Azure.AzureBlobFileSystem, Our.Umbraco.FileSystemProviders.Azure">
6-
<Parameters>
7-
<add key="containerName" value="media"/>
8-
<add key="rootUrl" value="http://existing123456789.blob.core.windows.net/"/>
9-
<add key="connectionString"
6+
<Parameters>
7+
<add key="containerName" value="media"/>
8+
<add key="rootUrl" value="http://existing123456789.blob.core.windows.net/"/>
9+
<add key="connectionString"
1010
value="DefaultEndpointsProtocol=https;AccountName=existing123456789;AccountKey=existingKey"/>
11-
<!--
11+
<!--
1212
Optional configuration value determining the maximum number of days to cache items in the browser.
1313
Defaults to 365 days.
1414
-->
15-
<add key="maxDays" value="365"/>
16-
</Parameters>
15+
<add key="maxDays" value="365"/>
16+
<!--
17+
When true this allows the VirtualPathProvider to use the deafult "media" route prefix regardless
18+
of the container name.
19+
-->
20+
<add key="useDefaultRoute" value="true"/>
21+
</Parameters>
1722
</Provider>
18-
23+
1924
</FileSystemProviders>

src/UmbracoFileSystemProviders.Azure.Tests/FileSystemVirtualPathProviderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public void FilePathPrefixFormatted()
3636
{
3737
// Arrange/Act
3838
Mock<IFileSystem> fileProvider = new Mock<IFileSystem>();
39-
FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider("media", new Lazy<IFileSystem>(() => fileProvider.Object));
40-
39+
FileSystemVirtualPathProvider provider = new FileSystemVirtualPathProvider(Constants.DefaultMediaRoute, new Lazy<IFileSystem>(() => fileProvider.Object));
40+
4141
// Assert
4242
Assert.AreEqual(provider.PathPrefix, "/media/");
4343
}
@@ -54,7 +54,7 @@ public void FilePathShouldBeExecuted()
5454

5555
// Act
5656
VirtualFile result = provider.GetFile("~/media/1010/media.jpg");
57-
57+
5858
// Assert
5959
Assert.IsNotNull(result);
6060
}

src/UmbracoFileSystemProviders.Azure.Tests/InstallerTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void CheckXdtFirstParameterKey()
2525
public void CheckXdtNumberOfParameters()
2626
{
2727
var parameters = InstallerController.GetParametersFromXml("FileSystemProviders.config.install.xdt");
28-
Assert.AreEqual(4, parameters.Count());
28+
Assert.AreEqual(5, parameters.Count());
2929
}
3030

3131
[Test]
@@ -41,6 +41,5 @@ public void CheckNewInstallDefaultConfig()
4141
var parameters = InstallerController.GetParametersFromXdt("FileSystemProviders.config.install.xdt", "FileSystemProviders.default.config");
4242
Assert.AreEqual("http://[myAccountName].blob.core.windows.net/", parameters.Single(k => k.Key == "rootUrl").Value);
4343
}
44-
4544
}
4645
}

src/UmbracoFileSystemProviders.Azure.Tests/stylecop.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
33
"settings": {
44
"documentationRules": {
5-
"companyName": "James Jackson-South",
5+
"companyName": "James Jackson-South and contributors",
66
"copyrightText": "Copyright (c) {companyName}. All rights reserved.\nLicensed under the Apache License, Version 2.0."
77
}
88
}

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class AzureBlobFileSystem : IFileSystem
2424
/// <param name="containerName">The container name.</param>
2525
/// <param name="rootUrl">The root url.</param>
2626
/// <param name="connectionString">The connection string.</param>
27-
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString) :
28-
this(containerName, rootUrl, connectionString, "365")
27+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString)
28+
: this(containerName, rootUrl, connectionString, "365", true)
2929
{
3030
}
3131

@@ -36,9 +36,10 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
3636
/// <param name="rootUrl">The root url.</param>
3737
/// <param name="connectionString">The connection string.</param>
3838
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
39-
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays)
39+
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
40+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, bool useDefaultRoute)
4041
{
41-
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays);
42+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
4243
}
4344

4445
/// <summary>

0 commit comments

Comments
 (0)