Builtin: ConfigValidate will validate your configuration
This commit is contained in:
parent
37e36010e0
commit
7f55d5eac8
|
@ -12,6 +12,7 @@ module Vagrant
|
||||||
autoload :BoxAdd, "vagrant/action/builtin/box_add"
|
autoload :BoxAdd, "vagrant/action/builtin/box_add"
|
||||||
autoload :Call, "vagrant/action/builtin/call"
|
autoload :Call, "vagrant/action/builtin/call"
|
||||||
autoload :Confirm, "vagrant/action/builtin/confirm"
|
autoload :Confirm, "vagrant/action/builtin/confirm"
|
||||||
|
autoload :ConfigValidate, "vagrant/action/builtin/config_validate"
|
||||||
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
autoload :EnvSet, "vagrant/action/builtin/env_set"
|
||||||
autoload :Provision, "vagrant/action/builtin/provision"
|
autoload :Provision, "vagrant/action/builtin/provision"
|
||||||
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
|
||||||
|
@ -20,7 +21,6 @@ module Vagrant
|
||||||
|
|
||||||
module General
|
module General
|
||||||
autoload :Package, 'vagrant/action/general/package'
|
autoload :Package, 'vagrant/action/general/package'
|
||||||
autoload :Validate, 'vagrant/action/general/validate'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is the action that will add a box from a URL. This middleware
|
# This is the action that will add a box from a URL. This middleware
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
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.has_key?(:config_validate) || env[:config_validate]
|
||||||
|
errors = env[:machine].config.validate(env[:machine])
|
||||||
|
|
||||||
|
if errors
|
||||||
|
raise Errors::ConfigInvalid,
|
||||||
|
:errors => Util::TemplateRenderer.render(
|
||||||
|
"config/validation_failed",
|
||||||
|
:errors => errors)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,21 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Action
|
|
||||||
module General
|
|
||||||
# Simply validates the configuration of the current Vagrant
|
|
||||||
# environment.
|
|
||||||
class Validate
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
if !env.has_key?(:validate) || env[:validate]
|
|
||||||
env[:machine].config.validate!(env[:machine].env)
|
|
||||||
end
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -150,6 +150,10 @@ module Vagrant
|
||||||
error_key(:cli_invalid_options)
|
error_key(:cli_invalid_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ConfigInvalid < VagrantError
|
||||||
|
error_key(:config_invalid)
|
||||||
|
end
|
||||||
|
|
||||||
class DestroyRequiresForce < VagrantError
|
class DestroyRequiresForce < VagrantError
|
||||||
status_code(74)
|
status_code(74)
|
||||||
error_key(:destroy_requires_force)
|
error_key(:destroy_requires_force)
|
||||||
|
|
|
@ -40,7 +40,7 @@ module VagrantPlugins
|
||||||
# validate the configuration here, and we don't want to confirm
|
# validate the configuration here, and we don't want to confirm
|
||||||
# we want to destroy.
|
# we want to destroy.
|
||||||
destroy_env = env.clone
|
destroy_env = env.clone
|
||||||
destroy_env[:validate] = false
|
destroy_env[:config_validate] = false
|
||||||
destroy_env[:force_confirm_destroy] = true
|
destroy_env[:force_confirm_destroy] = true
|
||||||
env[:action_runner].run(Action.action_destroy, destroy_env)
|
env[:action_runner].run(Action.action_destroy, destroy_env)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<% errors.each do |key, container| -%>
|
<% errors.each do |section, list| -%>
|
||||||
<%= key %>:
|
<%= section %>:
|
||||||
<% container.errors.each do |error| -%>
|
<% list.each do |error| -%>
|
||||||
* <%= error %>
|
* <%= error %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,11 @@ en:
|
||||||
available below.
|
available below.
|
||||||
|
|
||||||
%{help}
|
%{help}
|
||||||
|
config_invalid: |-
|
||||||
|
There are errors in the configuration of this machine. Please fix
|
||||||
|
the following errors and try again:
|
||||||
|
|
||||||
|
%{errors}
|
||||||
destroy_requires_force: |-
|
destroy_requires_force: |-
|
||||||
Destroy doesn't have a TTY to ask for confirmation. Please pass the
|
Destroy doesn't have a TTY to ask for confirmation. Please pass the
|
||||||
`--force` flag to force a destroy, otherwise attach a TTY so that
|
`--force` flag to force a destroy, otherwise attach a TTY so that
|
||||||
|
|
Loading…
Reference in New Issue