Skip to content

Commit

Permalink
KevinJump#128 Autodetect azure blob storage settings
Browse files Browse the repository at this point in the history
Attempt to work out if the container name is being used.
  • Loading branch information
Kevin Jump committed Jul 9, 2020
1 parent 71413b3 commit 51aeb21
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
27 changes: 25 additions & 2 deletions uSync8.ContentEdition/Mapping/Mappers/ImagePathMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -32,15 +33,21 @@ namespace uSync8.ContentEdition.Mapping.Mappers
public class ImagePathMapper : SyncValueMapperBase, ISyncMapper
{
private readonly string siteRoot;
private readonly string mediaFolder;
private readonly string mediaFolder;
private readonly IProfilingLogger logger;

public ImagePathMapper(IEntityService entityService,
IProfilingLogger logger, uSyncConfig config) : base(entityService)
{
this.logger = logger;

siteRoot = SystemDirectories.Root;
mediaFolder = GetMediaFolderSetting(config);

logger.Debug<ImagePathMapper>("Media Folders: [{media}]", mediaFolder);
if (!string.IsNullOrWhiteSpace(mediaFolder))
{
logger.Debug<ImagePathMapper>("Media Folders: [{media}]", mediaFolder);
}
}

public override string Name => "ImageCropper Mapper";
Expand Down Expand Up @@ -148,6 +155,22 @@ private string GetMediaFolderSetting(uSyncConfig config)
if (!string.IsNullOrWhiteSpace(folder))
return folder;

// azure guessing - so for most people seeing this issue,
// they won't have to do any config, as we will detect it ???
var useDefault = ConfigurationManager.AppSettings["AzureBlobFileSystem.UseDefaultRoute:media"];
if (useDefault != null && bool.TryParse(useDefault, out bool usingDefaultRoute) && !usingDefaultRoute)
{
// means azure is configured to not use the default root, so the media
// will be prepended with /container-name.
var containerName = ConfigurationManager.AppSettings["AzureBlobFileSystem.ContainerName:media"];
if (!string.IsNullOrWhiteSpace(containerName))
{
logger.Debug<ImagePathMapper>("Calculating media folder path from AzureBlobFileSystem settings");
return $"/{containerName}";
}
}


// look in the uSync8.config
return config.GetExtensionSetting("media", "folder", string.Empty);
}
Expand Down
11 changes: 9 additions & 2 deletions uSync8.Site/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,16 @@
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="PureLive" />

<add key="uSync.mediaFolder" value="/webconfigfolder"/>
<add key="AzureBlobFileSystem.ContainerName:media" value="jumoo-test-media" />
<add key="AzureBlobFileSystem.RootUrl:media" value="https://jumoodev.blob.core.windows.net/" />
<add key="AzureBlobFileSystem.ConnectionString:media" value="DefaultEndpointsProtocol=https;AccountName=jumoodev;AccountKey=hnW/g1zEkJKWBO1qUPy7zm5YSEACuzcDwMJO3pnoICcagqbyZwYpLK7YieW3KbleddNBYsHKWeBCXSF/BT88Ig==;EndpointSuffix=core.windows.net" />
<add key="AzureBlobFileSystem.MaxDays:media" value="365" />
<add key="AzureBlobFileSystem.UseDefaultRoute:media" value="false" />
<add key="AzureBlobFileSystem.UsePrivateContainer:media" value="false" />


<!--
<!--
<add key="uSync.mediaFolder" value="/webconfigfolder"/>
<add key="uSync.FlatFolders" value="true" />
<add key="uSync.ImportAtStartup" value="true" />
<add key="uSync.ExportAtStartup" value="false" />
Expand Down

0 comments on commit 51aeb21

Please sign in to comment.