File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
App/backend-api/Microsoft.GS.DPS.Host Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 11using Azure . Identity ;
22using Microsoft . Extensions . Azure ;
33using Microsoft . GS . DPSHost . AppConfiguration ;
4+ using Microsoft . GS . DPSHost . Helpers ;
45
56namespace Microsoft . GS . DPSHost . AppConfiguration
67{
@@ -16,7 +17,7 @@ public static void Config(IHostApplicationBuilder builder)
1617 //Read AppConfiguration with managed Identity
1718 builder . Configuration . AddAzureAppConfiguration ( options =>
1819 {
19- options . Connect ( new Uri ( builder . Configuration [ "ConnectionStrings:AppConfig" ] ) , new DefaultAzureCredential ( ) ) ;
20+ options . Connect ( new Uri ( builder . Configuration [ "ConnectionStrings:AppConfig" ] ) , AzureCredentialHelper . GetAzureCredential ( ) ) ;
2021 } ) ;
2122
2223 //Read ServiceConfiguration
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Azure . Core ;
4+ using Azure . Identity ;
5+
6+ namespace Microsoft . GS . DPSHost . Helpers
7+ {
8+ /// <summary>
9+ /// The Azure Credential Helper class
10+ /// </summary>
11+ public static class AzureCredentialHelper
12+ {
13+ /// <summary>
14+ /// Get the Azure Credentials based on the environment type
15+ /// </summary>
16+ /// <param name="clientId">The client Id in case of User assigned Managed identity</param>
17+ /// <returns>The Credential Object</returns>
18+ public static TokenCredential GetAzureCredential ( string ? clientId = null )
19+ {
20+ var env = Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ?? "Production" ;
21+
22+ if ( string . Equals ( env , "Development" , StringComparison . OrdinalIgnoreCase ) )
23+ {
24+ return new DefaultAzureCredential ( ) ; // CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
25+ }
26+ else
27+ {
28+ return clientId != null
29+ ? new ManagedIdentityCredential ( clientId )
30+ : new ManagedIdentityCredential ( ) ;
31+ }
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments