Skip to content

Commit

Permalink
(#217) Support non-AzureWebJobsStorage connection strings (#219)
Browse files Browse the repository at this point in the history
* #217, implementation for inproc

* #217, implementation for isolated

* #217, implementation for vscode ext
  • Loading branch information
scale-tone authored Nov 2, 2024
1 parent 9a99d06 commit 88455a5
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
6 changes: 4 additions & 2 deletions durablefunctionsmonitor-vscodeext/src/MonitorViewList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class MonitorViewList {
return this._monitorViews[keys[0]];
}

// Parses local project files and tries to infer connction settings from them
// Parses local project files and tries to infer connection settings from them
getStorageConnectionSettingsFromCurrentProject(defaultTaskHubName?: string, projectPath?: string): StorageConnectionSettings | null {

const hostJson = this.readHostJson(projectPath);
Expand Down Expand Up @@ -158,7 +158,7 @@ export class MonitorViewList {
return new StorageConnectionSettings(ConnStringUtils.ExpandEmulatorShortcutIfNeeded(storageConnString), hubName, hubsConnString);
}

const storageConnString = this.getValueFromLocalSettings('AzureWebJobsStorage', projectPath);
const storageConnString = this.getValueFromLocalSettings(hostJson.connectionStringName || 'AzureWebJobsStorage', projectPath);
if (!storageConnString) {
return null;
}
Expand Down Expand Up @@ -512,6 +512,8 @@ export class MonitorViewList {
result.connectionStringName = durableTask.storageProvider.StorageConnectionName || 'AzureWebJobsStorage';
result.otherConnectionStringName = durableTask.storageProvider.EventHubsConnectionName || 'EventHubsConnection';
break;
default:
result.connectionStringName = durableTask.storageProvider.connectionStringName;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion durablefunctionsmonitor.dotnetbackend/Common/Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static async Task<HashSet<string>> GetAllowedTaskHubNamesAsync()
try
{
var hubNames = new HashSet<string>(
await DfmEndpoint.ExtensionPoints.GetTaskHubNamesRoutine(EnvVariableNames.AzureWebJobsStorage),
await DfmEndpoint.ExtensionPoints.GetTaskHubNamesRoutine(DfmEndpoint.StorageConnStringEnvVarName),
StringComparer.InvariantCultureIgnoreCase
);

Expand Down
2 changes: 1 addition & 1 deletion durablefunctionsmonitor.dotnetbackend/Common/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static string GetFullConnectionStringEnvVariableName(string connName)
{
if (IsDefaultConnectionStringName(connName))
{
return EnvVariableNames.AzureWebJobsStorage;
return DfmEndpoint.StorageConnStringEnvVarName;
}
else
{
Expand Down
26 changes: 26 additions & 0 deletions durablefunctionsmonitor.dotnetbackend/Common/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Newtonsoft.Json.Linq;

namespace DurableFunctionsMonitor.DotNetBackend
{
Expand Down Expand Up @@ -185,6 +186,22 @@ public static void Setup(DfmSettings settings = null, DfmExtensionPoints extensi
{
_customUserAgent = $"DurableFunctionsMonitor-Injected/{GetVersion()}";
}

// Checking host.json for a custom dedicated Storage account
string hostJsonFileName = Globals.GetHostJsonPath();
if (File.Exists(hostJsonFileName))
{
dynamic hostJson = JObject.Parse(File.ReadAllText(hostJsonFileName));

string connStringNameFromHostJson =
hostJson?.extensions?.durableTask?.storageProvider?.azureStorageConnectionStringName ??
hostJson?.extensions?.durableTask?.storageProvider?.connectionStringName;

if (!string.IsNullOrEmpty(connStringNameFromHostJson))
{
_storageConnStringEnvVarName = connStringNameFromHostJson;
}
}
}

internal static DfmSettings Settings
Expand Down Expand Up @@ -220,9 +237,18 @@ internal static string CustomUserAgent
get { return _customUserAgent; }
}

/// <summary>
/// Provides support for dedicated Storage accounts (different from AzureWebJobsStorage)
/// </summary>
internal static string StorageConnStringEnvVarName
{
get { return _storageConnStringEnvVarName; }
}

private static DfmSettings _settings = null;
private static DfmExtensionPoints _extensionPoints = new DfmExtensionPoints();
private static string _customUserAgent;
private static string _storageConnStringEnvVarName = EnvVariableNames.AzureWebJobsStorage;

/// <summary>
/// Checks whether we should do our internal initialization (Standalone mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ILogger log
if (!string.IsNullOrEmpty(dfmNonce))
{
// For VsCode loading Task Hubs directly and without validation
hubNames = await DfmEndpoint.ExtensionPoints.GetTaskHubNamesRoutine(EnvVariableNames.AzureWebJobsStorage);
hubNames = await DfmEndpoint.ExtensionPoints.GetTaskHubNamesRoutine(DfmEndpoint.StorageConnStringEnvVarName);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion durablefunctionsmonitor.dotnetisolated.core/Common/Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static async Task<HashSet<string>> GetAllowedTaskHubNamesAsync(DfmExtensi
try
{
var hubNames = new HashSet<string>(
await extensionPoints.GetTaskHubNamesRoutine(EnvVariableNames.AzureWebJobsStorage),
await extensionPoints.GetTaskHubNamesRoutine(Globals.StorageConnStringEnvVarName),
StringComparer.InvariantCultureIgnoreCase
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;

namespace DurableFunctionsMonitor.DotNetIsolated
{
Expand Down Expand Up @@ -52,6 +53,22 @@ public static IFunctionsWorkerApplicationBuilder UseDurableFunctionsMonitor(
builder.Services.AddSingleton(settings);
builder.Services.AddSingleton(extensionPoints);

// Checking host.json for a custom dedicated Storage account
string hostJsonFileName = Globals.GetHostJsonPath();
if (File.Exists(hostJsonFileName))
{
dynamic hostJson = JObject.Parse(File.ReadAllText(hostJsonFileName));

string connStringNameFromHostJson =
hostJson?.extensions?.durableTask?.storageProvider?.azureStorageConnectionStringName ??
hostJson?.extensions?.durableTask?.storageProvider?.connectionStringName;

if (!string.IsNullOrEmpty(connStringNameFromHostJson))
{
Globals.StorageConnStringEnvVarName = connStringNameFromHostJson;
}
}

// Adding middleware
builder.UseWhen
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ static class Globals

public const string DfmModeContextValue = "DfmModeContextValue";

/// <summary>
/// Provides support for dedicated Storage accounts (different from AzureWebJobsStorage)
/// </summary>
internal static string StorageConnStringEnvVarName = EnvVariableNames.AzureWebJobsStorage;

public static void SplitConnNameAndHubName(string connAndHubName, out string connName, out string hubName)
{
int pos = connAndHubName.LastIndexOf("-");
Expand Down Expand Up @@ -99,7 +104,7 @@ public static string GetFullConnectionStringEnvVariableName(string connName)
{
if (IsDefaultConnectionStringName(connName))
{
return EnvVariableNames.AzureWebJobsStorage;
return StorageConnStringEnvVarName;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<HttpResponseData> DfmGetTaskHubNamesFunction(
if (!string.IsNullOrEmpty(dfmNonce))
{
// For VsCode loading Task Hubs directly and without validation
hubNames = await this.ExtensionPoints.GetTaskHubNamesRoutine(EnvVariableNames.AzureWebJobsStorage);
hubNames = await this.ExtensionPoints.GetTaskHubNamesRoutine(Globals.StorageConnStringEnvVarName);
}
else
{
Expand Down

0 comments on commit 88455a5

Please sign in to comment.