class Vagrant::Util::CredentialScrubber
Utility class to remove credential information from strings
Constants
- REPLACEMENT_TEXT
String used to replace credential information
Public Class Methods
desensitize(string)
click to toggle source
Remove sensitive information from string
@param [String] string @return [String]
# File lib/vagrant/util/credential_scrubber.rb, line 32 def self.desensitize(string) string = string.to_s.dup sensitive_strings.each do |remove| string.gsub!(/(\W|^)#{Regexp.escape(remove)}(\W|$)/, "\\1#{REPLACEMENT_TEXT}\\2") end string end
reset!()
click to toggle source
@private Reset the cached values for scrubber. This is not considered a public API and should only be used for testing.
# File lib/vagrant/util/credential_scrubber.rb, line 66 def self.reset! instance_variables.each(&method(:remove_instance_variable)) end
scrub(string)
click to toggle source
Attempt to remove detected credentials from string
@param [String] string @return [String]
# File lib/vagrant/util/credential_scrubber.rb, line 12 def self.scrub(string) string = url_scrubber(string) end
sensitive(string)
click to toggle source
Register a sensitive string to be scrubbed
# File lib/vagrant/util/credential_scrubber.rb, line 41 def self.sensitive(string) string = string.to_s.dup if string.length > 0 sensitive_strings.push(string).uniq! end nil end
sensitive_strings()
click to toggle source
@return [Array<string>]
# File lib/vagrant/util/credential_scrubber.rb, line 56 def self.sensitive_strings if !defined?(@_sensitive_strings) @_sensitive_strings = [] end @_sensitive_strings end
unsensitive(string)
click to toggle source
Deregister a sensitive string and allow output
# File lib/vagrant/util/credential_scrubber.rb, line 50 def self.unsensitive(string) sensitive_strings.delete(string) nil end
url_scrubber(string)
click to toggle source
Detect URLs and remove any embedded credentials
@param [String] string @return [String]
# File lib/vagrant/util/credential_scrubber.rb, line 20 def self.url_scrubber(string) string.gsub(%r{(ftp|https?)://[^\s]+@[^\s]+}) do |address| uri = URI.parse(address) uri.user = uri.password = REPLACEMENT_TEXT uri.to_s end end