Sha256: dee6ec53498e2e4b19d4faaa291877bf0de74cc928b56671558f171f74e4fa75

Contents?: true

Size: 1.56 KB

Versions: 40

Compression:

Stored size: 1.56 KB

Contents

# 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
            cache_uri = original_uri || uri

            uri_parts = [cache_uri.host, cache_uri.user, cache_uri.port, cache_uri.path]
            uri_digest = Digest::MD5.hexdigest(uri_parts.compact.join("."))

            uri_parts[-1] = uri_digest
            uri_parts.compact.join(".")
          end
        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

Version data entries

40 entries across 40 versions & 2 rubygems

Version Path
rubygems-update-2.6.14 bundler/lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.13 bundler/lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.12 bundler/lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.11 bundler/lib/bundler/source/rubygems/remote.rb
bundler-1.14.4 lib/bundler/source/rubygems/remote.rb
bundler-1.14.3 lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.10 bundler/lib/bundler/source/rubygems/remote.rb
bundler-1.14.2 lib/bundler/source/rubygems/remote.rb
bundler-1.14.1 lib/bundler/source/rubygems/remote.rb
bundler-1.14.0 lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.9 bundler/lib/bundler/source/rubygems/remote.rb
bundler-1.14.0.pre.2 lib/bundler/source/rubygems/remote.rb
bundler-1.14.0.pre.1 lib/bundler/source/rubygems/remote.rb
bundler-1.13.7 lib/bundler/source/rubygems/remote.rb
rubygems-update-2.6.8 bundler/lib/bundler/source/rubygems/remote.rb
bundler-1.13.6 lib/bundler/source/rubygems/remote.rb
bundler-1.13.5 lib/bundler/source/rubygems/remote.rb
bundler-1.13.4 lib/bundler/source/rubygems/remote.rb
bundler-1.13.3 lib/bundler/source/rubygems/remote.rb
bundler-1.12.6 lib/bundler/source/rubygems/remote.rb