Skip to content

Commit fa32ae5

Browse files
committed
Minor improvements to dist app builder config
1 parent be2a895 commit fa32ae5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/Aspire.Hosting/DistributedApplicationBuilder.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,17 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
179179
// account for the path the AppHost is running from to disambiguate between different projects
180180
// with the same name as seen in https://github.com/dotnet/aspire/issues/5413. For publish scenarios,
181181
// we want to use a stable hash based only on the project name.
182-
var appHostShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(AppHostPath));
183-
var appHostNameShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(appHostName));
184-
var appHostSha = ExecutionContext.IsPublishMode ? Convert.ToHexString(appHostNameShaBytes) : Convert.ToHexString(appHostShaBytes);
182+
string appHostSha;
183+
if (ExecutionContext.IsPublishMode)
184+
{
185+
var appHostNameShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(appHostName));
186+
appHostSha = Convert.ToHexString(appHostNameShaBytes);
187+
}
188+
else
189+
{
190+
var appHostShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(AppHostPath));
191+
appHostSha = Convert.ToHexString(appHostShaBytes);
192+
}
185193
_innerBuilder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
186194
{
187195
["AppHost:Sha256"] = appHostSha
@@ -244,6 +252,16 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
244252
}
245253
);
246254
}
255+
else
256+
{
257+
// The dashboard is enabled but is unsecured. Set auth mode config setting to reflect this state.
258+
_innerBuilder.Configuration.AddInMemoryCollection(
259+
new Dictionary<string, string?>
260+
{
261+
["AppHost:ResourceService:AuthMode"] = nameof(ResourceServiceAuthMode.Unsecured)
262+
}
263+
);
264+
}
247265

248266
_innerBuilder.Services.AddSingleton<DashboardCommandExecutor>();
249267
_innerBuilder.Services.AddOptions<TransportOptions>().ValidateOnStart().PostConfigure(MapTransportOptionsFromCustomKeys);

0 commit comments

Comments
 (0)