Skip to content

Commit 9d10a11

Browse files
authored
Search MSI migration + .NET 9 TFM support (#10248)
* search MSI migration + .NET 9 TFMs * update tests
1 parent a4de2bd commit 9d10a11

5 files changed

Lines changed: 86 additions & 29 deletions

File tree

src/NuGet.Jobs.Common/StorageAccountExtensions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,39 @@ public static BlobServiceClient CreateBlobServiceClient(
224224
}
225225
}
226226

227+
public static BlobServiceClientFactory CreateBlobServiceClientFactory(
228+
StorageMsiConfiguration storageMsiConfiguration,
229+
string storageConnectionString)
230+
{
231+
if (storageMsiConfiguration.UseManagedIdentity)
232+
{
233+
Uri blobEndpointUri = AzureStorage.GetPrimaryServiceUri(storageConnectionString);
234+
235+
if (string.IsNullOrWhiteSpace(storageMsiConfiguration.ManagedIdentityClientId))
236+
{
237+
// 1. Using MSI with DefaultAzureCredential (local debugging)
238+
return new BlobServiceClientFactory(
239+
blobEndpointUri,
240+
new DefaultAzureCredential());
241+
}
242+
else
243+
{
244+
// 2. Using MSI with ClientId
245+
return new BlobServiceClientFactory(
246+
blobEndpointUri,
247+
new ManagedIdentityCredential(storageMsiConfiguration.ManagedIdentityClientId));
248+
}
249+
}
250+
else
251+
{
252+
// 3. Using SAS token
253+
// workaround for https://github.com/Azure/azure-sdk-for-net/issues/44373
254+
var connectionString = storageConnectionString.Replace("SharedAccessSignature=?", "SharedAccessSignature=");
255+
256+
return new BlobServiceClientFactory(connectionString);
257+
}
258+
}
259+
227260
private static TableServiceClient CreateTableServiceClientClient(
228261
StorageMsiConfiguration msiConfiguration,
229262
string tableStorageConnectionString)

src/NuGet.Services.AzureSearch/DependencyInjectionExtensions.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,30 @@ private static void RegisterAzureSearchStorageServices(ContainerBuilder containe
124124
.Register(c =>
125125
{
126126
var options = c.Resolve<IOptionsSnapshot<AzureSearchConfiguration>>();
127-
128-
// https://github.com/Azure/azure-sdk-for-net/issues/44373
129-
options.Value.StorageConnectionString = options.Value.StorageConnectionString.Replace("SharedAccessSignature=?", "SharedAccessSignature=");
130-
131-
return new BlobServiceClient(options.Value.StorageConnectionString);
127+
var storageMsiConfiguration = c.Resolve<IOptionsSnapshot<StorageMsiConfiguration>>();
128+
129+
return StorageAccountHelper.CreateBlobServiceClient(storageMsiConfiguration.Value, options.Value.StorageConnectionString);
132130
})
133131
.Keyed<BlobServiceClient>(key);
134132

133+
containerBuilder
134+
.Register(c =>
135+
{
136+
var options = c.Resolve<IOptionsSnapshot<AzureSearchConfiguration>>();
137+
var storageMsiConfiguration = c.Resolve<IOptionsSnapshot<StorageMsiConfiguration>>();
138+
139+
return StorageAccountHelper.CreateBlobServiceClientFactory(storageMsiConfiguration.Value, options.Value.StorageConnectionString);
140+
})
141+
.Keyed<BlobServiceClientFactory>(key);
142+
135143
#if NETFRAMEWORK
136144
containerBuilder
137145
.Register<IStorageFactory>(c =>
138146
{
139147
var options = c.Resolve<IOptionsSnapshot<AzureSearchConfiguration>>();
140-
BlobServiceClientFactory blobServiceClient = c.ResolveKeyed<BlobServiceClientFactory>(key);
148+
BlobServiceClientFactory blobServiceClientFactory = c.ResolveKeyed<BlobServiceClientFactory>(key);
141149
return new Metadata.Catalog.Persistence.AzureStorageFactory(
142-
blobServiceClient,
150+
blobServiceClientFactory,
143151
options.Value.StorageContainer,
144152
maxExecutionTime: Metadata.Catalog.Persistence.AzureStorage.DefaultMaxExecutionTime,
145153
serverTimeout: Metadata.Catalog.Persistence.AzureStorage.DefaultServerTimeout,

src/NuGet.Services.SearchService.Core/Startup.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.Extensions.Configuration;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.PackageManagement.Search.Web;
16+
using NuGet.Jobs;
1617
using NuGet.Services.AzureSearch;
1718
using NuGet.Services.AzureSearch.SearchService;
1819
using NuGet.Services.Logging;
@@ -36,6 +37,8 @@ public void ConfigureServices(IServiceCollection services)
3637
{
3738
var refreshableConfig = StartupHelper.GetSecretInjectedConfiguration(Configuration);
3839
Configuration = refreshableConfig.Root;
40+
41+
services.ConfigureStorageMsi(Configuration);
3942
services.AddSingleton(refreshableConfig.SecretReaderFactory);
4043

4144
services

src/NuGetGallery.Core/Frameworks/SupportedFrameworks.cs

Lines changed: 32 additions & 15 deletions
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
using System;
@@ -27,35 +27,51 @@ public static class SupportedFrameworks
2727
public static readonly NuGetFramework Net3 = new NuGetFramework(FrameworkIdentifiers.Net, new Version(3, 0, 0, 0));
2828
public static readonly NuGetFramework Net48 = new NuGetFramework(FrameworkIdentifiers.Net, new Version(4, 8, 0, 0));
2929
public static readonly NuGetFramework Net481 = new NuGetFramework(FrameworkIdentifiers.Net, new Version(4, 8, 1, 0));
30+
public static readonly NuGetFramework NetCore = new NuGetFramework(FrameworkIdentifiers.NetCore, EmptyVersion);
31+
public static readonly NuGetFramework NetMf = new NuGetFramework(FrameworkIdentifiers.NetMicro, EmptyVersion);
32+
public static readonly NuGetFramework UAP = new NuGetFramework(FrameworkIdentifiers.UAP, EmptyVersion);
33+
public static readonly NuGetFramework WP = new NuGetFramework(FrameworkIdentifiers.WindowsPhone, EmptyVersion);
34+
public static readonly NuGetFramework XamarinIOs = new NuGetFramework(FrameworkIdentifiers.XamarinIOs, EmptyVersion);
35+
public static readonly NuGetFramework XamarinMac = new NuGetFramework(FrameworkIdentifiers.XamarinMac, EmptyVersion);
36+
public static readonly NuGetFramework XamarinTvOs = new NuGetFramework(FrameworkIdentifiers.XamarinTVOS, EmptyVersion);
37+
public static readonly NuGetFramework XamarinWatchOs = new NuGetFramework(FrameworkIdentifiers.XamarinWatchOS, EmptyVersion);
38+
3039
public static readonly NuGetFramework Net50Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version5, "windows", EmptyVersion);
40+
3141
public static readonly NuGetFramework Net60Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "android", EmptyVersion);
3242
public static readonly NuGetFramework Net60Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "ios", EmptyVersion);
33-
public static readonly NuGetFramework Net60MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "macos", EmptyVersion);
3443
public static readonly NuGetFramework Net60MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "maccatalyst", EmptyVersion);
44+
public static readonly NuGetFramework Net60MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "macos", EmptyVersion);
3545
public static readonly NuGetFramework Net60TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "tvos", EmptyVersion);
3646
public static readonly NuGetFramework Net60Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version6, "windows", EmptyVersion);
47+
3748
public static readonly NuGetFramework Net70Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "android", EmptyVersion);
3849
public static readonly NuGetFramework Net70Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "ios", EmptyVersion);
39-
public static readonly NuGetFramework Net70MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "macos", EmptyVersion);
4050
public static readonly NuGetFramework Net70MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "maccatalyst", EmptyVersion);
51+
public static readonly NuGetFramework Net70MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "macos", EmptyVersion);
4152
public static readonly NuGetFramework Net70TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "tvos", EmptyVersion);
4253
public static readonly NuGetFramework Net70Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "windows", EmptyVersion);
54+
4355
public static readonly NuGetFramework Net80Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "android", EmptyVersion);
4456
public static readonly NuGetFramework Net80Browser = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "browser", EmptyVersion);
4557
public static readonly NuGetFramework Net80Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "ios", EmptyVersion);
46-
public static readonly NuGetFramework Net80MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "macos", EmptyVersion);
4758
public static readonly NuGetFramework Net80MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "maccatalyst", EmptyVersion);
59+
public static readonly NuGetFramework Net80MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "macos", EmptyVersion);
4860
public static readonly NuGetFramework Net80TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "tvos", EmptyVersion);
4961
public static readonly NuGetFramework Net80Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "windows", EmptyVersion);
50-
public static readonly NuGetFramework NetCore = new NuGetFramework(FrameworkIdentifiers.NetCore, EmptyVersion);
51-
public static readonly NuGetFramework NetMf = new NuGetFramework(FrameworkIdentifiers.NetMicro, EmptyVersion);
52-
public static readonly NuGetFramework UAP = new NuGetFramework(FrameworkIdentifiers.UAP, EmptyVersion);
53-
public static readonly NuGetFramework WP = new NuGetFramework(FrameworkIdentifiers.WindowsPhone, EmptyVersion);
54-
public static readonly NuGetFramework XamarinIOs = new NuGetFramework(FrameworkIdentifiers.XamarinIOs, EmptyVersion);
55-
public static readonly NuGetFramework XamarinMac = new NuGetFramework(FrameworkIdentifiers.XamarinMac, EmptyVersion);
56-
public static readonly NuGetFramework XamarinTvOs = new NuGetFramework(FrameworkIdentifiers.XamarinTVOS, EmptyVersion);
57-
public static readonly NuGetFramework XamarinWatchOs = new NuGetFramework(FrameworkIdentifiers.XamarinWatchOS, EmptyVersion);
58-
62+
63+
// These 2 constants can be removed once they have been added to NuGet.Frameworks.FrameworkConstants - https://github.com/NuGet/Engineering/issues/5676
64+
public static readonly Version Version9 = new Version(9, 0, 0, 0);
65+
public static readonly NuGetFramework Net90 = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9);
66+
67+
public static readonly NuGetFramework Net90Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "android", EmptyVersion);
68+
public static readonly NuGetFramework Net90Browser = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "browser", EmptyVersion);
69+
public static readonly NuGetFramework Net90Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "ios", EmptyVersion);
70+
public static readonly NuGetFramework Net90MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "maccatalyst", EmptyVersion);
71+
public static readonly NuGetFramework Net90MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "macos", EmptyVersion);
72+
public static readonly NuGetFramework Net90TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "tvos", EmptyVersion);
73+
public static readonly NuGetFramework Net90Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version9, "windows", EmptyVersion);
74+
5975
public static readonly IReadOnlyList<NuGetFramework> AllSupportedNuGetFrameworks;
6076

6177
static SupportedFrameworks()
@@ -68,7 +84,8 @@ static SupportedFrameworks()
6884
Net50, Net50Windows,
6985
Net60, Net60Android, Net60Ios, Net60MacCatalyst, Net60MacOs, Net60TvOs, Net60Windows,
7086
Net70, Net70Android, Net70Ios, Net70MacCatalyst, Net70MacOs, Net70TvOs, Net70Windows,
71-
Net80, Net80Android, Net80Ios, Net80MacCatalyst, Net80MacOs, Net80TvOs, Net80Windows, Net80Browser,
87+
Net80, Net80Android, Net80Browser, Net80Ios, Net80MacCatalyst, Net80MacOs, Net80TvOs, Net80Windows,
88+
Net90, Net90Android, Net90Browser, Net90Ios, Net90MacCatalyst, Net90MacOs, Net90TvOs, Net90Windows,
7289
NetCore, NetCore45, NetCore451,
7390
NetCoreApp10, NetCoreApp11, NetCoreApp20, NetCoreApp21, NetCoreApp22, NetCoreApp30, NetCoreApp31,
7491
NetMf,
@@ -137,4 +154,4 @@ public static class TfmFilters {
137154
};
138155
}
139156
}
140-
}
157+
}

tests/NuGetGallery.Core.Facts/Frameworks/FrameworkCompatibilityServiceFacts.cs

Lines changed: 3 additions & 7 deletions
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
using System;
@@ -155,9 +155,7 @@ public void PlatformVersionsShouldContainAllSpecifiedFrameworks(string platformV
155155
var compatibleFrameworks = FrameworkCompatibilityService.GetCompatibleFrameworks(new HashSet<NuGetFramework>() { packageFramework });
156156

157157
// Assert
158-
Assert.Equal(expectedFrameworks.Length, compatibleFrameworks.Count);
159-
160-
var containsAllCompatibleFrameworks = compatibleFrameworks.All(cf => projectFrameworks.Contains(cf));
158+
var containsAllCompatibleFrameworks = projectFrameworks.All(cf => compatibleFrameworks.Contains(cf));
161159
Assert.True(containsAllCompatibleFrameworks);
162160
}
163161

@@ -189,9 +187,7 @@ public void MultiplePlatformVersionCasesShouldContainAllSpecifiedFrameworks(stri
189187
var compatibleFrameworks = FrameworkCompatibilityService.GetCompatibleFrameworks(packageFrameworks);
190188

191189
// Assert
192-
Assert.Equal(expectedFrameworks.Length, compatibleFrameworks.Count);
193-
194-
var containsAllCompatibleFrameworks = compatibleFrameworks.All(cf => expectedComputedFrameworks.Contains(cf));
190+
var containsAllCompatibleFrameworks = expectedComputedFrameworks.All(cf => compatibleFrameworks.Contains(cf));
195191
Assert.True(containsAllCompatibleFrameworks);
196192
}
197193
}

0 commit comments

Comments
 (0)