Skip to content

Commit

Permalink
Added support to configure blob container public access level
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasJakobsson committed Apr 13, 2021
1 parent ddf9ca3 commit a4664a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private async Task<BlobContainerClient> InitCloudStorage(int remainingTries)
}

var response = await blobClient.CreateIfNotExistsAsync(
PublicAccessType.BlobContainer,
_settings.ContainerPublicAccessType,
cancellationToken: cts.Token);

if (response.GetRawResponse().Status == (int)HttpStatusCode.Created)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using Akka.Configuration;
using Akka.Persistence.Azure.Util;
using Azure.Storage.Blobs.Models;

namespace Akka.Persistence.Azure.Snapshot
{
Expand All @@ -17,7 +18,8 @@ namespace Akka.Persistence.Azure.Snapshot
public sealed class AzureBlobSnapshotStoreSettings
{
public AzureBlobSnapshotStoreSettings(string connectionString, string containerName,
TimeSpan connectTimeout, TimeSpan requestTimeout, bool verboseLogging, bool development, bool autoInitialize)
TimeSpan connectTimeout, TimeSpan requestTimeout, bool verboseLogging, bool development, bool autoInitialize,
string containerPublicAccessType)
{
if (string.IsNullOrWhiteSpace(containerName))
throw new ConfigurationException("[AzureBlobSnapshotStore] Container name is null or empty.");
Expand All @@ -30,6 +32,10 @@ public AzureBlobSnapshotStoreSettings(string connectionString, string containerN
VerboseLogging = verboseLogging;
Development = development;
AutoInitialize = autoInitialize;
ContainerPublicAccessType =
Enum.TryParse<PublicAccessType>(containerPublicAccessType, true, out var accessType)
? accessType
: PublicAccessType.BlobContainer;
}

/// <summary>
Expand Down Expand Up @@ -60,6 +66,8 @@ public AzureBlobSnapshotStoreSettings(string connectionString, string containerN
public bool Development { get; }

public bool AutoInitialize { get; }

public PublicAccessType ContainerPublicAccessType { get; }

/// <summary>
/// Creates an <see cref="AzureBlobSnapshotStoreSettings" /> instance using the
Expand All @@ -76,6 +84,7 @@ public static AzureBlobSnapshotStoreSettings Create(Config config)
var verbose = config.GetBoolean("verbose-logging", false);
var development = config.GetBoolean("development", false);
var autoInitialize = config.GetBoolean("auto-initialize", true);
var containerPublicAccessType = config.GetString("container-public-access-type", PublicAccessType.BlobContainer.ToString());

return new AzureBlobSnapshotStoreSettings(
connectionString,
Expand All @@ -84,7 +93,8 @@ public static AzureBlobSnapshotStoreSettings Create(Config config)
requestTimeout,
verbose,
development,
autoInitialize);
autoInitialize,
containerPublicAccessType);
}
}
}
3 changes: 3 additions & 0 deletions src/Akka.Persistence.Azure/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ akka.persistence {

# Creates the required container if set
auto-initialize = on

# Public access level for storage container. Can be "None", "BlobContainer" or "Blob"
container-public-access-type = "BlobContainer"
}
}
}

0 comments on commit a4664a9

Please sign in to comment.