Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.
Draft
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
30 changes: 24 additions & 6 deletions ServerlessLibraryAPI/CosmosLibraryStore.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Fluent;
using ServerlessLibrary.Models;

namespace ServerlessLibrary
Expand All @@ -28,7 +29,7 @@ async public Task<IList<LibraryItem>> GetAllItems()
return libraryItems.ToList();
}
}

/// <summary>
/// Cosmos db APIs
/// </summary>
Expand Down Expand Up @@ -98,10 +99,27 @@ public static void Initialize()
{
if (container == null)
{
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
ServerlessLibrarySettings.CosmosEndpoint,
ServerlessLibrarySettings.CosmosAuthkey);
CosmosClient client = cosmosClientBuilder.Build();
CosmosClient client;

// Check if we have connection strings configured
if (!string.IsNullOrEmpty(ServerlessLibrarySettings.CosmosEndpoint) &&
!string.IsNullOrEmpty(ServerlessLibrarySettings.CosmosAuthkey))
{
// Use connection string authentication if available
client = new CosmosClient(
ServerlessLibrarySettings.CosmosEndpoint,
ServerlessLibrarySettings.CosmosAuthkey);
}
else
{
// Use DefaultAzureCredential for authentication
string endpoint = ServerlessLibrarySettings.CosmosEndpoint;

// Create DefaultAzureCredential with basic options compatible with .NET Core 2.1
TokenCredential credential = new DefaultAzureCredential();

client = new CosmosClient(endpoint, credential);
}

DatabaseResponse databaseResponse = client.CreateDatabaseIfNotExistsAsync(DatabaseId).Result;
Database database = databaseResponse;
Expand Down
8 changes: 6 additions & 2 deletions ServerlessLibraryAPI/ServerlessLibraryAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
<ApplicationInsightsAnnotationResourceId>/subscriptions/7c1b7bab-00b2-4cb7-924e-205c4f411810/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/ServerlessLibrary</ApplicationInsightsAnnotationResourceId>
<UserSecretsId>235c2497-239d-47f0-8ea7-af2dd2416d95</UserSecretsId>
<RootNamespace>ServerlessLibrary</RootNamespace>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.5.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.26.1" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>

Expand Down