Validate plugin sources and report errors if detected.
This commit is contained in:
parent
147b7e3275
commit
df069deac0
|
@ -19,13 +19,15 @@ module Vagrant
|
|||
# all Vagrant-installed plugins.
|
||||
class Bundler
|
||||
|
||||
# Location of HashiCorp gem repository
|
||||
HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze
|
||||
|
||||
# Default gem repositories
|
||||
DEFAULT_GEM_SOURCES = [
|
||||
"https://rubygems.org/".freeze,
|
||||
"https://gems.hashicorp.com/".freeze
|
||||
HASHICORP_GEMSTORE
|
||||
].freeze
|
||||
|
||||
HASHICORP_GEMSTORE = "https://gems.hashicorp.com/".freeze
|
||||
|
||||
def self.instance
|
||||
@bundler ||= self.new
|
||||
end
|
||||
|
@ -262,6 +264,9 @@ module Vagrant
|
|||
@logger.debug("Adding source - #{src}")
|
||||
Gem.sources << src
|
||||
end
|
||||
|
||||
validate_configured_sources!
|
||||
|
||||
source_list.values.each{|srcs| srcs.delete_if{|src| default_sources.include?(src)}}
|
||||
installer_set.prefer_sources = source_list
|
||||
|
||||
|
@ -321,6 +326,27 @@ module Vagrant
|
|||
list.values
|
||||
end
|
||||
|
||||
# Iterates each configured RubyGem source to validate that it is properly
|
||||
# available. If source is unavailable an exception is raised.
|
||||
def validate_configured_sources!
|
||||
Gem.sources.each_source do |src|
|
||||
begin
|
||||
src.load_specs(:released)
|
||||
rescue Gem::Exception => source_error
|
||||
if ENV["VAGRANT_ALLOW_PLUGIN_SOURCE_ERRORS"]
|
||||
@logger.warn("Failed to load configured plugin source: #{src}!")
|
||||
@logger.warn("Error received attempting to load source (#{src}): #{source_error}")
|
||||
@logger.warn("Ignoring plugin source load failure due user request via env variable")
|
||||
else
|
||||
@logger.error("Failed to load configured plugin source `#{src}`: #{source_error}")
|
||||
raise Vagrant::Errors::PluginSourceError,
|
||||
source: src.uri.to_s,
|
||||
error_msg: source_error.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Generate the builtin resolver set
|
||||
def generate_builtin_set
|
||||
builtin_set = BuiltinSet.new
|
||||
|
|
|
@ -596,6 +596,10 @@ module Vagrant
|
|||
error_key(:plugin_init_error)
|
||||
end
|
||||
|
||||
class PluginSourceError < VagrantError
|
||||
error_key(:plugin_source_error)
|
||||
end
|
||||
|
||||
class PushesNotDefined < VagrantError
|
||||
error_key(:pushes_not_defined)
|
||||
end
|
||||
|
|
|
@ -3,10 +3,7 @@ module VagrantPlugins
|
|||
module Command
|
||||
module MixinInstallOpts
|
||||
def build_install_opts(o, options)
|
||||
options[:plugin_sources] = [
|
||||
"https://rubygems.org",
|
||||
"https://gems.hashicorp.com",
|
||||
]
|
||||
options[:plugin_sources] = Vagrant::Bundler::DEFAULT_GEM_SOURCES.dup
|
||||
|
||||
o.on("--entry-point NAME", String,
|
||||
"The name of the entry point file for loading the plugin.") do |entry_point|
|
||||
|
|
|
@ -43,7 +43,11 @@ module VagrantPlugins
|
|||
# Clear the sources so that installation uses custom sources
|
||||
old_sources = Gem.sources
|
||||
Gem.sources = Gem.default_sources
|
||||
Gem.sources << "https://gems.hashicorp.com"
|
||||
Vagrant::Bundler::DEFAULT_GEM_SOURCES.each do |source|
|
||||
if !Gem.sources.include?(source)
|
||||
Gem.sources << source
|
||||
end
|
||||
end
|
||||
|
||||
# Use a silent UI so that we have no output
|
||||
Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) do
|
||||
|
|
|
@ -1020,6 +1020,16 @@ en:
|
|||
You can however, install a plugin with the same name to replace
|
||||
these plugins. User-installed plugins take priority over
|
||||
system-installed plugins.
|
||||
plugin_source_error: |-
|
||||
Vagrant failed to load a configured plugin source. This can be caused
|
||||
by a variety of issues including: transient connectivity issues, proxy
|
||||
filtering rejecting access to a configured plugin source, or a configured
|
||||
plugin source not responding correctly. Please review the error message
|
||||
below to help resolve the issue:
|
||||
|
||||
%{error_msg}
|
||||
|
||||
Source: %{source}
|
||||
pushes_not_defined: |-
|
||||
The Vagrantfile does not define any 'push' strategies. In order to use
|
||||
`vagrant push`, you must define at least one push strategy:
|
||||
|
@ -1985,7 +1995,7 @@ en:
|
|||
untar_failure: |-
|
||||
The box failed to unpackage properly. Please verify that the box
|
||||
file you're trying to add is not corrupted and that enough disk space
|
||||
is available and then try again.
|
||||
is available and then try again.
|
||||
The output from attempting to unpackage (if any):
|
||||
|
||||
%{output}
|
||||
|
|
Loading…
Reference in New Issue