Skip to content

Commit 439688f

Browse files
Merge branch 'refs/heads/pr/64' into develop
2 parents 2726aa5 + 8f88c04 commit 439688f

File tree

9 files changed

+65
-11
lines changed

9 files changed

+65
-11
lines changed

build/transforms/FileSystemProviders.config.install.xdt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
of the container name.
2323
-->
2424
<add key="useDefaultRoute" value="true" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
25+
<!--
26+
When true blob containers will be private instead of public what means that you can't access the original blob file directly from its blob url.
27+
-->
28+
<add key="usePrivateContainer" value="false" xdt:Locator="Match(key)" xdt:Transform="InsertIfMissing" />
2529
</Parameters>
2630
</Provider>
2731
<!--

src/.nuget/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="StyleCop.Analyzers" version="1.0.0" />
4+
</packages>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ configApp.controller("Loader", function ($scope, $http, $log) {
3838
};
3939

4040
$scope.getInputType = function (param) {
41-
return param.toUpperCase() === "USEDEFAULTROUTE" ? "checkbox" : "text";
41+
return param.toUpperCase() === "USEDEFAULTROUTE" || param.toUpperCase() === "USEPRIVATECONTAINER" ? "checkbox" : "text";
4242
};
4343
});

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
7777
string connection = newParameters.SingleOrDefault(k => k.Key == "connectionString").Value;
7878
string containerName = newParameters.SingleOrDefault(k => k.Key == "containerName").Value;
7979
bool useDefaultRoute = bool.Parse(newParameters.SingleOrDefault(k => k.Key == "useDefaultRoute").Value);
80+
bool usePrivateContainer = bool.Parse(newParameters.SingleOrDefault(k => k.Key == "usePrivateContainer").Value);
8081
string rootUrl = newParameters.SingleOrDefault(k => k.Key == "rootUrl").Value;
8182

8283
if (!TestAzureCredentials(connection, containerName))

src/UmbracoFileSystemProviders.Azure.Tests/AzureBlobFileSystemTestsBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public AzureBlobFileSystem CreateAzureBlobFileSystem(bool disableVirtualPathProv
4242
string connectionString = "UseDevelopmentStorage=true";
4343
string maxDays = "30";
4444
string useDefaultRoute = "true";
45+
string usePrivateContainer = "false";
4546

4647
Mock<ILogHelper> logHelper = new Mock<ILogHelper>();
4748
Mock<IMimeTypeResolver> mimeTypeHelper = new Mock<IMimeTypeResolver>();
4849

49-
return new AzureBlobFileSystem(containerName, rootUrl, connectionString, maxDays, useDefaultRoute)
50+
return new AzureBlobFileSystem(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, usePrivateContainer)
5051
{
5152
FileSystem =
5253
{

src/UmbracoFileSystemProviders.Azure.Tests/InstallerTests.cs

Lines changed: 1 addition & 1 deletion
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("..\\..\\build\\transforms\\FileSystemProviders.config.install.xdt");
28-
Assert.AreEqual(5, parameters.Count());
28+
Assert.AreEqual(6, parameters.Count());
2929
}
3030

3131
[Test]

src/UmbracoFileSystemProviders.Azure/AzureBlobFileSystem.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under the Apache License, Version 2.0.
44
// </copyright>
55

6+
using Microsoft.WindowsAzure.Storage.Blob;
7+
68
namespace Our.Umbraco.FileSystemProviders.Azure
79
{
810
using System;
@@ -42,14 +44,31 @@ public class AzureBlobFileSystem : IFileSystem
4244
/// </summary>
4345
private const string UseDefaultRootKey = Constants.Configuration.UseDefaultRouteKey;
4446

47+
/// <summary>
48+
/// The configuration key for determining whether the container should be private.
49+
/// </summary>
50+
private const string UsePrivateContainerKey = Constants.Configuration.UsePrivateContainer;
51+
4552
/// <summary>
4653
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
4754
/// </summary>
4855
/// <param name="containerName">The container name.</param>
4956
/// <param name="rootUrl">The root url.</param>
5057
/// <param name="connectionString">The connection string.</param>
5158
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString)
52-
: this(containerName, rootUrl, connectionString, "365", "true")
59+
: this(containerName, rootUrl, connectionString, "365", "true", "false")
60+
{
61+
}
62+
63+
/// <summary>
64+
/// Initializes a new instance of the <see cref="AzureBlobFileSystem"/> class.
65+
/// </summary>
66+
/// <param name="containerName">The container name.</param>
67+
/// <param name="rootUrl">The root url.</param>
68+
/// <param name="connectionString">The connection string.</param>
69+
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
70+
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
71+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute): this(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, "false")
5372
{
5473
}
5574

@@ -61,9 +80,10 @@ public AzureBlobFileSystem(string containerName, string rootUrl, string connecti
6180
/// <param name="connectionString">The connection string.</param>
6281
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
6382
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
64-
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
83+
/// <param name="usePrivateContainer">blob container can be private (no direct access) or public (direct access possible, default)</param>
84+
public AzureBlobFileSystem(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute, string usePrivateContainer)
6585
{
66-
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
86+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, usePrivateContainer);
6787
}
6888

6989
/// <summary>
@@ -100,7 +120,16 @@ public AzureBlobFileSystem(string alias)
100120
useDefaultRoute = "true";
101121
}
102122

103-
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute);
123+
string accessType = ConfigurationManager.AppSettings[$"{UsePrivateContainerKey}:{alias}"];
124+
if (string.IsNullOrWhiteSpace(accessType))
125+
{
126+
accessType = "true";
127+
}
128+
129+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute, accessType);
130+
131+
132+
this.FileSystem = AzureFileSystem.GetInstance(containerName, rootUrl, connectionString, maxDays, useDefaultRoute,accessType);
104133
}
105134
else
106135
{

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ internal class AzureFileSystem : IFileSystem
7777
/// <param name="connectionString">The connection string.</param>
7878
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
7979
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
80+
/// <param name="accessType"><see cref="BlobContainerPublicAccessType"/> indicating the access permissions.</param>
8081
/// <exception cref="ArgumentNullException">
8182
/// Thrown if <paramref name="containerName"/> is null or whitespace.
8283
/// </exception>
83-
internal AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays, bool useDefaultRoute)
84+
internal AzureFileSystem(string containerName, string rootUrl, string connectionString, int maxDays, bool useDefaultRoute, BlobContainerPublicAccessType accessType)
8485
{
8586
if (string.IsNullOrWhiteSpace(containerName))
8687
{
@@ -107,7 +108,7 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
107108
}
108109

109110
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
110-
this.cloudBlobContainer = CreateContainer(cloudBlobClient, containerName, BlobContainerPublicAccessType.Blob);
111+
this.cloudBlobContainer = CreateContainer(cloudBlobClient, containerName, accessType);
111112

112113
// First assign a local copy before editing. We use that to track the type.
113114
// TODO: Do we need this? The container should be an identifer.
@@ -166,8 +167,9 @@ internal AzureFileSystem(string containerName, string rootUrl, string connection
166167
/// <param name="connectionString">The connection string.</param>
167168
/// <param name="maxDays">The maximum number of days to cache blob items for in the browser.</param>
168169
/// <param name="useDefaultRoute">Whether to use the default "media" route in the url independent of the blob container.</param>
170+
/// <param name="usePrivateContainer">blob container can be private (no direct access) or public (direct access possible, default)</param>
169171
/// <returns>The <see cref="AzureFileSystem"/></returns>
170-
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute)
172+
public static AzureFileSystem GetInstance(string containerName, string rootUrl, string connectionString, string maxDays, string useDefaultRoute, string usePrivateContainer)
171173
{
172174
lock (Locker)
173175
{
@@ -187,7 +189,15 @@ public static AzureFileSystem GetInstance(string containerName, string rootUrl,
187189
defaultRoute = true;
188190
}
189191

190-
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute);
192+
bool privateContainer;
193+
if (!bool.TryParse(usePrivateContainer, out privateContainer))
194+
{
195+
privateContainer = true;
196+
}
197+
198+
var blobContainerPublicAccessType = privateContainer ? BlobContainerPublicAccessType.Off : BlobContainerPublicAccessType.Blob;
199+
200+
fileSystem = new AzureFileSystem(containerName, rootUrl, connectionString, max, defaultRoute, blobContainerPublicAccessType);
191201
FileSystems.Add(fileSystem);
192202
}
193203

src/UmbracoFileSystemProviders.Azure/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public static class Configuration
5454
/// The configuration key for providing the Use Default Root value via the web.config
5555
/// </summary>
5656
public const string UseDefaultRouteKey = "AzureBlobFileSystem.UseDefaultRoute";
57+
58+
/// <summary>
59+
/// The configuration key for providing the Use Private Container value via the web.config
60+
/// </summary>
61+
public const string UsePrivateContainer = "AzureBlobFileSystem.UsePrivateContainer";
5762
}
5863
}
5964
}

0 commit comments

Comments
 (0)