Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5608 - bundler:seg-config-mirror-fallback-timeout, r=i…
Browse files Browse the repository at this point in the history
…ndirect

[Settings] Allow configuring a mirror fallback timeout without a trailing slash

Closes #4830
  • Loading branch information
bundlerbot committed Apr 27, 2017
2 parents 8552918 + f4fb8cb commit b2efb3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/bundler/mirror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ def parse(key, value)
mirror = if config.all?
@all
else
(@mirrors[config.uri] = @mirrors[config.uri] || Mirror.new)
@mirrors[config.uri] ||= Mirror.new
end
config.update_mirror(mirror)
end

private

def fetch_valid_mirror_for(uri)
mirror = (@mirrors[URI(uri.to_s.downcase)] || @mirrors[URI(uri.to_s).host] || Mirror.new(uri)).validate!(@prober)
mirror = @mirrors[uri.to_s.downcase] || @mirrors[URI(uri.to_s).host] || Mirror.new(uri)
mirror.validate!(@prober)
mirror = Mirror.new(uri) unless mirror.valid?
mirror
end
Expand All @@ -71,7 +72,7 @@ def uri=(uri)
@uri = if uri.nil?
nil
else
URI(uri.to_s)
URI(uri.to_s.downcase)
end
@valid = nil
end
Expand Down Expand Up @@ -117,7 +118,7 @@ class MirrorConfig

def initialize(config_line, value)
uri, fallback =
config_line.match(%r{^mirror\.(all|.+?)(\.fallback_timeout)?\/?$}).captures
config_line.match(%r{\Amirror\.(all|.+?)(\.fallback_timeout)?\/?\z}).captures
@fallback = !fallback.nil?
@all = false
if uri == "all"
Expand Down
24 changes: 21 additions & 3 deletions lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def credentials_for(uri)

def gem_mirrors
all.inject(Mirrors.new) do |mirrors, k|
mirrors.parse(k, self[k]) if k =~ /^mirror\./
mirrors.parse(k, self[k]) if k.start_with?("mirror.")
mirrors
end
end
Expand Down Expand Up @@ -321,16 +321,34 @@ def load_config(config_file)
end
end

PER_URI_OPTIONS = %w(
fallback_timeout
).freeze

NORMALIZE_URI_OPTIONS_PATTERN =
/
\A
(\w+\.)? # optional prefix key
(https?.*?) # URI
(\.#{Regexp.union(PER_URI_OPTIONS)})? # optional suffix key
\z
/ix

# TODO: duplicates Rubygems#normalize_uri
# TODO: is this the correct place to validate mirror URIs?
def self.normalize_uri(uri)
uri = uri.to_s
uri = "#{uri}/" unless uri =~ %r{/\Z}
if uri =~ NORMALIZE_URI_OPTIONS_PATTERN
prefix = $1
uri = $2
suffix = $3
end
uri = "#{uri}/" unless uri.end_with?("/")
uri = URI(uri)
unless uri.absolute?
raise ArgumentError, format("Gem sources must be absolute. You provided '%s'.", uri)
end
uri
"#{prefix}#{uri}#{suffix}".downcase
end
end
end
10 changes: 10 additions & 0 deletions spec/bundler/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,16 @@
URI("http://rubygems-mirror.org/")
)
end

it "normalizes URIs with a fallback_timeout option" do
settings["mirror.https://rubygems.org/.fallback_timeout"] = "true"
expect(settings.all).to include("mirror.https://rubygems.org/.fallback_timeout")
end

it "normalizes URIs with a fallback_timeout option without a trailing slash" do
settings["mirror.https://rubygems.org.fallback_timeout"] = "true"
expect(settings.all).to include("mirror.https://rubygems.org/.fallback_timeout")
end
end

describe "BUNDLE_ keys format" do
Expand Down

0 comments on commit b2efb3d

Please sign in to comment.