Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for managed identity in Azure Cosmos DB hosting component #7092

Merged
merged 22 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
sebastienros committed Jan 13, 2025
commit 9107115090099146d50c7632fe4a0b7d3337cdc9
3 changes: 1 addition & 2 deletions playground/CosmosEndToEnd/CosmosEndToEnd.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

var db = builder.AddAzureCosmosDB("cosmos")
.WithDatabase("db", database => database.Containers.Add(new("entries", "/Id")))
.RunAsEmulator()
;
.RunAsEmulator();

builder.AddProject<Projects.CosmosEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context

var databases = _databasesFactory();

if (databases.Length != 0)
foreach (var database in databases)
{
foreach (var database in databases)
{
var db = (await cosmosClient.CreateDatabaseIfNotExistsAsync(database.Name, cancellationToken: cancellationToken).ConfigureAwait(false)).Database;
var db = (await cosmosClient.CreateDatabaseIfNotExistsAsync(database.Name, cancellationToken: cancellationToken).ConfigureAwait(false)).Database;

foreach (var container in database.Containers)
{
await db.CreateContainerIfNotExistsAsync(container.Name, container.PartitionKeyPath, cancellationToken: cancellationToken).ConfigureAwait(false);
}
foreach (var container in database.Containers)
{
await db.CreateContainerIfNotExistsAsync(container.Name, container.PartitionKeyPath, cancellationToken: cancellationToken).ConfigureAwait(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Hosting.Azure.CosmosDB/CosmosDBDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CosmosDBDatabase(string name)
}

/// <summary>
/// The topic name.
/// The database name.
/// </summary>
public string Name { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Linq;
using Microsoft.Azure.Cosmos.Query.Core.Metrics;
using Microsoft.Azure.Cosmos.Query.Core.QueryAdvisor;

Check failure on line 12 in tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs

View check run for this annotation

Azure Pipelines / dotnet.aspire (Build Linux)

tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs#L12

tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs(12,41): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'QueryAdvisor' does not exist in the namespace 'Microsoft.Azure.Cosmos.Query.Core' (are you missing an assembly reference?)

Check failure on line 12 in tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs

View check run for this annotation

Azure Pipelines / dotnet.aspire (Build Linux_helix_tests)

tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs#L12

tests/Aspire.Hosting.Azure.Tests/AzureCosmosDBEmulatorFunctionalTests.cs(12,41): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'QueryAdvisor' does not exist in the namespace 'Microsoft.Azure.Cosmos.Query.Core' (are you missing an assembly reference?)
using Microsoft.Azure.Cosmos.Resource.CosmosExceptions;
using Microsoft.Azure.Cosmos.Tracing;
using Microsoft.Azure.Documents;

using Aspire.Components.Common.Tests;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Microsoft.Azure.Cosmos;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -270,8 +282,6 @@

await app.StartAsync(cts.Token);

await app.WaitForTextAsync("Started").WaitAsync(cts.Token);

var rns = app.Services.GetRequiredService<ResourceNotificationService>();
await rns.WaitForResourceHealthyAsync(cosmos.Resource.Name, cts.Token);

Expand All @@ -283,15 +293,21 @@

await host.StartAsync(cts.Token);

// This needs to be outside the pipeline because when the CosmosClient is disposed,
// there is an exception in the pipeline
using var cosmosClient = host.Services.GetRequiredService<CosmosClient>();

var database = cosmosClient.GetDatabase(databaseName);
var result1 = await database.ReadAsync(cancellationToken: cts.Token);

var container = database.GetContainer(containerName);
var result2 = await container.ReadContainerAsync(cancellationToken: cts.Token);

Assert.True(IsSuccess(result1.StatusCode));
Assert.True(IsSuccess(result2.StatusCode));

Assert.NotNull(database);
Assert.NotNull(container);
static bool IsSuccess(HttpStatusCode httpStatusCode)
{
return ((int)httpStatusCode >= 200) && ((int)httpStatusCode <= 299);
}
}
}

Expand Down
Loading