1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/bundler/source/rubygems/remote.rb
hsbt 59c8d50653 Added bundler as default gems. Revisit [Feature #12733]
* bin/*, lib/bundler/*, lib/bundler.rb, spec/bundler, man/*:
    Merge from latest stable branch of bundler/bundler repository and
    added workaround patches. I will backport them into upstream.
  * common.mk, defs/gmake.mk: Added `test-bundler` task for test suite
    of bundler.
  * tool/sync_default_gems.rb: Added sync task for bundler.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-02 23:07:56 +00:00

69 lines
1.9 KiB
Ruby

# frozen_string_literal: true
module Bundler
class Source
class Rubygems
class Remote
attr_reader :uri, :anonymized_uri, :original_uri
def initialize(uri)
orig_uri = uri
uri = Bundler.settings.mirror_for(uri)
@original_uri = orig_uri if orig_uri != uri
fallback_auth = Bundler.settings.credentials_for(uri)
@uri = apply_auth(uri, fallback_auth).freeze
@anonymized_uri = remove_auth(@uri).freeze
end
# @return [String] A slug suitable for use as a cache key for this
# remote.
#
def cache_slug
@cache_slug ||= begin
return nil unless SharedHelpers.md5_available?
cache_uri = original_uri || uri
# URI::File of Ruby 2.6 returns empty string when given "file://".
host = defined?(URI::File) && cache_uri.is_a?(URI::File) ? nil : cache_uri.host
uri_parts = [host, cache_uri.user, cache_uri.port, cache_uri.path]
uri_digest = SharedHelpers.digest(:MD5).hexdigest(uri_parts.compact.join("."))
uri_parts[-1] = uri_digest
uri_parts.compact.join(".")
end
end
def to_s
"rubygems remote at #{anonymized_uri}"
end
private
def apply_auth(uri, auth)
if auth && uri.userinfo.nil?
uri = uri.dup
uri.userinfo = auth
end
uri
rescue URI::InvalidComponentError
error_message = "Please CGI escape your usernames and passwords before " \
"setting them for authentication."
raise HTTPError.new(error_message)
end
def remove_auth(uri)
if uri.userinfo
uri = uri.dup
uri.user = uri.password = nil
end
uri
end
end
end
end
end