Skip to content

Commit 8213c64

Browse files
committed
added ManagedIdentityClientId as fallback for storage MSI
1 parent 27bdba1 commit 8213c64

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/NuGet.Jobs.Common/StorageAccountExtensions.cs

Lines changed: 9 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,11 +29,13 @@ 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];
36+
string managedIdentityClientId = string.IsNullOrEmpty(configuration[storageManagedIdentityClientIdPropertyName])
37+
? configuration[Constants.ManagedIdentityClientIdKey]
38+
: configuration[storageManagedIdentityClientIdPropertyName];
3939
bool useManagedIdentity = false;
4040
if (!string.IsNullOrWhiteSpace(useManagedIdentityStr))
4141
{

src/NuGet.Services.Configuration/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
namespace NuGet.Services.Configuration
@@ -15,5 +15,7 @@ public static class Constants
1515
public static string KeyVaultStoreNameKey = "KeyVault_StoreName";
1616
public static string KeyVaultStoreLocationKey = "KeyVault_StoreLocation";
1717
public static string KeyVaultSendX5c = "KeyVault_SendX5c";
18+
public static string StorageUseManagedIdentityPropertyName = "Storage_UseManagedIdentity";
19+
public static string StorageManagedIdentityClientIdPropertyName = "Storage_ManagedIdentityClientId";
1820
}
1921
}

0 commit comments

Comments
 (0)