Skip to content

Commit ae6fec2

Browse files
committed
Handled PR feedback and added support to log dashboard Uri
1 parent 26793ea commit ae6fec2

File tree

22 files changed

+44
-49
lines changed

22 files changed

+44
-49
lines changed

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,12 @@ public static IResourceBuilder<AzureAppServiceEnvironmentResource> AddAzureAppSe
134134
Value = identity.ClientId
135135
});
136136

137-
infra.Add(new ProvisioningOutput("AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_NAME", typeof(string))
138-
{
139-
Value = identity.Name
140-
});
141-
142137
if (resource.EnableDashboard)
143138
{
144139
// Add aspire dashboard website
145140
var website = AzureAppServiceEnvironmentUtility.AddDashboard(infra, identity, plan.Id);
146141

147-
infra.Add(new ProvisioningOutput("DASHBOARD_URI", typeof(string))
142+
infra.Add(new ProvisioningOutput("AZURE_APP_SERVICE_DASHBOARD_URI", typeof(string))
148143
{
149144
Value = BicepFunction.Interpolate($"https://{AzureAppServiceEnvironmentUtility.DashboardHostName}.azurewebsites.net")
150145
});

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class AzureAppServiceEnvironmentResource(string name, Action<AzureResourc
4141
/// <summary>
4242
/// Gets the URI of the App Service Environment dashboard.
4343
/// </summary>
44-
public BicepOutputReference DashboardUriReference => new("DASHBOARD_URI", this);
44+
public BicepOutputReference DashboardUriReference => new("AZURE_APP_SERVICE_DASHBOARD_URI", this);
4545

4646
ReferenceExpression IAzureContainerRegistry.ManagedIdentityId =>
4747
ReferenceExpression.Create($"{ContainerRegistryManagedIdentityId}");

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentUtility.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Aspire.Hosting.Azure.AppService;
1313

1414
internal static class AzureAppServiceEnvironmentUtility
1515
{
16-
internal static readonly string ResourceName = "dashboard";
16+
internal const string ResourceName = "dashboard";
1717

1818
public static BicepValue<string> DashboardHostName => BicepFunction.Take(
1919
BicepFunction.Interpolate($"{BicepFunction.ToLower(ResourceName)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}"), 60);
@@ -22,13 +22,13 @@ public static WebSite AddDashboard(AzureResourceInfrastructure infra,
2222
UserAssignedIdentity otelIdentity,
2323
BicepValue<ResourceIdentifier> appServicePlanId)
2424
{
25-
var acrClientIdParameter = otelIdentity.ClientId;
25+
// This ACR identity is used by the dashboard to authorize the telemetry data
26+
// coming from the dotnet web apps. This identity is being assigned to every web app
27+
// in the aspire project and can be safely reused for authorization in the dashboard.
28+
var otelClientId = otelIdentity.ClientId;
2629
var prefix = infra.AspireResource.Name;
2730
var contributorIdentity = new UserAssignedIdentity(Infrastructure.NormalizeBicepIdentifier($"{prefix}-contributor-mi"));
28-
29-
var contributorMidParameter = contributorIdentity.Id;
30-
var contributorClientIdParameter = contributorIdentity.ClientId;
31-
31+
3232
infra.Add(contributorIdentity);
3333

3434
// Add Website Contributor role assignment
@@ -72,7 +72,7 @@ public static WebSite AddDashboard(AzureResourceInfrastructure infra,
7272
SiteConfig = new SiteConfigProperties()
7373
{
7474
LinuxFxVersion = "ASPIREDASHBOARD|1.0",
75-
AcrUserManagedIdentityId = acrClientIdParameter,
75+
AcrUserManagedIdentityId = otelClientId,
7676
UseManagedIdentityCreds = true,
7777
IsHttp20Enabled = true,
7878
Http20ProxyFlag = 1,
@@ -89,7 +89,7 @@ public static WebSite AddDashboard(AzureResourceInfrastructure infra,
8989
}
9090
};
9191

92-
var contributorMid = BicepFunction.Interpolate($"{contributorMidParameter}").Compile().ToString();
92+
var contributorMid = BicepFunction.Interpolate($"{contributorIdentity.Id}").Compile().ToString();
9393
webSite.Identity.UserAssignedIdentities[contributorMid] = new UserAssignedIdentityDetails();
9494

9595
// Security is handled by app service platform
@@ -103,8 +103,8 @@ public static WebSite AddDashboard(AzureResourceInfrastructure infra,
103103
// Enable SCM preloading to ensure dashboard is always available
104104
webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITE_START_SCM_WITH_PRELOAD", Value = "true" });
105105
// Appsettings related to managed identity for auth
106-
webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "AZURE_CLIENT_ID", Value = contributorClientIdParameter });
107-
webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ALLOWED_MANAGED_IDENTITIES", Value = acrClientIdParameter });
106+
webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "AZURE_CLIENT_ID", Value = contributorIdentity.ClientId });
107+
webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ALLOWED_MANAGED_IDENTITIES", Value = otelClientId });
108108
infra.Add(webSite);
109109

110110
return webSite;

src/Aspire.Hosting.Azure/AzureDeployingContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ private static string TryGetComputeResourceEndpoint(IResource computeResource, I
482482
{
483483
return $"https://aspire-dashboard.ext.{domainValue}";
484484
}
485+
// If the resource is a compute environment (app service), we can use its properties
486+
// to get the dashboard URL.
487+
if (environmentBicepResource.Outputs.TryGetValue($"AZURE_APP_SERVICE_DASHBOARD_URI", out var dashboardUri))
488+
{
489+
return (string?)dashboardUri;
490+
}
485491
}
486492
}
487493

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddAppServiceEnvironmentWithoutDashboardAddsEnvironmentResource.verified.bicep

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,3 @@ output AZURE_CONTAINER_REGISTRY_ENDPOINT string = env_acr.properties.loginServer
5555
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID string = env_mi.id
5656

5757
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_CLIENT_ID string = env_mi.properties.clientId
58-
59-
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_NAME string = env_mi.name

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddContainerAppEnvironmentAddsDeploymentTargetWithContainerAppToProjectResources.verified.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ param api_containerimage string
1313

1414
param api_containerport string
1515

16-
param env_outputs_dashboard_uri string
16+
param env_outputs_azure_app_service_dashboard_uri string
1717

1818
resource mainContainer 'Microsoft.Web/sites/sitecontainers@2024-11-01' = {
1919
name: 'main'
@@ -75,7 +75,7 @@ resource webapp 'Microsoft.Web/sites@2024-11-01' = {
7575
}
7676
{
7777
name: 'OTEL_COLLECTOR_URL'
78-
value: env_outputs_dashboard_uri
78+
value: env_outputs_azure_app_service_dashboard_uri
7979
}
8080
{
8181
name: 'OTEL_CLIENT_ID'

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddContainerAppEnvironmentAddsDeploymentTargetWithContainerAppToProjectResources.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"env_outputs_azure_container_registry_managed_identity_client_id": "{env.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_CLIENT_ID}",
99
"api_containerimage": "{api.containerImage}",
1010
"api_containerport": "{api.containerPort}",
11-
"env_outputs_dashboard_uri": "{env.outputs.DASHBOARD_URI}"
11+
"env_outputs_azure_app_service_dashboard_uri": "{env.outputs.AZURE_APP_SERVICE_DASHBOARD_URI}"
1212
}
1313
}

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddContainerAppEnvironmentAddsEnvironmentResource.verified.bicep

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,4 @@ output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID string = env_mi.id
141141

142142
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_CLIENT_ID string = env_mi.properties.clientId
143143

144-
output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_NAME string = env_mi.name
145-
146-
output DASHBOARD_URI string = 'https://${take('${toLower('dashboard')}-${uniqueString(resourceGroup().id)}', 60)}.azurewebsites.net'
144+
output AZURE_APP_SERVICE_DASHBOARD_URI string = 'https://${take('${toLower('dashboard')}-${uniqueString(resourceGroup().id)}', 60)}.azurewebsites.net'

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddDockerfileWithAppServiceInfrastructureAddsDeploymentTargetWithAppServiceToContainerResources.verified.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ param env_outputs_azure_container_registry_managed_identity_client_id string
1111

1212
param api_containerimage string
1313

14-
param env_outputs_dashboard_uri string
14+
param env_outputs_azure_app_service_dashboard_uri string
1515

1616
resource mainContainer 'Microsoft.Web/sites/sitecontainers@2024-11-01' = {
1717
name: 'main'
@@ -57,7 +57,7 @@ resource webapp 'Microsoft.Web/sites@2024-11-01' = {
5757
}
5858
{
5959
name: 'OTEL_COLLECTOR_URL'
60-
value: env_outputs_dashboard_uri
60+
value: env_outputs_azure_app_service_dashboard_uri
6161
}
6262
{
6363
name: 'OTEL_CLIENT_ID'

tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureAppServiceTests.AddDockerfileWithAppServiceInfrastructureAddsDeploymentTargetWithAppServiceToContainerResources.verified.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"env_outputs_azure_container_registry_managed_identity_id": "{env.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID}",
88
"env_outputs_azure_container_registry_managed_identity_client_id": "{env.outputs.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_CLIENT_ID}",
99
"api_containerimage": "{api.containerImage}",
10-
"env_outputs_dashboard_uri": "{env.outputs.DASHBOARD_URI}"
10+
"env_outputs_azure_app_service_dashboard_uri": "{env.outputs.AZURE_APP_SERVICE_DASHBOARD_URI}"
1111
}
1212
}

0 commit comments

Comments
 (0)