This commit adds a new flag to the `vagrant validate` command which allows users to completely ignore the provider block of a config file. This is useful for when you are running `vagrant validate` in CI and don't want to install a valid provider to check the syntax of your Vagratnfile. When the flag is invoked, a warning will be displayed saying that the provider block will be ignored and not validated.
31 lines
793 B
Ruby
31 lines
793 B
Ruby
require "vagrant/util/template_renderer"
|
|
|
|
module Vagrant
|
|
module Action
|
|
module Builtin
|
|
# This class validates the configuration and raises an exception
|
|
# if there are any validation errors.
|
|
class ConfigValidate
|
|
def initialize(app, env)
|
|
@app = app
|
|
end
|
|
|
|
def call(env)
|
|
if !env.key?(:config_validate) || env[:config_validate]
|
|
errors = env[:machine].config.validate(env[:machine], env[:ignore_provider])
|
|
|
|
if errors && !errors.empty?
|
|
raise Errors::ConfigInvalid,
|
|
errors: Util::TemplateRenderer.render(
|
|
"config/validation_failed",
|
|
errors: errors)
|
|
end
|
|
end
|
|
|
|
@app.call(env)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|