Sha256: dc409ff89820a9ca73b8949f1a5c1e5d0f650ef93f637e1d5c561ca010b25edc

Contents?: true

Size: 1.2 KB

Versions: 52

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Bundler
  module URICredentialsFilter
  module_function

    def credential_filtered_uri(uri_to_anonymize)
      return uri_to_anonymize if uri_to_anonymize.nil?
      uri = uri_to_anonymize.dup
      uri = URI(uri.to_s) unless uri.is_a?(URI)
      if uri.userinfo
        # oauth authentication
        if uri.password == "x-oauth-basic" || uri.password == "x"
          # URI as string does not display with password if no user is set
          oauth_designation = uri.password
          uri.user = oauth_designation
        end
        uri.password = nil
      end
      return uri if uri_to_anonymize.is_a?(URI)
      return uri.to_s if uri_to_anonymize.is_a?(String)
    rescue URI::InvalidURIError # uri is not canonical uri scheme
      uri
    end

    def credential_filtered_string(str_to_filter, uri)
      return str_to_filter if uri.nil? || str_to_filter.nil?
      str_with_no_credentials = str_to_filter.dup
      anonymous_uri_str = credential_filtered_uri(uri).to_s
      uri_str = uri.to_s
      if anonymous_uri_str != uri_str
        str_with_no_credentials = str_with_no_credentials.gsub(uri_str, anonymous_uri_str)
      end
      str_with_no_credentials
    end
  end
end

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
rubygems-update-3.0.9 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-2.7.11 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.8 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.7 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.1.0.pre3 bundler/lib/bundler/uri_credentials_filter.rb
bundler-2.1.0.pre.3 lib/bundler/uri_credentials_filter.rb
rubygems-update-3.1.0.pre2 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.1.0.pre1 bundler/lib/bundler/uri_credentials_filter.rb
bundler-2.1.0.pre.2 lib/bundler/uri_credentials_filter.rb
bundler-2.1.0.pre.1 lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.6 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.5 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.4 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-2.7.10 bundler/lib/bundler/uri_credentials_filter.rb
bundler-2.0.2 lib/bundler/uri_credentials_filter.rb
rubygems-update-2.7.9 bundler/lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.3 bundler/lib/bundler/uri_credentials_filter.rb
bundler-2.0.1 lib/bundler/uri_credentials_filter.rb
bundler-2.0.0 lib/bundler/uri_credentials_filter.rb
rubygems-update-3.0.2 bundler/lib/bundler/uri_credentials_filter.rb