@@ -39,6 +39,15 @@ public class InstallerController : UmbracoAuthorizedApiController
39
39
private static readonly string ImageProcessorWebAssemblyPath = HostingEnvironment . MapPath ( "~/bin/ImageProcessor.Web.dll" ) ;
40
40
private static readonly Version ImageProcessorWebMinRequiredVersion = new Version ( "4.3.2.0" ) ;
41
41
42
+ private static readonly string ImageProcessorConfigPath = HostingEnvironment . MapPath ( "~/Config/imageprocessor/" ) ;
43
+
44
+ private static readonly string ImageProcessorSecurityConfigPath = HostingEnvironment . MapPath ( "~/Config/imageprocessor/security.config" ) ;
45
+ private static readonly string ImageProcessorSecurityDefaultConfigPath = HostingEnvironment . MapPath ( "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/security.config" ) ;
46
+ private static readonly string ImageProcessorSecurityInstallXdtPath = HostingEnvironment . MapPath ( "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/security.config.install.xdt" ) ;
47
+ private static readonly string ImageProcessorSecurityServiceType = "ImageProcessor.Web.Services.CloudImageService, ImageProcessor.Web" ;
48
+ private static readonly string ImageProcessorSecurityServiceName = "CloudImageService" ;
49
+ private static readonly string ImageProcessorSecurityServicePrefix = "media/" ;
50
+
42
51
private readonly string fileSystemProvidersConfigInstallXdtPath = HostingEnvironment . MapPath ( "~/App_Plugins/UmbracoFileSystemProviders/Azure/Install/FileSystemProviders.config.install.xdt" ) ;
43
52
private readonly string fileSystemProvidersConfigPath = HostingEnvironment . MapPath ( "~/Config/FileSystemProviders.config" ) ;
44
53
@@ -53,7 +62,10 @@ public IEnumerable<Parameter> GetParameters()
53
62
public InstallerStatus PostParameters ( IEnumerable < Parameter > parameters )
54
63
{
55
64
var connection = parameters . SingleOrDefault ( k => k . Key == "connectionString" ) . Value ;
56
- var containerName = parameters . SingleOrDefault ( k => k . Key == "containerName" ) . Value ;
65
+ var containerName = parameters . SingleOrDefault ( k => k . Key == "containerName" ) . Value ;
66
+ var rootUrl = parameters . SingleOrDefault ( k => k . Key == "rootUrl" ) . Value ;
67
+
68
+ var host = $ "{ rootUrl } { containerName } /";
57
69
58
70
if ( ! TestAzureCredentials ( connection , containerName ) )
59
71
{
@@ -71,6 +83,14 @@ public InstallerStatus PostParameters(IEnumerable<Parameter> parameters)
71
83
{
72
84
return InstallerStatus . ImageProcessorWebCompatibility ;
73
85
}
86
+ else
87
+ {
88
+ // merge in Storage url
89
+ SaveBlobPathToImageProcessorSecurityXdt ( ImageProcessorSecurityInstallXdtPath , host ) ;
90
+
91
+ // transform ImageProcessor security.config
92
+ ExecuteImageProcessorSecurityConfigTransform ( ) ;
93
+ }
74
94
75
95
return InstallerStatus . Ok ;
76
96
}
@@ -139,6 +159,41 @@ internal static bool SaveParametersToXdt(string xdtPath, IEnumerable<Parameter>
139
159
return result ;
140
160
}
141
161
162
+ internal static bool SaveBlobPathToImageProcessorSecurityXdt ( string xdtPath , string blobPath )
163
+ {
164
+ var result = false ;
165
+
166
+ var document = XmlHelper . OpenAsXmlDocument ( xdtPath ) ;
167
+
168
+ var rawSettings = document . SelectNodes ( string . Format ( "//services/service[@prefix = '{0}' and @name = '{1}' and @type = '{2}']/settings/setting" , ImageProcessorSecurityServicePrefix , ImageProcessorSecurityServiceName , ImageProcessorSecurityServiceType ) ) ;
169
+
170
+ if ( rawSettings == null )
171
+ {
172
+ return false ;
173
+ }
174
+
175
+ foreach ( var setting in from XmlElement setting in rawSettings let key = setting . GetAttribute ( "key" ) where key == "Host" select setting )
176
+ {
177
+ setting . SetAttribute ( "value" , blobPath ) ;
178
+ }
179
+
180
+ try
181
+ {
182
+ document . Save ( xdtPath ) ;
183
+
184
+ // No errors so the result is true
185
+ result = true ;
186
+ }
187
+ catch ( Exception e )
188
+ {
189
+ // Log error message
190
+ var message = "Error saving XDT Settings: " + e . Message ;
191
+ LogHelper . Error ( typeof ( InstallerController ) , message , e ) ;
192
+ }
193
+
194
+ return result ;
195
+ }
196
+
142
197
internal static IEnumerable < Parameter > GetParametersFromXdt ( string xdtPath , string configPath )
143
198
{
144
199
// 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)
@@ -203,6 +258,26 @@ private static bool ExecuteWebConfigTransform()
203
258
return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
204
259
}
205
260
261
+ private static bool ExecuteImageProcessorSecurityConfigTransform ( )
262
+ {
263
+ // Ensure that security.config exists in ~/Config/Imageprocessor/
264
+ if ( ! File . Exists ( ImageProcessorSecurityConfigPath ) )
265
+ {
266
+ if ( ! Directory . Exists ( ImageProcessorConfigPath ) )
267
+ {
268
+ Directory . CreateDirectory ( ImageProcessorConfigPath ) ;
269
+ }
270
+
271
+ File . Copy ( ImageProcessorSecurityDefaultConfigPath , ImageProcessorSecurityConfigPath ) ;
272
+ }
273
+
274
+ var transFormConfigAction = helper . parseStringToXmlNode ( "<Action runat=\" install\" undo=\" true\" alias=\" UmbracoFileSystemProviders.Azure.TransformConfig\" file=\" ~/config/imageprocessor/security.config\" xdtfile=\" ~/app_plugins/UmbracoFileSystemProviders/Azure/install/security.config\" >" +
275
+ "</Action>" ) . FirstChild ;
276
+
277
+ var transformConfig = new PackageActions . TransformConfig ( ) ;
278
+ return transformConfig . Execute ( "UmbracoFileSystemProviders.Azure" , transFormConfigAction ) ;
279
+ }
280
+
206
281
private static bool TestAzureCredentials ( string connectionString , string containerName )
207
282
{
208
283
var useEmulator = ConfigurationManager . AppSettings [ Azure . Constants . Configuration . UseStorageEmulatorKey ] != null
0 commit comments