From 5b0abba9317f206913cf2e599d0dac7e9dbd0baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 21 Apr 2021 13:54:29 +0200 Subject: Sync bundler & rubygems --- lib/bundler/settings.rb | 69 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 9 deletions(-) (limited to 'lib/bundler/settings.rb') diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index f59ae37eed..e9155acf48 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -13,6 +13,7 @@ module Bundler auto_install cache_all cache_all_platforms + clean default_install_uses_path deployment disable_checksum_validation @@ -25,11 +26,14 @@ module Bundler force_ruby_platform forget_cli_options frozen + gem.changelog gem.coc gem.mit + git.allow_insecure global_gem_cache ignore_messages init_gems_rb + inline no_install no_prune path_relative_to_cwd @@ -59,6 +63,22 @@ module Bundler without ].freeze + STRING_KEYS = %w[ + bin + cache_path + console + gem.ci + gem.github_username + gem.linter + gem.rubocop + gem.test + gemfile + path + shebang + system_bindir + trust-policy + ].freeze + DEFAULT_CONFIG = { "BUNDLE_SILENCE_DEPRECATIONS" => false, "BUNDLE_DISABLE_VERSION_CHECK" => true, @@ -124,8 +144,8 @@ module Bundler keys = @temporary.keys | @global_config.keys | @local_config.keys | @env_config.keys keys.map do |key| - key.sub(/^BUNDLE_/, "").gsub(/__/, ".").downcase - end + key.sub(/^BUNDLE_/, "").gsub(/___/, "-").gsub(/__/, ".").downcase + end.sort end def local_overrides @@ -171,19 +191,19 @@ module Bundler locations = [] if value = @temporary[key] - locations << "Set for the current command: #{converted_value(value, exposed_key).inspect}" + locations << "Set for the current command: #{printable_value(value, exposed_key).inspect}" end if value = @local_config[key] - locations << "Set for your local app (#{local_config_file}): #{converted_value(value, exposed_key).inspect}" + locations << "Set for your local app (#{local_config_file}): #{printable_value(value, exposed_key).inspect}" end if value = @env_config[key] - locations << "Set via #{key}: #{converted_value(value, exposed_key).inspect}" + locations << "Set via #{key}: #{printable_value(value, exposed_key).inspect}" end if value = @global_config[key] - locations << "Set for the current user (#{global_config_file}): #{converted_value(value, exposed_key).inspect}" + locations << "Set for the current user (#{global_config_file}): #{printable_value(value, exposed_key).inspect}" end return ["You have not configured a value for `#{exposed_key}`"] if locations.empty? @@ -275,9 +295,7 @@ module Bundler end def key_for(key) - key = Settings.normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key - key = key.to_s.gsub(".", "__").upcase - "BUNDLE_#{key}" + self.class.key_for(key) end private @@ -312,6 +330,10 @@ module Bundler BOOL_KEYS.include?(name.to_s) || BOOL_KEYS.include?(parent_setting_for(name.to_s)) end + def is_string(name) + STRING_KEYS.include?(name.to_s) || name.to_s.start_with?("local.") || name.to_s.start_with?("mirror.") || name.to_s.start_with?("build.") + end + def to_bool(value) case value when nil, /\A(false|f|no|n|0|)\z/i, false @@ -329,6 +351,14 @@ module Bundler ARRAY_KEYS.include?(key.to_s) end + def is_credential(key) + key == "gem.push_key" + end + + def is_userinfo(value) + value.include?(":") + end + def to_array(value) return [] unless value value.split(":").map(&:to_sym) @@ -375,6 +405,21 @@ module Bundler end end + def printable_value(value, key) + converted = converted_value(value, key) + return converted unless converted.is_a?(String) + + if is_string(key) + converted + elsif is_credential(key) + "[REDACTED]" + elsif is_userinfo(converted) + converted.gsub(/:.*$/, ":[REDACTED]") + else + converted + end + end + def global_config_file if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty? Pathname.new(ENV["BUNDLE_CONFIG"]) @@ -414,6 +459,12 @@ module Bundler \z /ix.freeze + def self.key_for(key) + key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key + key = key.to_s.gsub(".", "__").gsub("-", "___").upcase + "BUNDLE_#{key}" + end + # TODO: duplicates Rubygems#normalize_uri # TODO: is this the correct place to validate mirror URIs? def self.normalize_uri(uri) -- cgit v1.2.3