Skip to content

Commit 0a79342

Browse files
committed
Minor improvements to dist app builder config
1 parent c3cdb10 commit 0a79342

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
@@ -178,9 +178,17 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
178178
// account for the path the AppHost is running from to disambiguate between different projects
179179
// with the same name as seen in https://github.com/dotnet/aspire/issues/5413. For publish scenarios,
180180
// we want to use a stable hash based only on the project name.
181-
var appHostShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(AppHostPath));
182-
var appHostNameShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(appHostName));
183-
var appHostSha = ExecutionContext.IsPublishMode ? Convert.ToHexString(appHostNameShaBytes) : Convert.ToHexString(appHostShaBytes);
181+
string appHostSha;
182+
if (ExecutionContext.IsPublishMode)
183+
{
184+
var appHostNameShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(appHostName));
185+
appHostSha = Convert.ToHexString(appHostNameShaBytes);
186+
}
187+
else
188+
{
189+
var appHostShaBytes = SHA256.HashData(Encoding.UTF8.GetBytes(AppHostPath));
190+
appHostSha = Convert.ToHexString(appHostShaBytes);
191+
}
184192
_innerBuilder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
185193
{
186194
["AppHost:Sha256"] = appHostSha
@@ -243,6 +251,16 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
243251
}
244252
);
245253
}
254+
else
255+
{
256+
// The dashboard is enabled but is unsecured. Set auth mode config setting to reflect this state.
257+
_innerBuilder.Configuration.AddInMemoryCollection(
258+
new Dictionary<string, string?>
259+
{
260+
["AppHost:ResourceService:AuthMode"] = nameof(ResourceServiceAuthMode.Unsecured)
261+
}
262+
);
263+
}
246264

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

0 commit comments

Comments
 (0)