-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Cargo private registries (#8719)
* Add support for Rust alternative registries * Fix handling of missing source info in dependencies * Fixed calculation of crates dl URL * Minor cleanups * Fixes for crates-ms * Update to get interface with private registry (tested with Cloudsmith) working * Try to handle the case of updating versions for private registries * Fix up some tests for fetching Cargo config file * Sorbet typechecking adjustments * Refactor sparse registry details to method * Expect Cargo config file to be fetched in FileFetcher spec * Revert changes to base Gitlab metadata finder made in feature base PR * Enable using index URL to fetch crate metadata from private registry * Remove special case for Microsoft; we can/need to authenticate normally * Cargo prefers config.toml to have the extension * Fix typo in method name * Fix filename for fixture * Merge main into cargo-private-registries * Add a bit more spam in the DEBUG_HELPERS case. * Fix issues found in local testing, especially setting `CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDER=cargo:token`. * Style lint fixes * Simplify conditional logic to satisfy ABC linter --------- Co-authored-by: John Batty <john.batty@metaswitch.com> Co-authored-by: John Batty <johnbatty@microsoft.com> Co-authored-by: Ian Joiner <14581281+iajoiner@users.noreply.github.com> Co-authored-by: Rob Jellinghaus <rjelling@microsoft.com> Co-authored-by: AbdulFattaah Popoola <abdulapopoola@github.com>
- Loading branch information
1 parent
f3e2bec
commit b28ce2f
Showing
14 changed files
with
434 additions
and
74 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "yaml" | ||
|
||
module Dependabot | ||
module Cargo | ||
module Helpers | ||
def self.setup_credentials_in_environment(credentials) | ||
credentials.each do |cred| | ||
next if cred["type"] != "cargo_registry" | ||
|
||
# If there is a 'token' property, then apply it. | ||
# If there is not, it probably means we are running under dependabot-cli which stripped | ||
# all tokens. So in that case, we assume that the dependabot proxy will re-inject the | ||
# actual correct token, and we just use 'token' as a placeholder at this point. | ||
# (We must add these environment variables here, or 'cargo update' will not think it is | ||
# configured properly for the private registries.) | ||
|
||
token_env_var = "CARGO_REGISTRIES_#{cred['cargo_registry'].upcase.tr('-', '_')}_TOKEN" | ||
|
||
token = "placeholder_token" | ||
if cred["token"].nil? | ||
puts "Setting #{token_env_var} to 'placeholder_token' because dependabot-cli proxy will override it anyway" | ||
else | ||
token = cred["token"] | ||
puts "Setting #{token_env_var} to provided token value" | ||
end | ||
|
||
ENV[token_env_var] ||= token | ||
end | ||
|
||
# And set CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS here as well, so Cargo will expect tokens | ||
ENV["CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS"] ||= "cargo:token" | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/file_fetchers" | ||
require "dependabot/file_fetchers/base" | ||
|
||
module Dependabot | ||
module Cargo | ||
class RegistryFetcher < Dependabot::FileFetchers::Base | ||
def self.required_files_in?(filenames) | ||
filenames.include?("config.json") | ||
end | ||
|
||
def self.required_files_message | ||
"Repo must contain a config.json" | ||
end | ||
|
||
def dl | ||
parsed_config_json["dl"].chomp("/") | ||
end | ||
|
||
def api | ||
parsed_config_json["api"].chomp("/") | ||
end | ||
|
||
private | ||
|
||
def fetch_files | ||
fetched_files = [] | ||
fetched_files << config_json | ||
end | ||
|
||
def parsed_config_json | ||
@parsed_config_json ||= JSON.parse(config_json.content) | ||
end | ||
|
||
def config_json | ||
@config_json ||= fetch_file_from_host("config.json") | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.