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

Refactor AllowListVerificationProvider #2454

Merged
merged 6 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 2 additions & 5 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/AddCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ public override async Task ExecuteCommandAsync()
// If the Source Feed Folder does not exist, it will be created.
OfflineFeedUtility.ThrowIfInvalid(Source);

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

var packageExtractionContext = new PackageExtractionContext(
Expand ? PackageSaveMode.Defaultv3 : PackageSaveMode.Nuspec | PackageSaveMode.Nupkg,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(Settings, Console));
ClientPolicyContext.GetClientPolicy(Settings, Console),
Console);

var offlineFeedAddContext = new OfflineFeedAddContext(
packagePath,
Expand Down
8 changes: 3 additions & 5 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/InitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public override async Task ExecuteCommandAsync()

if (packagePaths.Count > 0)
{
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var signingSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, Console);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, Console);

var packageExtractionContext = new PackageExtractionContext(
Expand ? PackageSaveMode.Defaultv3 : PackageSaveMode.Nuspec | PackageSaveMode.Nupkg,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
signingSettings);
clientPolicyContext,
Console);

foreach (var packagePath in packagePaths)
{
Expand Down
26 changes: 10 additions & 16 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,24 @@ private async Task PerformV2RestoreAsync(string packagesConfigFilePath, string i
cacheContext.NoCache = NoCache;
cacheContext.DirectDownload = DirectDownload;

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var signingSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, Console);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, Console);

var projectContext = new ConsoleProjectContext(Console)
{
PackageExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
signingSettings)
clientPolicyContext,
Console)
};

var downloadContext = new PackageDownloadContext(cacheContext, installPath, DirectDownload)
{
ExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
signingSettings)
clientPolicyContext,
Console)
};

var result = await PackageRestoreManager.RestoreMissingPackagesAsync(
Expand Down Expand Up @@ -381,17 +378,15 @@ private async Task InstallPackageAsync(
}
else
{
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var signingVerificationSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, Console);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, Console);

var projectContext = new ConsoleProjectContext(Console)
{
PackageExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
signingVerificationSettings)
clientPolicyContext,
Console)
};

resolutionContext.SourceCacheContext.NoCache = NoCache;
Expand All @@ -402,9 +397,8 @@ private async Task InstallPackageAsync(
ExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode,
Console,
signedPackageVerifier,
signingVerificationSettings)
clientPolicyContext,
Console)
};

if (EffectivePackageSaveMode != Packaging.PackageSaveMode.None)
Expand Down
13 changes: 5 additions & 8 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,14 @@ private async Task<RestoreSummary> PerformNuGetV2RestoreAsync(PackageRestoreInpu

CheckRequireConsent();

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var signingVerificationSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, collectorLogger);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, collectorLogger);
var projectContext = new ConsoleProjectContext(collectorLogger)
{
PackageExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
collectorLogger,
signedPackageVerifier,
signingVerificationSettings)
clientPolicyContext,
collectorLogger)
};

if (EffectivePackageSaveMode != Packaging.PackageSaveMode.None)
Expand All @@ -356,9 +354,8 @@ private async Task<RestoreSummary> PerformNuGetV2RestoreAsync(PackageRestoreInpu
ExtractionContext = new PackageExtractionContext(
Packaging.PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode,
collectorLogger,
signedPackageVerifier,
signingVerificationSettings)
clientPolicyContext,
collectorLogger)
};

var result = await PackageRestoreManager.RestoreMissingPackagesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ public override async Task ExecuteCommandAsync()
var context = new UpdateConsoleProjectContext(Console, FileConflictAction);

var logger = new LoggerAdapter(context);
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var signedPackageVerifierSettings = SignedPackageVerifierSettings.GetClientPolicy(Settings, logger);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(Settings, logger);

context.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
signedPackageVerifierSettings);
clientPolicyContext,
logger);

string inputFileName = Path.GetFileName(inputFile);
// update with packages.config as parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ protected NuGetPowerShellBaseCommand()
PackageRestoreManager = ServiceLocator.GetInstance<IPackageRestoreManager>();
_deleteOnRestartManager = ServiceLocator.GetInstance<IDeleteOnRestartManager>();

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var logger = new LoggerAdapter(this);
PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(ConfigSettings, logger));
ClientPolicyContext.GetClientPolicy(ConfigSettings, logger),
logger);

if (_commonOperations != null)
{
Expand Down Expand Up @@ -261,17 +259,14 @@ protected async Task CheckMissingPackagesAsync()
{
var logger = new LoggerAdapter(this);

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

var downloadContext = new PackageDownloadContext(cacheContext)
{
ParentId = OperationId,
ExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(ConfigSettings, logger))
ClientPolicyContext.GetClientPolicy(ConfigSettings, logger),
logger)
};

var result = await PackageRestoreManager.RestoreMissingPackagesAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,17 +547,14 @@ private async Task RestoreMissingPackagesInSolutionAsync(

using (var cacheContext = new SourceCacheContext())
{
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

var downloadContext = new PackageDownloadContext(cacheContext)
{
ParentId = _nuGetProjectContext.OperationId,
ExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv3,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger))
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger)
};

await _packageRestoreManager.RestoreMissingPackagesAsync(
Expand Down
7 changes: 3 additions & 4 deletions src/NuGet.Clients/NuGet.Tools/NuGetUIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ public NuGetUIFactory(
INuGetUILogger logger,
ISourceControlManagerProvider sourceControlManagerProvider)
{
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
ProjectContext = new NuGetUIProjectContext(
commonOperations,
logger,
sourceControlManagerProvider);

var adapterLogger = new LoggerAdapter(ProjectContext);
ProjectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
new LoggerAdapter(ProjectContext),
signedPackageVerifier,
SignedPackageVerifierSettings.GetDefault());
ClientPolicyContext.GetClientPolicy(Settings.Value, adapterLogger),
adapterLogger);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ public VsPackageInstaller(

_projectContext = new Lazy<INuGetProjectContext>(() => {
var projectContext = new VSAPIProjectContext();
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

var logger = new LoggerAdapter(projectContext);
projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

return projectContext;
});
Expand Down Expand Up @@ -180,14 +178,12 @@ private Task InstallPackageAsync(string source, Project project, string packageI

var projectContext = new VSAPIProjectContext();
var logger = new LoggerAdapter(projectContext);
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

return InstallInternalAsync(project, toInstall, GetSources(sources), projectContext, includePrerelease, ignoreDependencies, CancellationToken.None);
}
Expand Down Expand Up @@ -242,15 +238,13 @@ public void InstallPackagesFromRegistryRepository(string keyName, bool isPreUnzi
var disableBindingRedirects = skipAssemblyReferences;

var projectContext = new VSAPIProjectContext(skipAssemblyReferences, disableBindingRedirects);
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var logger = new LoggerAdapter(projectContext);

projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

await InstallInternalAsync(
project,
Expand Down Expand Up @@ -302,14 +296,12 @@ public void InstallPackagesFromVSExtensionRepository(string extensionId, bool is
var disableBindingRedirects = skipAssemblyReferences;

var projectContext = new VSAPIProjectContext(skipAssemblyReferences, disableBindingRedirects);
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var logger = new LoggerAdapter(projectContext);
projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

return InstallInternalAsync(
project,
Expand Down Expand Up @@ -480,15 +472,13 @@ internal async Task InstallInternalAsync(
var disableBindingRedirects = skipAssemblyReferences;

var projectContext = new VSAPIProjectContext(skipAssemblyReferences, disableBindingRedirects);
var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var logger = new LoggerAdapter(projectContext);

projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

await InstallInternalAsync(
project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,13 @@ private async Task<FallbackPackagePathResolver> GetPackagesPathResolverAsync(Bui
{
InitializePackageManagerAndPackageFolderPath();

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());
var projectContext = new VSAPIProjectContext();
var logger = new LoggerAdapter(projectContext);
projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

var nuGetProject = await _solutionManager.GetOrCreateProjectAsync(
project,
Expand Down Expand Up @@ -174,16 +172,13 @@ public IEnumerable<IVsPackageMetadata> GetInstalledPackages(Project project)
{
InitializePackageManagerAndPackageFolderPath();

var signedPackageVerifier = new PackageSignatureVerifier(SignatureVerificationProviderFactory.GetSignatureVerificationProviders());

var projectContext = new VSAPIProjectContext();
var logger = new LoggerAdapter(projectContext);
projectContext.PackageExtractionContext = new PackageExtractionContext(
PackageSaveMode.Defaultv2,
PackageExtractionBehavior.XmlDocFileSaveMode,
logger,
signedPackageVerifier,
SignedPackageVerifierSettings.GetClientPolicy(_settings, logger));
ClientPolicyContext.GetClientPolicy(_settings, logger),
logger);

var nuGetProject = await _solutionManager.GetOrCreateProjectAsync(
project,
Expand Down
Loading