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

Discover plugins installed using Net tools #5990

Conversation

Nigusu-Allehu
Copy link
Contributor

@Nigusu-Allehu Nigusu-Allehu commented Aug 24, 2024

Bug

Fixes: NuGet/Home#13740

Description

This PR makes sure NuGet discovers credential providers installed using .NET tools.
dotnet tool install <provider package name> --global should install the tool and add its path to the PATH environmental varibale. Iterate through all the paths in PATH and all the files in the path to find the plugins. By design, we expect these plugins to be named nuget-plugin*.

This PR introduces a new TFM, net8.0, to NuGet.Protocol. The primary reason for adding net8.0 support is to take advantage of newer APIs, specifically File.GetUnixFileMode(fileInfo.FullName), which simplifies handling file permissions in Unix-based systems.

Plugin discovery method

The discovery is done based on which environmental variable has been specified

  • If NUGET_NETFX_PLUGIN_PATHS or NUGET_NETCORE_PLUGIN_PATHS have been specified, use the old discovery method to look up non dotnet tools plugins in the paths added in the env variable.
  • If NUGET_NETFX_PLUGIN_PATHS and NUGET_NETCORE_PLUGIN_PATHS have not been specified
    • if NUGET_PLUGIN_PATHS specified,
      • Collect the set of plugins the env variable is pointing to: They could be donet tools or non dotnet tools plugin files.
    • if NUGET_PLUGIN_PATHS not specified,
      • Discover all plugins using the default discovery method

Default discovery method

  • For dotnet tools
    • Traverse all the directories specified in PATH env variable, and search for executable nuget-plugin-*files
  • For non dotnet tools
    • %UserProfile%/.nuget/plugins

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc. Document .net tools Plugin feature Home#13858

@Nigusu-Allehu Nigusu-Allehu requested a review from a team as a code owner August 24, 2024 19:20
@Nigusu-Allehu Nigusu-Allehu marked this pull request as draft August 24, 2024 19:20
@Nigusu-Allehu Nigusu-Allehu self-assigned this Aug 26, 2024
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 3, 2024
@Nigusu-Allehu Nigusu-Allehu removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 3, 2024
@Nigusu-Allehu Nigusu-Allehu marked this pull request as ready for review September 3, 2024 19:21
@Nigusu-Allehu Nigusu-Allehu added this to the 6.12 milestone Sep 5, 2024
@Nigusu-Allehu Nigusu-Allehu changed the title Discover Net tools installed plugins Discover plugins installed using Net tools Sep 9, 2024
@nkolev92 nkolev92 added the Merge next release PRs that should not be merged until the dev branch targets the next release label Sep 19, 2024
@nkolev92 nkolev92 removed the Merge next release PRs that should not be merged until the dev branch targets the next release label Sep 27, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed and removed Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed labels Oct 4, 2024
}

[PlatformFact(Platform.Windows)]
public void GetNetToolsPluginFiles_WithNuGetPluginPaths_ReturnsPluginsInNuGetPluginPathOnly()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test priority of the discovery methods we have. This test makes sure we prioritize the environmental variables.

Copy link
Contributor

@kartheekp-ms kartheekp-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress. Left few comments on the new changes proposed.

Copy link
Contributor

@jgonz120 jgonz120 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. There were a couple of instances where you're checking for null results from private/internal methods which don't return null.

src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs Outdated Show resolved Hide resolved
src/NuGet.Core/NuGet.Protocol/Plugins/PluginDiscoverer.cs Outdated Show resolved Hide resolved
File.Create(pluginFilePath);

// Remove execute permissions
var process = new Process();
Copy link
Contributor

@kartheekp-ms kartheekp-ms Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: There is an opportunity to refactor here because we set/remove execute permissions for files in all the new tests. I think we can create a private utility method and invoke it from the tests as needed. Please feel free to address it a follow-up issue.

@Nigusu-Allehu Nigusu-Allehu merged commit 6c1f792 into dev-feature-dot-net-tool-plugin-support Oct 22, 2024
25 of 31 checks passed
@Nigusu-Allehu Nigusu-Allehu deleted the dev-nyenework-net-tools-plugin branch October 22, 2024 18:52
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.WaitForExit();
Copy link
Contributor

@kartheekp-ms kartheekp-ms Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that Process.WaitForExit waits indefinitely for the process to exit, while addressing this comment you might want to consider this code by changing it to the following:

Assert.True(process.WaitForExit(1000), userMessage: "some string that helps to troubleshoot the issue");

With this approach, the test fails gracefully if the process doesn't complete on time for any unknown reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants