-
Notifications
You must be signed in to change notification settings - Fork 1.3k
cargo: strip per-registry credential-provider from .cargo/config.toml #14356
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
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,21 @@ def self.bypass_cargo_credential_providers | |||||||||||||||||||||||||||||||||
| # shell (along with the appropriate CARGO_REGISTRIES_{NAME}_TOKEN vars) for local development without the proxy. | ||||||||||||||||||||||||||||||||||
| ENV["CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS"] ||= "" | ||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| sig { params(config_content: String).returns(String) } | ||||||||||||||||||||||||||||||||||
| def self.sanitize_cargo_config(config_content) | ||||||||||||||||||||||||||||||||||
| # Remove per-registry `credential-provider` settings from .cargo/config.toml. | ||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||
| # Users may configure their repos with lines like: | ||||||||||||||||||||||||||||||||||
| # [registries.my-registry] | ||||||||||||||||||||||||||||||||||
| # credential-provider = "cargo:token" | ||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||
| # These per-registry settings override the global CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS env var, | ||||||||||||||||||||||||||||||||||
| # causing Cargo to look up tokens via CARGO_REGISTRIES_{NAME}_TOKEN env vars. Since the dependabot proxy | ||||||||||||||||||||||||||||||||||
| # handles authentication by intercepting HTTP requests, we need to strip these so Cargo makes plain | ||||||||||||||||||||||||||||||||||
| # requests that the proxy can decorate with credentials. | ||||||||||||||||||||||||||||||||||
| config_content.gsub(/^\s*credential-provider\s*=.*$/, "") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| config_content.gsub(/^\s*credential-provider\s*=.*$/, "") | |
| current_section = nil | |
| sanitized_lines = config_content.lines.each_with_object([]) do |line, kept| | |
| if line =~ /^\s*\[(.+?)\]\s*$/ | |
| current_section = Regexp.last_match(1) | |
| end | |
| if current_section&.start_with?("registries.") && line =~ /^\s*credential-provider\s*=/ | |
| next | |
| end | |
| kept << line | |
| end | |
| sanitized_lines.join |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,7 +218,7 @@ def write_temporary_dependency_files(prepared: true) | |
| return unless config | ||
|
|
||
| FileUtils.mkdir_p(File.dirname(T.must(config).name)) | ||
| File.write(T.must(config).name, T.must(config).content) | ||
| File.write(T.must(config).name, Helpers.sanitize_cargo_config(T.must(T.must(config).content))) | ||
|
Comment on lines
220
to
+221
|
||
| end | ||
|
|
||
| sig { void } | ||
|
|
||
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
T.must(T.must(config).content)nesting makes the write path harder to read. Consider assigningconfig_file = T.must(config)andcontent = T.must(config_file.content)(or similar) before callingsanitize_cargo_configso the nil assertions are clearer.See below for a potential fix: