-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathAzureCredentialHelper.cs
More file actions
28 lines (26 loc) · 1.17 KB
/
AzureCredentialHelper.cs
File metadata and controls
28 lines (26 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
namespace Microsoft.GS.DPSHost.Helpers
{
/// <summary>
/// The Azure Credential Helper class
/// </summary>
public static class AzureCredentialHelper
{
/// <summary>
/// Get the Azure Credentials based on the environment type
/// </summary>
/// <param name="clientId">The client Id in case of User assigned Managed identity</param>
/// <returns>The Credential Object</returns>
public static TokenCredential GetAzureCredential(string? clientId = null)
{
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production";
// CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
return string.Equals(env, "Development", StringComparison.OrdinalIgnoreCase)
? new DefaultAzureCredential() // CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development
: (clientId != null ? new ManagedIdentityCredential(clientId) : new ManagedIdentityCredential());
}
}
}