Skip to content

Commit 36d116e

Browse files
committed
Fix for the installer creating private containers for new installs
1 parent 29a906b commit 36d116e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
8484
bool usePrivateContainer = bool.Parse(newParameters.SingleOrDefault(k => k.Key == "UsePrivateContainer").Value);
8585
string rootUrl = newParameters.SingleOrDefault(k => k.Key == "RootUrl").Value;
8686

87-
if (!TestAzureCredentials(connection, containerName))
87+
BlobContainerPublicAccessType blobContainerPublicAccessType = usePrivateContainer ? BlobContainerPublicAccessType.Off : BlobContainerPublicAccessType.Blob;
88+
89+
if (!TestAzureCredentials(connection, containerName, blobContainerPublicAccessType))
8890
{
8991
return InstallerStatus.ConnectionError;
9092
}
@@ -443,7 +445,7 @@ private static bool ExecuteImageProcessorSecurityConfigTransform()
443445
return true;
444446
}
445447

446-
private static bool TestAzureCredentials(string connectionString, string containerName)
448+
private static bool TestAzureCredentials(string connectionString, string containerName, BlobContainerPublicAccessType accessType)
447449
{
448450
bool useEmulator = ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey] != null
449451
&& ConfigurationManager.AppSettings[Azure.Constants.Configuration.UseStorageEmulatorKey]
@@ -453,11 +455,14 @@ private static bool TestAzureCredentials(string connectionString, string contain
453455
CloudStorageAccount cloudStorageAccount = useEmulator ? CloudStorageAccount.DevelopmentStorageAccount : CloudStorageAccount.Parse(connectionString);
454456

455457
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
456-
CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference(containerName);
457458

458459
// This should fully check that the connection works.
459-
blobContainer.CreateIfNotExists();
460-
return true;
460+
var testContainer = AzureFileSystem.CreateContainer(cloudBlobClient, containerName, accessType);
461+
462+
if (testContainer.Exists())
463+
{
464+
return true;
465+
}
461466
}
462467
catch (Exception e)
463468
{

src/UmbracoFileSystemProviders.Azure/AzureFileSystem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// <summary>
77
// A singleton class for communicating with Azure Blob Storage.
88
// </summary>
9+
using System.Runtime.CompilerServices;
10+
[assembly: InternalsVisibleTo("Our.Umbraco.FileSystemProviders.Azure.Installer")]
911
namespace Our.Umbraco.FileSystemProviders.Azure
1012
{
1113
using System;
@@ -668,7 +670,7 @@ public Stream OpenFile(string path)
668670
/// <param name="containerName">The name of the container.</param>
669671
/// <param name="accessType"><see cref="BlobContainerPublicAccessType"/> indicating the access permissions.</param>
670672
/// <returns>The <see cref="CloudBlobContainer"/></returns>
671-
private static CloudBlobContainer CreateContainer(CloudBlobClient cloudBlobClient, string containerName, BlobContainerPublicAccessType accessType)
673+
internal static CloudBlobContainer CreateContainer(CloudBlobClient cloudBlobClient, string containerName, BlobContainerPublicAccessType accessType)
672674
{
673675
containerName = containerName.ToLowerInvariant();
674676

0 commit comments

Comments
 (0)