Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReleasePrep][2018.08.01]RI of dev into master #6246

Merged
merged 18 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,539 changes: 779 additions & 760 deletions src/Bootstrap/package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/Bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,11 @@
"fonts",
"js"
]
},
"dependencies": {
"fresh": "^0.5.2",
"mime": "^1.4.1",
"no-case": "^2.3.2",
"tough-cookie": "^2.3.3"
}
}
7 changes: 7 additions & 0 deletions src/NuGetGallery.Core/CoreConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class CoreConstants
public const string OctetStreamContentType = "application/octet-stream";
public const string TextContentType = "text/plain";
public const string CertificateContentType = "application/pkix-cert";
public const string JsonContentType = "application/json";

public const string UserCertificatesFolderName = "user-certificates";
public const string ContentFolderName = "content";
Expand All @@ -30,5 +31,11 @@ public static class CoreConstants
public const string PackagesFolderName = "packages";
public const string UploadsFolderName = "uploads";
public const string ValidationFolderName = "validation";
public const string RevalidationFolderName = "revalidation";
public const string StatusFolderName = "status";

public const string SymbolPackagesFolderName = "symbol-packages";
public const string NuGetSymbolPackageFileExtension = ".snupkg";
public const string SymbolPackageBackupsFolderName = "symbol-package-backups";
}
}
3 changes: 2 additions & 1 deletion src/NuGetGallery.Core/Diagnostics/IDiagnosticsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;

namespace NuGetGallery.Diagnostics
{
public interface IDiagnosticsSource
public interface IDiagnosticsSource : ILogger
{
void ExceptionEvent(Exception exception);

Expand Down
16 changes: 16 additions & 0 deletions src/NuGetGallery.Core/Diagnostics/NullDiagnosticsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;

namespace NuGetGallery.Diagnostics
{
Expand All @@ -28,5 +29,20 @@ public void PerfEvent(string name, TimeSpan time, IEnumerable<KeyValuePair<strin
{
// No-op!
}

void ILogger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
// No-op!
}

bool ILogger.IsEnabled(LogLevel logLevel)
{
return false;
}

IDisposable ILogger.BeginScope<TState>(TState state)
{
return null;
}
}
}
26 changes: 26 additions & 0 deletions src/NuGetGallery.Core/Entities/Certificate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

Expand All @@ -26,6 +27,31 @@ public class Certificate : IEntity
/// </summary>
public string Thumbprint { get; set; }

/// <summary>
/// The subject distinguished name of the certificate.
/// </summary>
public string Subject { get; set; }

/// <summary>
/// The short subject of the certificate. In most cases, this is the CN attribute.
/// </summary>
public string ShortSubject { get; set; }

/// <summary>
/// The issuer distinguished name of the certificate.
/// </summary>
public string Issuer { get; set; }

/// <summary>
/// The short issuer of the certificate. In most cases, this is the CN attribute.
/// </summary>
public string ShortIssuer { get; set; }

/// <summary>
/// The expiration date and time of the certificate.
/// </summary>
public DateTime? Expiration { get; set; }

/// <summary>
/// Gets or sets the collection of user certificates.
/// </summary>
Expand Down
18 changes: 18 additions & 0 deletions src/NuGetGallery.Core/Entities/EntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public EntitiesContext(DbConnection connection, bool readOnly)
public IDbSet<ReservedNamespace> ReservedNamespaces { get; set; }
public IDbSet<Certificate> Certificates { get; set; }
public IDbSet<UserCertificate> UserCertificates { get; set; }
public IDbSet<SymbolPackage> SymbolPackages { get; set; }

/// <summary>
/// User or organization accounts.
Expand Down Expand Up @@ -371,6 +372,23 @@ protected override void OnModelCreating(DbModelBuilder modelBuilder)
.WithRequired(uc => uc.Certificate)
.HasForeignKey(uc => uc.CertificateKey)
.WillCascadeOnDelete(true); // Deleting a Certificate entity will also delete related UserCertificate entities.

modelBuilder.Entity<Certificate>()
.Property(pv => pv.Expiration)
.IsOptional()
.HasColumnType("datetime2");

modelBuilder.Entity<SymbolPackage>()
.HasKey(s => s.Key);

modelBuilder.Entity<Package>()
.HasMany(p => p.SymbolPackages)
.WithRequired(s => s.Package)
.HasForeignKey(p => p.PackageKey);

modelBuilder.Entity<SymbolPackage>()
.Property(s => s.RowVersion)
.IsRowVersion();
}
#pragma warning restore 618
}
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery.Core/Entities/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,7 @@ public bool HasReadMe {
/// Gets or sets the certificate used to sign the package.
/// </summary>
public virtual Certificate Certificate { get; set; }

public virtual ICollection<SymbolPackage> SymbolPackages { get; set; }
}
}
55 changes: 55 additions & 0 deletions src/NuGetGallery.Core/Entities/SymbolPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace NuGetGallery
{
public class SymbolPackage
: IEntity
{
public int Key { get; set; }

public Package Package { get; set; }

public int PackageKey { get; set; }

/// <summary>
/// Timestamp when this symbol was created.
/// </summary>
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime Created { get; set; }

/// <summary>
/// Time when this symbol package is available for consumption. It will be updated after validations are complete.
/// </summary>
public DateTime? Published { get; set; }

/// <summary>
/// The size of the snupkg file in bytes.
/// </summary>
public long FileSize { get; set; }

[StringLength(10)]
public string HashAlgorithm { get; set; }

/// <summary>
/// Stringified hashcode generated by hashing the snupkg file with HashAlgorithm.
/// </summary>
[StringLength(256)]
[Required]
public string Hash { get; set; }

/// <summary>
/// Availability status of the symbol
/// </summary>
public PackageStatus StatusKey { get; set; }

/// <summary>
/// Used for optimistic concurrency when updating the symbols.
/// </summary>
public byte[] RowVersion { get; set; }
}
}
24 changes: 24 additions & 0 deletions src/NuGetGallery.Core/Extensions/PackageRegistrationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ namespace NuGetGallery.Extensions
{
public static class PackageRegistrationExtensions
{
/// <summary>
/// Determines if package signing is allowed for the specified package registration.
/// </summary>
/// <param name="packageRegistration">A package registration.</param>
/// <returns>A flag indicating whether package signing is allowed.</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="packageRegistration" />
/// is <c>null</c>.</exception>
public static bool IsSigningAllowed(this PackageRegistration packageRegistration)
{
if (packageRegistration == null)
{
throw new ArgumentNullException(nameof(packageRegistration));
}

var requiredSigner = packageRegistration.RequiredSigners.FirstOrDefault();

if (requiredSigner == null)
{
return packageRegistration.Owners.Any(owner => HasAnyCertificate(owner));
}

return HasAnyCertificate(requiredSigner);
}

/// <summary>
/// Determines if package signing is required for the specified package registration.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions src/NuGetGallery.Core/Extensions/StorageExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Net;
using Microsoft.WindowsAzure.Storage;

namespace NuGetGallery
{
public static class StorageExceptionExtensions
{
public static bool IsFileAlreadyExistsException(this StorageException e)
{
return e?.RequestInformation?.HttpStatusCode == (int?)HttpStatusCode.Conflict;
}

public static bool IsPreconditionFailedException(this StorageException e)
{
return e?.RequestInformation?.HttpStatusCode == (int?)HttpStatusCode.PreconditionFailed;
}
}
}
8 changes: 8 additions & 0 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<Compile Include="Entities\AccountDelete.cs" />
<Compile Include="Entities\MembershipRequest.cs" />
<Compile Include="Entities\OrganizationMigrationRequest.cs" />
<Compile Include="Entities\SymbolPackage.cs" />
<Compile Include="Entities\PackageDelete.cs" />
<Compile Include="Entities\EmailMessage.cs" />
<Compile Include="Entities\EntitiesConfiguration.cs" />
Expand Down Expand Up @@ -147,6 +148,7 @@
<Compile Include="Extensions\EntitiesContextExtensions.cs" />
<Compile Include="Extensions\PackageRegistrationExtensions.cs" />
<Compile Include="Extensions\PackageValidationSetExtensions.cs" />
<Compile Include="Extensions\StorageExceptionExtensions.cs" />
<Compile Include="Extensions\UserExtensionsCore.cs" />
<Compile Include="ICloudStorageStatusDependency.cs" />
<Compile Include="Infrastructure\AzureEntityList.cs" />
Expand Down Expand Up @@ -175,6 +177,7 @@
<Compile Include="Services\CloudFileReference.cs" />
<Compile Include="Services\CoreMessageService.cs" />
<Compile Include="Services\CorePackageFileService.cs" />
<Compile Include="Services\CoreSymbolPackageService.cs" />
<Compile Include="Services\CorePackageService.cs" />
<Compile Include="Services\CryptographyService.cs" />
<Compile Include="Services\FileAlreadyExistsException.cs" />
Expand All @@ -185,12 +188,17 @@
<Compile Include="Services\ICoreMessageService.cs" />
<Compile Include="Services\ICoreMessageServiceConfiguration.cs" />
<Compile Include="Services\ICorePackageFileService.cs" />
<Compile Include="Services\ICoreSymbolPackageService.cs" />
<Compile Include="Services\ICorePackageService.cs" />
<Compile Include="Services\IFileReference.cs" />
<Compile Include="Services\ICoreFileStorageService.cs" />
<Compile Include="Services\IFileMetadataService.cs" />
<Compile Include="Services\IRevalidationStateService.cs" />
<Compile Include="Services\ISimpleCloudBlob.cs" />
<Compile Include="Services\SymbolPackageFileServiceMetadata.cs" />
<Compile Include="Services\PackageFileServiceMetadata.cs" />
<Compile Include="Services\RevalidationState.cs" />
<Compile Include="Services\RevalidationStateService.cs" />
<Compile Include="Services\TestableStorageClientException.cs" />
<Compile Include="StreamExtensions.cs" />
<Compile Include="CoreStrings.Designer.cs">
Expand Down
Loading