lib/vagrant.rb in vagrant-unbundled-2.1.4.0 vs lib/vagrant.rb in vagrant-unbundled-2.2.0.0

- old
+ new

@@ -1,9 +1,18 @@ -require "vagrant/shared_helpers" +require "log4r" +require "vagrant/util/credential_scrubber" +# Update the default formatter within the log4r library to ensure +# sensitive values are being properly scrubbed from logger data +class Log4r::BasicFormatter + alias_method :vagrant_format_object, :format_object + def format_object(obj) + Vagrant::Util::CredentialScrubber.desensitize(vagrant_format_object(obj)) + end +end +require "vagrant/shared_helpers" require "rubygems" -require "log4r" require "vagrant/util" require "vagrant/plugin/manager" # Enable logging if it is requested. We do this before # anything else so that we can setup the output before @@ -38,20 +47,34 @@ end # Set the logging level on all "vagrant" namespaced # logs as long as we have a valid level. if level - logger = Log4r::Logger.new("vagrant") + # NOTE: We must do this little hack to allow + # rest-client to write using the `<<` operator. + # See https://github.com/rest-client/rest-client/issues/34#issuecomment-290858 + # for more information + class VagrantLogger < Log4r::Logger + def << (msg) + debug(msg.strip) + end + end + logger = VagrantLogger.new("vagrant") logger.outputters = Log4r::Outputter.stderr logger.level = level base_formatter = Log4r::BasicFormatter.new if ENV["VAGRANT_LOG_TIMESTAMP"] base_formatter = Log4r::PatternFormatter.new( pattern: "%d [%5l] %m", date_pattern: "%F %T" ) end + # Vagrant Cloud gem uses RestClient to make HTTP requests, so + # log them if debug is enabled and use Vagrants logger + require 'rest_client' + RestClient.log = logger + Log4r::Outputter.stderr.formatter = Vagrant::Util::LoggingFormatter.new(base_formatter) logger = nil end end @@ -149,20 +172,13 @@ if !version # We check the plugin names first because those are cheaper to check return true if plugin("2").manager.registered.any? { |p| p.name == name } end - # Make the requirement object - version = Gem::Requirement.new([version]) if version - # Now check the plugin gem names require "vagrant/plugin/manager" - Plugin::Manager.instance.installed_specs.any? do |s| - match = s.name == name - next match if !version - next match && version.satisfied_by?(s.version) - end + Plugin::Manager.instance.plugin_installed?(name, version) end # Returns a superclass to use when creating a plugin for Vagrant. # Given a specific version, this returns a proper superclass to use # to register plugins for that version. @@ -200,10 +216,21 @@ puts "Vagrant.require_plugin is deprecated and has no effect any longer." puts "Use `vagrant plugin` commands to manage plugins. This warning will" puts "be removed in the next version of Vagrant." end + # This checks if Vagrant is installed in a specific version. + # + # Example: + # + # Vagrant.version?(">= 2.1.0") + # + def self.version?(*requirements) + req = Gem::Requirement.new(*requirements) + req.satisfied_by?(Gem::Version.new(VERSION)) + end + # This allows a Vagrantfile to specify the version of Vagrant that is # required. You can specify a list of requirements which will all be checked # against the running Vagrant version. # # This should be specified at the _top_ of any Vagrantfile. @@ -216,11 +243,10 @@ # def self.require_version(*requirements) logger = Log4r::Logger.new("vagrant::root") logger.info("Version requirements from Vagrantfile: #{requirements.inspect}") - req = Gem::Requirement.new(*requirements) - if req.satisfied_by?(Gem::Version.new(VERSION)) + if version?(*requirements) logger.info(" - Version requirements satisfied!") return end raise Errors::VagrantVersionBad,