Sha256: 2476bed14c38c9b4ee937ea7d22c5030d94d9af9ae02bb9e261c203783cebd4e

Contents?: true

Size: 1.65 KB

Versions: 29

Compression:

Stored size: 1.65 KB

Contents

# encoding: utf-8
require "logstash/namespace"
require "logstash/util"

# This class exists to quietly wrap a password string so that, when printed or
# logged, you don't accidentally print the password itself.
class LogStash::Util::SafeURI
  PASS_PLACEHOLDER = "xxxxxx".freeze
  HOSTNAME_PORT_REGEX=/\A(?<hostname>([A-Za-z0-9\.\-]+)|\[[0-9A-Fa-f\:]+\])(:(?<port>\d+))?\Z/
  
  extend Forwardable
  
  def_delegators :@uri, :coerce, :query=, :route_from, :port=, :default_port, :select, :normalize!, :absolute?, :registry=, :path, :password, :hostname, :merge, :normalize, :host, :component_ary, :userinfo=, :query, :set_opaque, :+, :merge!, :-, :password=, :parser, :port, :set_host, :set_path, :opaque=, :scheme, :fragment=, :set_query, :set_fragment, :userinfo, :hostname=, :set_port, :path=, :registry, :opaque, :route_to, :set_password, :hierarchical?, :set_user, :set_registry, :set_userinfo, :fragment, :component, :user=, :set_scheme, :absolute, :host=, :relative?, :scheme=, :user
  
  attr_reader :uri
  
  public
  def initialize(arg)    
    @uri = case arg
           when String
             arg = "//#{arg}" if HOSTNAME_PORT_REGEX.match(arg)
             URI.parse(arg)
           when URI
             arg
           else
             raise ArgumentError, "Expected a string or URI, got a #{arg.class} creating a URL"
           end
  end

  def to_s
    sanitized.to_s
  end

  def inspect
    sanitized.to_s
  end

  def sanitized
    return uri unless uri.password # nothing to sanitize here!
    
    safe = uri.clone
    safe.password = PASS_PLACEHOLDER
    safe
  end

  def ==(other)
    other.is_a?(::LogStash::Util::SafeURI) ? @uri == other.uri : false
  end
end

Version data entries

29 entries across 29 versions & 6 rubygems

Version Path
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/logstash-core-5.0.0-java/lib/logstash/util/safe_uri.rb
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/logstash-core-2.4.1-java/lib/logstash/util/safe_uri.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/logstash-core-2.4.1-java/lib/logstash/util/safe_uri.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/logstash-core-2.4.1-java/lib/logstash/util/safe_uri.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/logstash-core-2.4.1-java/lib/logstash/util/safe_uri.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/logstash-core-2.4.1-java/lib/logstash/util/safe_uri.rb
logstash-core-5.0.2-java lib/logstash/util/safe_uri.rb
logstash-core-5.0.1-java lib/logstash/util/safe_uri.rb
logstash-core-2.4.1-java lib/logstash/util/safe_uri.rb
logstash-core-5.0.0-java lib/logstash/util/safe_uri.rb
logstash-core-5.0.0.pre.rc1-java lib/logstash/util/safe_uri.rb
logstash-core-5.0.0.pre.beta1-java lib/logstash/util/safe_uri.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/logstash-core-5.0.0.alpha6.snapshot5-java/lib/logstash/util/safe_uri.rb