Skip to content

Commit

Permalink
Merge pull request #4852 from NuGet/dev
Browse files Browse the repository at this point in the history
[ReleasePrep][2017.10.16]RI of dev into master
  • Loading branch information
shishirx34 committed Oct 19, 2017
2 parents c69bf0e + 8a2a6b2 commit da86aef
Show file tree
Hide file tree
Showing 129 changed files with 3,959 additions and 624 deletions.
25 changes: 25 additions & 0 deletions src/Bootstrap/dist/css/bootstrap-theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/Bootstrap/less/theme/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,16 @@ img.package-icon {
word-break: normal;
word-break: break-word;
}

.showOnFocus {
display: block;
line-height:0;
height: 0;
overflow: hidden;
}

.showOnFocus:focus {
line-height:2em;
height: 2em;
color: @navbar-inverse-color;
}
19 changes: 18 additions & 1 deletion src/Bootstrap/less/theme/page-manage-owners.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,25 @@
}
}

.remove-owner-disabled a {
color: @gray;

.ms-Icon {
position: relative;
top: 3px;
}
}

.remove-owner a:hover, .remove-owner a:active {
color: darken(@brand-danger, 10%);
}

.remove-owner-disabled a:hover, .remove-owner-disabled a:active {
color: darken(@gray, 10%);
}

.remove-owner-disabled .icon-link:hover span {
text-decoration: none;
}
}
}
}
17 changes: 14 additions & 3 deletions src/NuGetGallery.Core/Auditing/AuditActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using NuGetGallery.Authentication;

namespace NuGetGallery.Auditing
{
Expand All @@ -18,21 +20,23 @@ public class AuditActor
public string MachineIP { get; set; }
public string UserName { get; set; }
public string AuthenticationType { get; set; }
public string CredentialKey { get; set; }
public DateTime TimestampUtc { get; set; }

public AuditActor OnBehalfOf { get; set; }

public AuditActor(string machineName, string machineIP, string userName, string authenticationType, DateTime timeStampUtc)
: this(machineName, machineIP, userName, authenticationType, timeStampUtc, null) { }
public AuditActor(string machineName, string machineIP, string userName, string authenticationType, string credentialKey, DateTime timeStampUtc)
: this(machineName, machineIP, userName, authenticationType, credentialKey, timeStampUtc, null) { }

public AuditActor(string machineName, string machineIP, string userName, string authenticationType, DateTime timeStampUtc, AuditActor onBehalfOf)
public AuditActor(string machineName, string machineIP, string userName, string authenticationType, string credentialKey, DateTime timeStampUtc, AuditActor onBehalfOf)
{
MachineName = machineName;
MachineIP = machineIP;
UserName = userName;
AuthenticationType = authenticationType;
TimestampUtc = timeStampUtc;
OnBehalfOf = onBehalfOf;
CredentialKey = credentialKey;
}

public static Task<AuditActor> GetAspNetOnBehalfOfAsync()
Expand Down Expand Up @@ -68,17 +72,23 @@ public static Task<AuditActor> GetAspNetOnBehalfOfAsync(HttpContextBase context)

string user = null;
string authType = null;
string credentialKey = null;

if (context.User != null)
{
user = context.User.Identity.Name;
authType = context.User.Identity.AuthenticationType;

var claimsIdentity = context.User.Identity as ClaimsIdentity;
credentialKey = claimsIdentity?.GetClaimOrDefault(NuGetClaims.CredentialKey);
}

return Task.FromResult(new AuditActor(
null,
clientIpAddress,
user,
authType,
credentialKey,
DateTime.UtcNow));
}

Expand All @@ -97,6 +107,7 @@ public static async Task<AuditActor> GetCurrentMachineActorAsync(AuditActor onBe
ipAddress,
$@"{Environment.UserDomainName}\{Environment.UserName}",
"MachineUser",
string.Empty,
DateTime.UtcNow,
onBehalfOf);
}
Expand Down
26 changes: 26 additions & 0 deletions src/NuGetGallery.Core/Authentication/AuthenticationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.Linq;
using System.Security.Claims;

namespace NuGetGallery.Authentication
{
public static class AuthenticationExtensions
{
public static string GetClaimOrDefault(this ClaimsIdentity self, string claimType)
{
return self.Claims.GetClaimOrDefault(claimType);
}

public static string GetClaimOrDefault(this IEnumerable<Claim> self, string claimType)
{
return self
.Where(c => string.Equals(c.Type, claimType, StringComparison.OrdinalIgnoreCase))
.Select(c => c.Value)
.FirstOrDefault();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ public static class NuGetClaims
public const string ApiKey = "https://claims.nuget.org/apikey";

public const string Scope = "https://claims.nuget.org/scope";

// Allows identifying the credential that was used by his DB key.
public const string CredentialKey = "https://claims.nuget.org/credentialkey";
}
}
}
11 changes: 2 additions & 9 deletions src/NuGetGallery.Core/Entities/EntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NuGetGallery
{
public class EntityRepository<T>
: IEntityRepository<T>
where T : class, IEntity, new()
where T : class, new()
{
private readonly IEntitiesContext _entities;

Expand All @@ -27,21 +27,14 @@ public void DeleteOnCommit(T entity)
_entities.Set<T>().Remove(entity);
}

public T GetEntity(int key)
{
return _entities.Set<T>().Find(key);
}

public IQueryable<T> GetAll()
{
return _entities.Set<T>();
}

public int InsertOnCommit(T entity)
public void InsertOnCommit(T entity)
{
_entities.Set<T>().Add(entity);

return entity.Key;
}
}
}
5 changes: 2 additions & 3 deletions src/NuGetGallery.Core/Entities/IEntityRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
namespace NuGetGallery
{
public interface IEntityRepository<T>
where T : class, IEntity, new()
where T : class, new()
{
Task CommitChangesAsync();
void DeleteOnCommit(T entity);
T GetEntity(int key);
IQueryable<T> GetAll();
int InsertOnCommit(T entity);
void InsertOnCommit(T entity);
}
}
5 changes: 5 additions & 0 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="Auditing\PackageAuditRecord.cs" />
<Compile Include="Auditing\ScopeAuditRecord.cs" />
<Compile Include="Auditing\UserAuditRecord.cs" />
<Compile Include="Authentication\AuthenticationExtensions.cs" />
<Compile Include="Cookies\CookieComplianceServiceBase.cs" />
<Compile Include="Cookies\CookieConsentMessage.cs" />
<Compile Include="Cookies\ICookieComplianceService.cs" />
Expand Down Expand Up @@ -191,6 +192,7 @@
<Compile Include="ICloudStorageStatusDependency.cs" />
<Compile Include="Infrastructure\AzureEntityList.cs" />
<Compile Include="Infrastructure\TableErrorLog.cs" />
<Compile Include="Authentication\NuGetClaims.cs" />
<Compile Include="PackageReaderCoreExtensions.cs" />
<Compile Include="PackageStatus.cs" />
<Compile Include="Packaging\InvalidPackageException.cs" />
Expand All @@ -205,7 +207,10 @@
<Compile Include="Properties\AssemblyInfo.*.cs" />
<Compile Include="NuGetVersionExtensions.cs" />
<Compile Include="SemVerLevelKey.cs" />
<Compile Include="Services\CloudBlobClientWrapper.cs" />
<Compile Include="Services\CloudBlobContainerWrapper.cs" />
<Compile Include="Services\CloudBlobCoreFileStorageService.cs" />
<Compile Include="Services\CloudBlobWrapper.cs" />
<Compile Include="Services\CloudFileReference.cs" />
<Compile Include="Services\CorePackageFileService.cs" />
<Compile Include="Services\CorePackageService.cs" />
Expand Down
25 changes: 19 additions & 6 deletions src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public CloudBlobCoreFileStorageService(ICloudBlobClient client)

public async Task DeleteFileAsync(string folderName, string fileName)
{
ICloudBlobContainer container = await GetContainer(folderName);
ICloudBlobContainer container = await GetContainerAsync(folderName);
var blob = container.GetBlobReference(fileName);
await blob.DeleteIfExistsAsync();
}

public async Task<bool> FileExistsAsync(string folderName, string fileName)
{
ICloudBlobContainer container = await GetContainer(folderName);
ICloudBlobContainer container = await GetContainerAsync(folderName);
var blob = container.GetBlobReference(fileName);
return await blob.ExistsAsync();
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public async Task<IFileReference> GetFileReferenceAsync(string folderName, strin
throw new ArgumentNullException(nameof(fileName));
}

ICloudBlobContainer container = await GetContainer(folderName);
ICloudBlobContainer container = await GetContainerAsync(folderName);
var blob = container.GetBlobReference(fileName);
var result = await GetBlobContentAsync(folderName, fileName, ifNoneMatch);
if (result.StatusCode == HttpStatusCode.NotModified)
Expand All @@ -88,7 +88,7 @@ public async Task<IFileReference> GetFileReferenceAsync(string folderName, strin

public async Task SaveFileAsync(string folderName, string fileName, Stream packageFile, bool overwrite = true)
{
ICloudBlobContainer container = await GetContainer(folderName);
ICloudBlobContainer container = await GetContainerAsync(folderName);
var blob = container.GetBlobReference(fileName);

try
Expand All @@ -110,7 +110,20 @@ public async Task SaveFileAsync(string folderName, string fileName, Stream packa
await blob.SetPropertiesAsync();
}

protected async Task<ICloudBlobContainer> GetContainer(string folderName)
public async Task<Uri> GetFileReadUriAsync(string folderName, string fileName, DateTimeOffset? endOfAccess)
{
folderName = folderName ?? throw new ArgumentNullException(nameof(folderName));
fileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
if (endOfAccess.HasValue && endOfAccess < DateTimeOffset.UtcNow)
{
throw new ArgumentOutOfRangeException(nameof(endOfAccess), $"{nameof(endOfAccess)} is in the past");
}
ICloudBlobContainer container = await GetContainerAsync(folderName);
var blob = container.GetBlobReference(fileName);
return new Uri(blob.Uri, blob.GetSharedReadSignature(endOfAccess));
}

protected async Task<ICloudBlobContainer> GetContainerAsync(string folderName)
{
ICloudBlobContainer container;
if (_containers.TryGetValue(folderName, out container))
Expand Down Expand Up @@ -146,7 +159,7 @@ protected async Task<ICloudBlobContainer> GetContainer(string folderName)

private async Task<StorageResult> GetBlobContentAsync(string folderName, string fileName, string ifNoneMatch = null)
{
ICloudBlobContainer container = await GetContainer(folderName);
ICloudBlobContainer container = await GetContainerAsync(folderName);

var blob = container.GetBlobReference(fileName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ public Task FetchAttributesAsync()
state: null);
}

public string GetSharedReadSignature(DateTimeOffset? endOfAccess)
{
var accessPolicy = new SharedAccessBlobPolicy
{
SharedAccessExpiryTime = endOfAccess,
Permissions = SharedAccessBlobPermissions.Read
};

var signature = this._blob.GetSharedAccessSignature(accessPolicy);

return signature;
}

// The default retry policy treats a 304 as an error that requires a retry. We don't want that!
private class DontRetryOnNotModifiedPolicy : IRetryPolicy
{
Expand Down
30 changes: 30 additions & 0 deletions src/NuGetGallery.Core/Services/CorePackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ public Task DeleteValidationPackageFileAsync(string id, string version)
return _fileStorageService.DeleteFileAsync(CoreConstants.ValidationFolderName, fileName);
}

public Task DeletePackageFileAsync(string id, string version)
{
if (String.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException(nameof(id));
}

if (String.IsNullOrWhiteSpace(version))
{
throw new ArgumentNullException(nameof(version));
}

var normalizedVersion = NuGetVersionFormatter.Normalize(version);

var fileName = BuildFileName(id, normalizedVersion, CoreConstants.PackageFileSavePathTemplate, CoreConstants.NuGetPackageFileExtension);
return _fileStorageService.DeleteFileAsync(CoreConstants.PackagesFolderName, fileName);
}

public Task<Uri> GetValidationPackageReadUriAsync(Package package, DateTimeOffset endOfAccess)
{
package = package ?? throw new ArgumentNullException(nameof(package));

var fileName = BuildFileName(
package,
CoreConstants.PackageFileSavePathTemplate,
CoreConstants.NuGetPackageFileExtension);

return _fileStorageService.GetFileReadUriAsync(CoreConstants.ValidationFolderName, fileName, endOfAccess);
}

protected static string BuildFileName(Package package, string format, string extension)
{
if (package == null)
Expand Down
Loading

0 comments on commit da86aef

Please sign in to comment.