-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use dotnet credential provider #8927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
module Dependabot | ||
module Nuget | ||
module NuGetConfigCredentialHelpers | ||
extend T::Sig | ||
|
||
def self.user_nuget_config_path | ||
home_directory = Dir.home | ||
File.join(home_directory, ".nuget", "NuGet", "NuGet.Config") | ||
|
@@ -48,6 +50,36 @@ def self.add_credentials_to_nuget_config(credentials) | |
File.write(user_nuget_config_path, nuget_config) | ||
end | ||
|
||
sig { params(credentials: T::Array[Dependabot::Credential]).returns(T::Hash[String, String]) } | ||
def self.get_credentials_to_credential_helper_env(credentials) | ||
env = {} | ||
|
||
nuget_credentials = credentials.select { |cred| cred["type"] == "nuget_feed" } | ||
|
||
if nuget_credentials.any? | ||
endpoint_credentials = [] | ||
|
||
nuget_credentials.each do |c| | ||
next unless c["token"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Azure DevOps feeds aren't necessarily private and authentication isn't always specified via a |
||
|
||
exploded_token = T.must(c["token"]).split(":", 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the above comment, this shouldn't assume a token will be of the form |
||
|
||
next unless exploded_token.length == 2 | ||
|
||
username = exploded_token[0] | ||
password = exploded_token[1] | ||
|
||
endpoint_credentials << <<~NUGET_ENDPOINT_CREDENTIAL | ||
{"endpoint":"#{c['url']}", "username":"#{username}", "password":"#{password}"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and a few lines below, use the endpoint_credentials << {
"endpoint" => c['url'],
"username" => username,
"password" => password,
} Then later on: env["VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"] = {
"endpointCredentials" => endpoint_credentials
}.to_json |
||
NUGET_ENDPOINT_CREDENTIAL | ||
end | ||
|
||
env["VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"] = "{\"endpointCredentials\": [#{endpoint_credentials.join(',')}]}" | ||
end | ||
|
||
env | ||
end | ||
|
||
def self.restore_user_nuget_config | ||
return unless File.exist?(temporary_nuget_config_path) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature only works with NuGet feeds from Azure DevOps, right? If that's the case it would be a good idea to filter
credentials
to only those feeds so you don't accidentally expose feeds/tokens that aren't ADO to the ADO service.If I recall, all Azure DevOps NuGet feeds look like
https://pkgs.dev.azure.com/...
orhttps://SOME-ORGANIZATION.pkgs.visualstudio.com/...
.