|
10 | 10 | using System.Threading.Tasks; |
11 | 11 | using Autofac; |
12 | 12 | using Autofac.Core; |
13 | | -using Azure.Identity; |
14 | 13 | using Azure.Storage.Blobs; |
15 | 14 | using Microsoft.ApplicationInsights; |
16 | 15 | using Microsoft.Extensions.Configuration; |
@@ -181,6 +180,13 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi |
181 | 180 | services.AddTransient<IBrokeredMessageSerializer<PackageValidationMessageData>, PackageValidationMessageDataSerializationAdapter>(); |
182 | 181 | services.AddTransient<ICriteriaEvaluator<Package>, PackageCriteriaEvaluator>(); |
183 | 182 | services.AddTransient<IProcessSignatureEnqueuer, ProcessSignatureEnqueuer>(); |
| 183 | + services.AddTransient<ICloudBlobClient>(c => |
| 184 | + { |
| 185 | + var configurationAccessor = c.GetRequiredService<IOptionsSnapshot<ValidationConfiguration>>(); |
| 186 | + return new CloudBlobClientWrapper( |
| 187 | + configurationAccessor.Value.ValidationStorageConnectionString, |
| 188 | + readAccessGeoRedundant: false); |
| 189 | + }); |
184 | 190 | services.AddTransient<ICloudBlobContainerInformationProvider, GalleryCloudBlobContainerInformationProvider>(); |
185 | 191 | services.AddTransient<ICoreFileStorageService, CloudBlobCoreFileStorageService>(); |
186 | 192 | services.AddTransient<IFileDownloader, FileDownloader>(); |
@@ -230,10 +236,6 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi |
230 | 236 |
|
231 | 237 | protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot) |
232 | 238 | { |
233 | | - containerBuilder |
234 | | - .RegisterStorageAccount<ValidationConfiguration>(c => c.ValidationStorageConnectionString) |
235 | | - .As<ICloudBlobClient>(); |
236 | | - |
237 | 239 | containerBuilder |
238 | 240 | .Register(c => |
239 | 241 | { |
@@ -385,9 +387,11 @@ private static void ConfigureLeaseService(ContainerBuilder builder) |
385 | 387 | .Register(c => |
386 | 388 | { |
387 | 389 | LeaseConfiguration config = c.Resolve<IOptionsSnapshot<LeaseConfiguration>>().Value; |
388 | | - StorageMsiConfiguration storageMsiConfiguration = c.Resolve<IOptionsSnapshot<StorageMsiConfiguration>>().Value; |
389 | 390 |
|
390 | | - BlobServiceClient blobServiceClient = CreateBlobServiceClient(storageMsiConfiguration, config.ConnectionString); |
| 391 | + // workaround for https://github.com/Azure/azure-sdk-for-net/issues/44373 |
| 392 | + var connectionString = config.ConnectionString.Replace("SharedAccessSignature=?", "SharedAccessSignature="); |
| 393 | + |
| 394 | + BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); |
391 | 395 | return new CloudBlobLeaseService(blobServiceClient, config.ContainerName, config.StoragePath); |
392 | 396 | }) |
393 | 397 | .As<ILeaseService>(); |
@@ -452,7 +456,13 @@ private static void ConfigureSymbolScanValidator(ContainerBuilder builder) |
452 | 456 | private static void ConfigureFlatContainer(ContainerBuilder builder) |
453 | 457 | { |
454 | 458 | builder |
455 | | - .RegisterStorageAccount<FlatContainerConfiguration>(c => c.ConnectionString) |
| 459 | + .Register<CloudBlobClientWrapper>(c => |
| 460 | + { |
| 461 | + var configurationAccessor = c.Resolve<IOptionsSnapshot<FlatContainerConfiguration>>(); |
| 462 | + return new CloudBlobClientWrapper( |
| 463 | + configurationAccessor.Value.ConnectionString, |
| 464 | + readAccessGeoRedundant: false); |
| 465 | + }) |
456 | 466 | .Keyed<ICloudBlobClient>(FlatContainerBindingKey); |
457 | 467 |
|
458 | 468 | builder |
@@ -604,50 +614,5 @@ private T GetRequiredService<T>() |
604 | 614 | { |
605 | 615 | return _serviceProvider.GetRequiredService<T>(); |
606 | 616 | } |
607 | | - |
608 | | - private static BlobServiceClient CreateBlobServiceClient( |
609 | | - StorageMsiConfiguration msiConfiguration, |
610 | | - string storageConnectionString, |
611 | | - TimeSpan? requestTimeout = null) |
612 | | - { |
613 | | - BlobClientOptions blobClientOptions = new BlobClientOptions(); |
614 | | - if (requestTimeout.HasValue) |
615 | | - { |
616 | | - blobClientOptions.Retry.NetworkTimeout = requestTimeout.Value; |
617 | | - } |
618 | | - |
619 | | - if (msiConfiguration.UseManagedIdentity) |
620 | | - { |
621 | | - if (string.IsNullOrWhiteSpace(msiConfiguration.ManagedIdentityClientId)) |
622 | | - { |
623 | | - // 1. Using MSI with DefaultAzureCredential (local debugging) |
624 | | - var defaultAzureCredentialOptions = new DefaultAzureCredentialOptions |
625 | | - { |
626 | | - ManagedIdentityClientId = null, |
627 | | - }; |
628 | | - |
629 | | - return new BlobServiceClient( |
630 | | - ConnectionStringExtensions.GetBlobEndpointFromConnectionString(storageConnectionString), |
631 | | - new DefaultAzureCredential(defaultAzureCredentialOptions), |
632 | | - blobClientOptions); |
633 | | - } |
634 | | - else |
635 | | - { |
636 | | - // 2. Using MSI with ClientId |
637 | | - return new BlobServiceClient( |
638 | | - ConnectionStringExtensions.GetBlobEndpointFromConnectionString(storageConnectionString), |
639 | | - new ManagedIdentityCredential(msiConfiguration.ManagedIdentityClientId), |
640 | | - blobClientOptions); |
641 | | - } |
642 | | - } |
643 | | - else |
644 | | - { |
645 | | - // 3. Using SAS token |
646 | | - // workaround for https://github.com/Azure/azure-sdk-for-net/issues/44373 |
647 | | - var connectionString = storageConnectionString.Replace("SharedAccessSignature=?", "SharedAccessSignature="); |
648 | | - |
649 | | - return new BlobServiceClient(connectionString, blobClientOptions); |
650 | | - } |
651 | | - } |
652 | 617 | } |
653 | 618 | } |
0 commit comments