11// 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
4+ using System ;
45using System . Threading . Tasks ;
56using Microsoft . WindowsAzure . Storage ;
67using Microsoft . WindowsAzure . Storage . Blob ;
78using Microsoft . WindowsAzure . Storage . RetryPolicies ;
9+ using NuGetGallery . Services ;
810
911namespace NuGetGallery
1012{
1113 public class CloudReportService : IReportService
1214 {
1315 private const string _statsContainerName = "nuget-cdnstats" ;
14- private readonly string _connectionString ;
15- private readonly bool _readAccessGeoRedundant ;
16+ private readonly IFeatureFlagService _featureFlagService ;
17+ private readonly IBlobStorageConfiguration _primaryStorageConfiguration ;
18+ private readonly IBlobStorageConfiguration _alternateBlobStorageConfiguration ;
1619
17- public CloudReportService ( string connectionString , bool readAccessGeoRedundant )
20+ public CloudReportService (
21+ IFeatureFlagService featureFlagService ,
22+ IBlobStorageConfiguration primaryBlobStorageConfiguration ,
23+ IBlobStorageConfiguration alternateBlobStorageConfiguration )
1824 {
19- _connectionString = connectionString ;
20- _readAccessGeoRedundant = readAccessGeoRedundant ;
25+ _featureFlagService = featureFlagService ?? throw new ArgumentNullException ( nameof ( featureFlagService ) ) ;
26+ _primaryStorageConfiguration = primaryBlobStorageConfiguration ?? throw new ArgumentNullException ( nameof ( primaryBlobStorageConfiguration ) ) ;
27+ _alternateBlobStorageConfiguration = alternateBlobStorageConfiguration ;
2128 }
2229
2330 public async Task < StatisticsReport > Load ( string reportName )
@@ -42,10 +49,19 @@ public async Task<StatisticsReport> Load(string reportName)
4249
4350 private CloudBlobContainer GetCloudBlobContainer ( )
4451 {
45- var storageAccount = CloudStorageAccount . Parse ( _connectionString ) ;
52+ var connectionString = _primaryStorageConfiguration . ConnectionString ;
53+ var readAccessGeoRedundant = _primaryStorageConfiguration . ReadAccessGeoRedundant ;
54+
55+ if ( _alternateBlobStorageConfiguration != null && _featureFlagService . IsAlternateStatisticsSourceEnabled ( ) )
56+ {
57+ connectionString = _alternateBlobStorageConfiguration . ConnectionString ;
58+ readAccessGeoRedundant = _alternateBlobStorageConfiguration . ReadAccessGeoRedundant ;
59+ }
60+
61+ var storageAccount = CloudStorageAccount . Parse ( connectionString ) ;
4662 var blobClient = storageAccount . CreateCloudBlobClient ( ) ;
4763
48- if ( _readAccessGeoRedundant )
64+ if ( readAccessGeoRedundant )
4965 {
5066 blobClient . DefaultRequestOptions . LocationMode = LocationMode . PrimaryThenSecondary ;
5167 }
0 commit comments