Skip to content

Commit 1593e94

Browse files
authored
Merge pull request #10238 from NuGet/dev-feature-sdkmigration
RI `dev-feature-sdkmigration` to `dev`
2 parents 92f6412 + bddbd2d commit 1593e94

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/AccountDeleter/Configuration/AccountDeleteConfiguration.cs

Lines changed: 3 additions & 2 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.Collections.Generic;
@@ -27,6 +27,7 @@ public class AccountDeleteConfiguration
2727
/// </summary>
2828
public Dictionary<string, string> TemplateReplacements { get; set; }
2929

30+
3031
/// <summary>
3132
/// Storage container connection string where gallery content can be found
3233
/// </summary>
@@ -50,4 +51,4 @@ public SourceConfiguration GetSourceConfiguration(string source)
5051
throw new UnknownSourceException();
5152
}
5253
}
53-
}
54+
}

src/AccountDeleter/Job.cs

Lines changed: 9 additions & 9 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,6 +27,7 @@
2727
using NuGetGallery.Features;
2828
using NuGetGallery.Infrastructure.Authentication;
2929
using NuGetGallery.Security;
30+
using ConfigConstants = NuGet.Services.Configuration.Constants;
3031

3132
namespace NuGetGallery.AccountDeleter
3233
{
@@ -104,6 +105,13 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi
104105
services.AddScoped<ITelemetryClient, TelemetryClientWrapper>(
105106
sp => TelemetryClientWrapper.UseTelemetryConfiguration(ApplicationInsightsConfiguration.TelemetryConfiguration));
106107

108+
services.AddScoped<ICloudBlobClient>(serviceProvider =>
109+
{
110+
var options = serviceProvider.GetRequiredService<IOptionsSnapshot<AccountDeleteConfiguration>>();
111+
return CloudBlobClientWrapper.UsingMsi(options.Value.GalleryStorageConnectionString,
112+
configurationRoot[ConfigConstants.StorageManagedIdentityClientIdPropertyName]);
113+
});
114+
107115
ConfigureGalleryServices(services);
108116
}
109117

@@ -160,14 +168,6 @@ protected void ConfigureGalleryServices(IServiceCollection services)
160168
return new SupportRequestDbContext(connection);
161169
});
162170

163-
services.AddScoped<ICloudBlobClient>(sp =>
164-
{
165-
var options = sp.GetRequiredService<IOptionsSnapshot<AccountDeleteConfiguration>>();
166-
var optionsSnapshot = options.Value;
167-
168-
return new CloudBlobClientWrapper(optionsSnapshot.GalleryStorageConnectionString, readAccessGeoRedundant: true);
169-
});
170-
171171
services.AddScoped<ITelemetryService, TelemetryService>();
172172
services.AddScoped<ISecurityPolicyService, SecurityPolicyService>();
173173
services.AddScoped<IAppConfiguration, GalleryConfiguration>();

src/GitHubVulnerabilities2Db/Job.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Autofac;
9+
using Azure.Identity;
910
using Azure.Storage.Blobs;
1011
using GitHubVulnerabilities2Db.Configuration;
1112
using GitHubVulnerabilities2Db.Fakes;
@@ -31,13 +32,14 @@ namespace GitHubVulnerabilities2Db
3132
{
3233
public class Job : JsonConfigurationJob, IDisposable
3334
{
35+
private const string ManagedIdentityClientIdKey = "UserManagedIdentityClientId";
3436
private readonly HttpClient _client = new HttpClient();
3537

3638
public override async Task Run()
3739
{
3840
var collector = _serviceProvider.GetRequiredService<IAdvisoryCollector>();
39-
while (await collector.ProcessAsync(CancellationToken.None));
40-
41+
while (await collector.ProcessAsync(CancellationToken.None)) ;
42+
4143
}
4244

4345
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot)
@@ -59,7 +61,7 @@ protected override void ConfigureAutofacServices(ContainerBuilder containerBuild
5961

6062
ConfigureQueryServices(containerBuilder);
6163
ConfigureIngestionServices(containerBuilder);
62-
ConfigureCollectorServices(containerBuilder);
64+
ConfigureCollectorServices(containerBuilder, configurationRoot);
6365
}
6466

6567
protected void ConfigureIngestionServices(ContainerBuilder containerBuilder)
@@ -159,14 +161,14 @@ protected void ConfigureQueryServices(ContainerBuilder containerBuilder)
159161
.As<IAdvisoryQueryService>();
160162
}
161163

162-
protected void ConfigureCollectorServices(ContainerBuilder containerBuilder)
164+
protected void ConfigureCollectorServices(ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot)
163165
{
164166
containerBuilder
165167
.Register(ctx =>
166168
{
167169
var config = ctx.Resolve<GitHubVulnerabilities2DbConfiguration>();
168-
var connectionString = AzureStorageFactory.PrepareConnectionString(config.StorageConnectionString);
169-
return new BlobServiceClient(connectionString);
170+
var credential = new ManagedIdentityCredential(configurationRoot[ManagedIdentityClientIdKey]);
171+
return new BlobServiceClient(new Uri(config.StorageConnectionString), credential);
170172
})
171173
.As<BlobServiceClient>();
172174

0 commit comments

Comments
 (0)