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 interface for cosmosdb MI #4712

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Microsoft.Health.Fhir.Azure.ExportDestinationClient
{
public class AzureAccessTokenProvider : IAccessTokenProvider
public class AzureAccessTokenProvider : IAccessTokenProvider, ICosmosDBAccessTokenProvider
{
private readonly DefaultAzureCredential _azureServiceTokenProvider;
private readonly ILogger<AzureAccessTokenProvider> _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,16 @@ public static IFhirServerBuilder AddAzureIntegrationDataStoreClient(this IFhirSe

return fhirServerBuilder;
}

public static IFhirServerBuilder AddCosmosdbMI(this IFhirServerBuilder fhirServerBuilder)
{
EnsureArg.IsNotNull(fhirServerBuilder, nameof(fhirServerBuilder));

fhirServerBuilder.Services.Add<AzureAccessTokenProvider>()
.Transient()
.AsService<ICosmosDBAccessTokenProvider>();

return fhirServerBuilder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Health.Fhir.Core.Features.Operations
{
public interface ICosmosDBAccessTokenProvider
rbans96 marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Gets the access token for the resource.
/// </summary>
/// <param name="resourceUri">Uri pointing to the resource for which we need an access token.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>Access token.</returns>
/// <exception cref="AccessTokenProviderException">Thrown when unable to get access token.</exception>
Task<string> GetAccessTokenForResourceAsync(Uri resourceUri, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class CosmosDbCollectionPhysicalPartitionInfo : IRequireInitializationO
private readonly CosmosDataStoreConfiguration _dataStoreConfiguration;
private readonly CosmosCollectionConfiguration _collectionConfiguration;
private readonly IHttpClientFactory _httpClientFactory;
private readonly IAccessTokenProvider _accessTokenProvider;
private readonly ICosmosDBAccessTokenProvider _accessTokenProvider;
private readonly ILogger<CosmosDbCollectionPhysicalPartitionInfo> _logger;
private readonly CancellationTokenSource _backgroundLoopCancellationTokenSource = new();
private Task _backgroundLoopTask;
Expand All @@ -41,7 +41,7 @@ public CosmosDbCollectionPhysicalPartitionInfo(
CosmosDataStoreConfiguration dataStoreConfiguration,
IOptionsMonitor<CosmosCollectionConfiguration> collectionConfiguration,
IHttpClientFactory httpClientFactory,
IAccessTokenProvider accessTokenProvider,
ICosmosDBAccessTokenProvider accessTokenProvider,
ILogger<CosmosDbCollectionPhysicalPartitionInfo> logger)
{
EnsureArg.IsNotNull(dataStoreConfiguration, nameof(dataStoreConfiguration));
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Health.Fhir.Shared.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private void AddDataStore(IServiceCollection services, IFhirServerBuilder fhirSe
if (runtimeConfiguration is AzureApiForFhirRuntimeConfiguration)
{
fhirServerBuilder.AddCosmosDb();
fhirServerBuilder.AddCosmosdbMI();
rbans96 marked this conversation as resolved.
Show resolved Hide resolved
}
else if (runtimeConfiguration is AzureHealthDataServicesRuntimeConfiguration)
{
Expand Down