Skip to content

Commit

Permalink
Merge branch 'dev' into lilixie-2087140
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodyear2017 committed Jul 10, 2024
2 parents 20d56c4 + 9482371 commit bed9655
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 75 deletions.
24 changes: 22 additions & 2 deletions .pipelines/Release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,32 @@ trigger:

pr: none

parameters:
- name: TargetPipelines
type: object
default:
- id: 21120
paramName: NuGetGallerySubmoduleBranch
- id: 21280
paramName: NuGetGalleryBranch

variables:
- name: NugetMultifeedWarnLevel
value: none

pool:
vmImage: 'windows-latest'

steps:
- powershell: Write-Host "Dummy task"
- ${{ each pipeline in parameters.TargetPipelines }}:
- powershell: |-
$body = @{
"templateParameters" = @{
"${{ pipeline.paramName }}" = "$(Build.SourceBranchName)"
}
}
$headers = @{ "Authorization" = "Bearer $env:ACCESS_TOKEN" };
$url = "$(System.CollectionUri)$(System.TeamProject)/_apis/pipelines/${{ pipeline.id }}/runs?api-version=7.0"
Invoke-RestMethod -Uri $url -Method POST -Headers $headers -Body ($body | ConvertTo-Json) -ContentType "application/json"
env:
ACCESS_TOKEN: $(System.AccessToken)
2 changes: 2 additions & 0 deletions src/AccountDeleter/Configuration/GalleryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public string SiteRoot
public string AzureStorage_Uploads_ConnectionString { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string AzureStorage_Revalidation_ConnectionString { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool AzureStorageReadAccessGeoRedundant { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool AzureStorageUseMsi { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string AzureStorageMsiClientId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public TimeSpan FeatureFlagsRefreshInterval { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool AdminPanelEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool AdminPanelDatabaseAccessEnabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
Expand Down
2 changes: 0 additions & 2 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />

<PackageReference Include="Azure.Core" Version="1.39.0" />
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
Expand Down
14 changes: 14 additions & 0 deletions src/NuGetGallery.Core/Services/CloudBlobClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ public static CloudBlobClientWrapper UsingServicePrincipal(
return new CloudBlobClientWrapper(storageConnectionString, tokenCredential, readAccessGeoRedundant, requestTimeout);
}

public static CloudBlobClientWrapper UsingDefaultAzureCredential(
string storageConnectionString,
string clientId = null,
bool readAccessGeoRedundant = false,
TimeSpan? requestTimeout = null)
{
var options = new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = clientId,
};
var tokenCredential = new DefaultAzureCredential(options);
return new CloudBlobClientWrapper(storageConnectionString, tokenCredential, readAccessGeoRedundant, requestTimeout);
}

public ISimpleCloudBlob GetBlobFromUri(Uri uri)
{
// For Azure blobs, the query string is assumed to be the SAS token.
Expand Down
9 changes: 9 additions & 0 deletions src/NuGetGallery.Core/Services/CloudBlobReadOnlyProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ public CloudBlobReadOnlyProperties(BlobItem blobItem)
CopyStatus = null;
CopyStatusDescription = null;
}

public CloudBlobReadOnlyProperties(BlobDownloadDetails details)
{
LastModifiedUtc = details.LastModified.UtcDateTime;
Length = details.ContentLength;
IsSnapshot = false;
CopyStatus = details.CopyStatus;
CopyStatusDescription = details.CopyStatusDescription;
}
}
}
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/Services/CloudBlobWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ private void UpdateEtag(BlobDownloadDetails details)
if (details != null)
{
_lastSeenEtag = EtagToString(details.ETag);
BlobProperties = new CloudBlobReadOnlyProperties(details);
ReplaceHttpHeaders(details);
ReplaceMetadata(details.Metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private async Task<DeleteAccountStatus> RunAccountDeletionTask(Func<Task> getTas
await _featureFlagService.RemoveUserAsync(userToBeDeleted);
await RemoveSupportRequests(userToBeDeleted);

using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
await getTask();
Expand Down
4 changes: 4 additions & 0 deletions src/NuGetGallery.Services/Configuration/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public class AppConfiguration : IAppConfiguration
/// </summary>
public bool AzureStorageReadAccessGeoRedundant { get; set; }

public bool AzureStorageUseMsi { get; set; } = false;

public string AzureStorageMsiClientId { get; set; } = null;

public TimeSpan FeatureFlagsRefreshInterval { get; set; }

[DefaultValue(true)]
Expand Down
14 changes: 14 additions & 0 deletions src/NuGetGallery.Services/Configuration/IAppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ public interface IAppConfiguration : IMessageServiceConfiguration
/// </summary>
bool AzureStorageReadAccessGeoRedundant { get; set; }

/// <summary>
/// Indicates whether Managed Service Identity should be used to access Azure Storage.
/// If false, the presumption is that connection strings contain the necessary credentials.
/// If true, single MSI is going to be used for all storage connections.
/// </summary>
bool AzureStorageUseMsi { get; set; }

/// <summary>
/// Client ID of the MSI to use for Azure storage access.
/// If empty or not specified, the default MSI will be used in Release builds
/// and <see cref="Azure.Identity.DefaultAzureCredential"/> in Debug builds.
/// </summary>
string AzureStorageMsiClientId { get; set; }

/// <summary>
/// How frequently the feature flags should be refreshed.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task AddPackageOwnerAsync(PackageRegistration packageRegistration,

if (commitChanges)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
await AddPackageOwnerTask(packageRegistration, user, commitChanges);
Expand Down Expand Up @@ -288,7 +288,7 @@ private async Task RemovePackageOwnerAsync(
{
if (commitChanges)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
await RemovePackageOwnerImplAsync(packageRegistration, ownerToBeRemoved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task UpdateListedInBulkAsync(IReadOnlyList<Package> packages, bool
throw new ArgumentException("All packages to change the listing status of must have the same ID.", nameof(packages));
}

using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
foreach (var package in packages)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task UpdateVulnerabilityAsync(PackageVulnerability vulnerability, b
throw new ArgumentNullException(nameof(vulnerability));
}

using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
var packagesToUpdate = UpdateVulnerabilityInternal(vulnerability, withdrawn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task DeleteReservedNamespaceAsync(string existingNamespace)
throw new ArgumentException(ServicesStrings.ReservedNamespace_InvalidNamespace);
}

using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = EntitiesContext.GetDatabase().BeginTransaction())
{
var namespaceToDelete = FindReservedNamespaceForPrefix(existingNamespace)
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task DeleteOwnerFromReservedNamespaceAsync(string prefix, string us
List<PackageRegistration> packageRegistrationsToMarkUnverified;
if (commitChanges)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = EntitiesContext.GetDatabase().BeginTransaction())
{
packageRegistrationsToMarkUnverified = await DeleteOwnerFromReservedNamespaceImplAsync(prefix, username, namespaceToModify);
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetGallery/App_Code/ViewHelpers.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@
<text>onerror="this.src='@url'; this.onerror = null;"</text>
}

@helper PackageImageFallback()
{
<text>onerror="this.className='package-icon img-responsive package-default-icon'; this.onerror = null;"</text>
}

@helper Option(string value, string label, string currentValue)
{
<option value="@value" @if (value == currentValue)
Expand Down
47 changes: 37 additions & 10 deletions src/NuGetGallery/App_Start/DefaultDependenciesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ protected override void Load(ContainerBuilder builder)
.InstancePerLifetimeScope();

builder.RegisterType<EntityRepository<AccountDelete>>()
.AsSelf()
.As<IEntityRepository<AccountDelete>>()
.InstancePerLifetimeScope();
.AsSelf()
.As<IEntityRepository<AccountDelete>>()
.InstancePerLifetimeScope();

builder.RegisterType<EntityRepository<Credential>>()
.AsSelf()
Expand Down Expand Up @@ -1432,18 +1432,45 @@ private static void ConfigureForAzureStorage(ContainerBuilder builder, IGalleryC
{
if (completedBindingKeys.Add(dependent.BindingKey))
{
builder.RegisterInstance(new CloudBlobClientWrapper(dependent.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant))
.AsSelf()
.As<ICloudBlobClient>()
.SingleInstance()
.Keyed<ICloudBlobClient>(dependent.BindingKey);
CloudBlobClientWrapper blobClient;
if (!configuration.Current.AzureStorageUseMsi)
{
blobClient = new CloudBlobClientWrapper(dependent.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant);
}
else
{
if (string.IsNullOrWhiteSpace(configuration.Current.AzureStorageMsiClientId))
{
#if DEBUG
blobClient = CloudBlobClientWrapper.UsingDefaultAzureCredential(
dependent.AzureStorageConnectionString,
readAccessGeoRedundant: configuration.Current.AzureStorageReadAccessGeoRedundant);
#else
blobClient = CloudBlobClientWrapper.UsingMsi(
dependent.AzureStorageConnectionString,
readAccessGeoRedundant: configuration.Current.AzureStorageReadAccessGeoRedundant);
#endif
}
else
{
blobClient = CloudBlobClientWrapper.UsingMsi(
dependent.AzureStorageConnectionString,
configuration.Current.AzureStorageMsiClientId,
configuration.Current.AzureStorageReadAccessGeoRedundant);
}
}
builder.RegisterInstance(blobClient)
.AsSelf()
.As<ICloudBlobClient>()
.SingleInstance()
.Keyed<ICloudBlobClient>(dependent.BindingKey);

// Do not register the service as ICloudStorageStatusDependency because
// the CloudAuditingService registers it and the gallery uses the same storage account for all the containers.
builder.RegisterType<CloudBlobFileStorageService>()
.WithParameter(new ResolvedParameter(
(pi, ctx) => pi.ParameterType == typeof(ICloudBlobClient),
(pi, ctx) => ctx.ResolveKeyed<ICloudBlobClient>(dependent.BindingKey)))
(pi, ctx) => pi.ParameterType == typeof(ICloudBlobClient),
(pi, ctx) => ctx.ResolveKeyed<ICloudBlobClient>(dependent.BindingKey)))
.AsSelf()
.As<IFileStorageService>()
.As<ICoreFileStorageService>()
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public virtual async Task<JsonResult> AddCertificate(string accountName, HttpPos

try
{
using (var uploadStream = uploadFile.InputStream)
using (uploadFile.InputStream)
{
certificate = await CertificateService.AddCertificateAsync(uploadFile);
}
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/Services/PackageDeleteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private async Task<bool> AreStatisticsStaleAsync()

public async Task SoftDeletePackagesAsync(IEnumerable<Package> packages, User deletedBy, string reason, string signature)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
// Increase command timeout
Expand Down Expand Up @@ -322,7 +322,7 @@ await _symbolPackageService.UpdateStatusAsync(

public async Task HardDeletePackagesAsync(IEnumerable<Package> packages, User deletedBy, string reason, string signature, bool deleteEmptyPackageRegistration)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
// Increase command timeout
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Services/PackageDeprecationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public async Task UpdateDeprecation(

if (_entitiesContext.HasChanges)
{
using (var strategy = new SuspendDbExecutionStrategy())
using (new SuspendDbExecutionStrategy())
using (var transaction = _entitiesContext.GetDatabase().BeginTransaction())
{
await _entitiesContext.SaveChangesAsync();
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
<h1>
<span class="pull-left">
<img class="package-icon img-responsive @(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? null : "package-default-icon")" aria-hidden="true" alt=""
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? Model.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) && Model.ShowDetailsAndLinks ? Model.IconUrl : null)" @ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/default-package-icon-256x256.png")) />
</span>
<span class="title">
@Html.BreakWord(Model.Id)
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Shared/_ListPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div class="row">
<div class="col-sm-1 hidden-xs hidden-sm col-package-icon">
<img class="package-icon img-responsive @(!PackageHelper.ShouldRenderUrl(Model.IconUrl) ? "package-default-icon" : null)" aria-hidden="true" alt=""
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) ? Model.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) ? Model.IconUrl : null)" @ViewHelpers.PackageImageFallback()/>
</div>
<div class="col-sm-11">
<div class="package-header">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</td>
<td class="align-middle hidden-xs">
<img class="package-icon img-responsive @(!PackageHelper.ShouldRenderUrl(package.IconUrl) ? "package-default-icon" : null)" aria-hidden="true" alt="Package Icon"
src="@(PackageHelper.ShouldRenderUrl(package.IconUrl) ? package.IconUrl : null)" />
src="@(PackageHelper.ShouldRenderUrl(package.IconUrl) ? package.IconUrl : null)" @ViewHelpers.PackageImageFallback()/>
</td>
<td class="align-middle package-id"><a href="@Url.Package(package.Id)">@Html.BreakWord(package.Id.Abbreviate(40))</a></td>
<td class="align-middle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<Compile Include="Services\CoreReadmeFileServiceFacts.cs" />
<Compile Include="Services\CoreLicenseFileServiceFacts.cs" />
<Compile Include="Services\CoreSymbolPackageServiceFacts.cs" />
<Compile Include="Services\FileUriPermissionsFacts.cs" />
<Compile Include="Services\FolderNamesDataAttribute.cs" />
<Compile Include="Services\FolderNamesDataAttributeFacts.cs" />
<Compile Include="Services\GalleryCloudBlobContainerInformationProviderFacts.cs" />
Expand Down
33 changes: 0 additions & 33 deletions tests/NuGetGallery.Core.Facts/Services/FileUriPermissionsFacts.cs

This file was deleted.

Loading

0 comments on commit bed9655

Please sign in to comment.