Skip to content

Commit ec1d943

Browse files
authored
Add fall back option if Storage MSI isn't specified (#10156)
1 parent a90cbe6 commit ec1d943

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/NuGet.Jobs.Common/StorageAccountExtensions.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
99
using Microsoft.Extensions.Options;
10+
using NuGet.Services.Configuration;
1011
using NuGetGallery;
1112

1213
namespace NuGet.Jobs
1314
{
1415
public static class StorageAccountHelper
1516
{
16-
private const string StorageUseManagedIdentityPropertyName = "Storage_UseManagedIdentity";
17-
private const string StorageManagedIdentityClientIdPropertyName = "Storage_ManagedIdentityClientId";
18-
1917
public static IServiceCollection ConfigureStorageMsi(
2018
this IServiceCollection serviceCollection,
2119
IConfiguration configuration,
22-
string useManageIdentityPropertyName = null,
23-
string managedIdentityClientIdPropertyName = null)
20+
string storageUseManagedIdentityPropertyName = null,
21+
string storageManagedIdentityClientIdPropertyName = null)
2422
{
2523
if (serviceCollection == null)
2624
{
@@ -31,12 +29,16 @@ public static IServiceCollection ConfigureStorageMsi(
3129
throw new ArgumentNullException(nameof(configuration));
3230
}
3331

34-
useManageIdentityPropertyName ??= StorageUseManagedIdentityPropertyName;
35-
managedIdentityClientIdPropertyName ??= StorageManagedIdentityClientIdPropertyName;
32+
storageUseManagedIdentityPropertyName ??= Constants.StorageUseManagedIdentityPropertyName;
33+
storageManagedIdentityClientIdPropertyName ??= Constants.StorageManagedIdentityClientIdPropertyName;
3634

37-
string useManagedIdentityStr = configuration[useManageIdentityPropertyName];
38-
string managedIdentityClientId = configuration[managedIdentityClientIdPropertyName];
35+
string useManagedIdentityStr = configuration[storageUseManagedIdentityPropertyName];
3936
bool useManagedIdentity = false;
37+
38+
string managedIdentityClientId = string.IsNullOrWhiteSpace(configuration[storageManagedIdentityClientIdPropertyName])
39+
? configuration[Constants.ManagedIdentityClientIdKey]
40+
: configuration[storageManagedIdentityClientIdPropertyName];
41+
4042
if (!string.IsNullOrWhiteSpace(useManagedIdentityStr))
4143
{
4244
useManagedIdentity = bool.Parse(useManagedIdentityStr);

0 commit comments

Comments
 (0)