Skip to content

Commit c7d6c12

Browse files
committed
Update the method that sets the values in the ImageProcessor security.config so that it supports custom containerNames
1 parent ed9136f commit c7d6c12

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/UmbracoFileSystemProviders.Azure.Installer/InstallerController.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class InstallerController : UmbracoAuthorizedApiController
4646
private static readonly string ImageProcessorSecurityInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/security.config.install.xdt");
4747
private static readonly string ImageProcessorSecurityServiceType = "ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web";
4848
private static readonly string ImageProcessorSecurityServiceName = "CloudImageService";
49-
private static readonly string ImageProcessorSecurityServicePrefix = "media/";
5049

5150
private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment.MapPath("~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt");
5251
private readonly string fileSystemProvidersConfigPath = HostingEnvironment.MapPath("~/Config/FileSystemProviders.config");
@@ -65,8 +64,6 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
6564
var containerName = parameters.SingleOrDefault(k => k.Key == "containerName").Value;
6665
var rootUrl = parameters.SingleOrDefault(k => k.Key == "rootUrl").Value;
6766

68-
var host = $"{rootUrl}{containerName}/";
69-
7067
if (!TestAzureCredentials(connection, containerName))
7168
{
7269
return InstallerStatus.ConnectionError;
@@ -86,7 +83,7 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
8683
else
8784
{
8885
// merge in storage url to ImageProcessor security.config xdt
89-
SaveBlobPathToImageProcessorSecurityXdt(ImageProcessorSecurityInstallXdtPath, host);
86+
SaveBlobPathToImageProcessorSecurityXdt(ImageProcessorSecurityInstallXdtPath, rootUrl, containerName);
9087

9188
// transform ImageProcessor security.config
9289
if (ExecuteImageProcessorSecurityConfigTransform())
@@ -169,22 +166,34 @@ internal static bool SaveParametersToXdt(string xdtPath, IEnumerable<Parameter>
169166
return result;
170167
}
171168

172-
internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, string blobPath)
169+
internal static bool SaveBlobPathToImageProcessorSecurityXdt(string xdtPath, string rootUrl, string containerName)
173170
{
174171
var result = false;
175172

176173
var document = XmlHelper.OpenAsXmlDocument(xdtPath);
177174

178-
var rawSettings = document.SelectNodes(string.Format("//services/service[@prefix = '{0}' and @name = '{1}' and @type = '{2}']/settings/setting", ImageProcessorSecurityServicePrefix, ImageProcessorSecurityServiceName, ImageProcessorSecurityServiceType));
175+
// Set the prefix attribute on both the Remove and InsertIfMissing actions
176+
var rawServices = document.SelectNodes($"//services/service[@name = '{ImageProcessorSecurityServiceName}' and @type = '{ImageProcessorSecurityServiceType}']");
177+
if (rawServices == null)
178+
{
179+
return false;
180+
}
181+
182+
foreach (XmlElement service in rawServices)
183+
{
184+
service.SetAttribute("prefix", $"{containerName}/");
185+
}
179186

187+
// Set the settings within the InsertIfMissing action
188+
var rawSettings = document.SelectNodes($"//services/service[@prefix = '{containerName}/' and @name = '{ImageProcessorSecurityServiceName}' and @type = '{ImageProcessorSecurityServiceType}']/settings/setting");
180189
if (rawSettings == null)
181190
{
182191
return false;
183192
}
184193

185194
foreach (var setting in from XmlElement setting in rawSettings let key = setting.GetAttribute("key") where key == "Host" select setting)
186195
{
187-
setting.SetAttribute("value", blobPath);
196+
setting.SetAttribute("value", $"{rootUrl}{containerName}/");
188197
}
189198

190199
try

0 commit comments

Comments
 (0)