-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Prefix] Add auditing for reserved namespaces (#4940)
- Loading branch information
1 parent
02cb908
commit ff2cbd9
Showing
20 changed files
with
373 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/NuGetGallery.Core/Auditing/AuditedEntities/AuditedReservedNamespace.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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. | ||
|
||
namespace NuGetGallery.Auditing.AuditedEntities | ||
{ | ||
public class AuditedReservedNamespace | ||
{ | ||
public string Value { get; private set; } | ||
public bool IsPrefix { get; private set; } | ||
public bool IsSharedNamespace { get; private set; } | ||
|
||
public static AuditedReservedNamespace CreateFrom(ReservedNamespace reservedNamespace) | ||
{ | ||
return new AuditedReservedNamespace | ||
{ | ||
Value = reservedNamespace.Value, | ||
IsSharedNamespace = reservedNamespace.IsSharedNamespace, | ||
IsPrefix = reservedNamespace.IsPrefix, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/NuGetGallery.Core/Auditing/AuditedReservedNamespaceAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// 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. | ||
|
||
namespace NuGetGallery.Auditing | ||
{ | ||
public enum AuditedReservedNamespaceAction | ||
{ | ||
ReserveNamespace, | ||
UnreserveNamespace, | ||
AddOwner, | ||
RemoveOwner | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/NuGetGallery.Core/Auditing/ReservedNamespaceAuditRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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.Linq; | ||
using System.Collections.Generic; | ||
using NuGetGallery.Auditing.AuditedEntities; | ||
|
||
namespace NuGetGallery.Auditing | ||
{ | ||
public class ReservedNamespaceAuditRecord : AuditRecord<AuditedReservedNamespaceAction> | ||
{ | ||
public string Value; | ||
|
||
public AuditedReservedNamespace AffectedReservedNamespace; | ||
|
||
public string AffectedOwner; | ||
|
||
public PackageRegistrationAuditRecord[] AffectedRegistrations; | ||
|
||
public ReservedNamespaceAuditRecord(ReservedNamespace reservedNamespace, AuditedReservedNamespaceAction action) | ||
: this(reservedNamespace, action, username: null, registrations: null) | ||
{ } | ||
|
||
public ReservedNamespaceAuditRecord(ReservedNamespace reservedNamespace, | ||
AuditedReservedNamespaceAction action, | ||
string username, | ||
IEnumerable<PackageRegistration> registrations) | ||
: base(action) | ||
{ | ||
if (reservedNamespace == null) | ||
{ | ||
throw new ArgumentNullException(nameof(reservedNamespace)); | ||
} | ||
|
||
Value = reservedNamespace.Value; | ||
AffectedReservedNamespace = AuditedReservedNamespace.CreateFrom(reservedNamespace); | ||
Action = action; | ||
|
||
if (!string.IsNullOrWhiteSpace(username)) | ||
{ | ||
AffectedOwner = username; | ||
|
||
if (registrations != null && registrations.Any()) | ||
{ | ||
var registrationAction = GetPackageRegistrationAction(action); | ||
AffectedRegistrations = registrations | ||
.Select(pr => new PackageRegistrationAuditRecord(pr, registrationAction, username)) | ||
.ToArray(); | ||
} | ||
} | ||
} | ||
|
||
public override string GetPath() | ||
{ | ||
return Value.ToLowerInvariant(); | ||
} | ||
|
||
private static AuditedPackageRegistrationAction GetPackageRegistrationAction(AuditedReservedNamespaceAction action) | ||
{ | ||
switch (action) | ||
{ | ||
case AuditedReservedNamespaceAction.AddOwner: | ||
return AuditedPackageRegistrationAction.MarkVerified; | ||
case AuditedReservedNamespaceAction.RemoveOwner: | ||
return AuditedPackageRegistrationAction.MarkUnverified; | ||
default: | ||
throw new ArgumentException($"Invalid value specified for {nameof(action)}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.