2012-11-07 05:28:44 +00:00
|
|
|
require "vagrant"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Kernel_V2
|
|
|
|
class VagrantConfig < Vagrant.plugin("2", :config)
|
|
|
|
attr_accessor :host
|
2018-01-15 15:23:47 +00:00
|
|
|
attr_accessor :sensitive
|
2018-05-10 19:03:21 +00:00
|
|
|
attr_accessor :plugins
|
|
|
|
|
|
|
|
VALID_PLUGIN_KEYS = [:sources, :version, :entry_point].freeze
|
2013-04-03 23:18:37 +00:00
|
|
|
|
2014-01-08 03:11:08 +00:00
|
|
|
def initialize
|
|
|
|
@host = UNSET_VALUE
|
2018-01-15 15:23:47 +00:00
|
|
|
@sensitive = UNSET_VALUE
|
2018-05-10 19:03:21 +00:00
|
|
|
@plugins = UNSET_VALUE
|
2014-01-08 03:11:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2014-02-05 23:35:37 +00:00
|
|
|
@host = :detect if @host == UNSET_VALUE
|
2014-01-08 03:11:08 +00:00
|
|
|
@host = @host.to_sym if @host
|
2018-01-15 15:23:47 +00:00
|
|
|
@sensitive = nil if @sensitive == UNSET_VALUE
|
2018-05-10 19:03:21 +00:00
|
|
|
if @plugins == UNSET_VALUE
|
|
|
|
@plugins = {}
|
|
|
|
else
|
|
|
|
@plugins = format_plugins(@plugins)
|
|
|
|
end
|
2018-01-15 15:23:47 +00:00
|
|
|
|
|
|
|
if @sensitive.is_a?(Array) || @sensitive.is_a?(String)
|
|
|
|
Array(@sensitive).each do |value|
|
|
|
|
Vagrant::Util::CredentialScrubber.sensitive(value.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-10 19:03:21 +00:00
|
|
|
# Validate the configuration
|
|
|
|
#
|
|
|
|
# @param [Vagrant::Machine, NilClass] machine Machine instance or nil
|
|
|
|
# @return [Hash]
|
2018-01-15 15:23:47 +00:00
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
|
|
|
if @sensitive && (!@sensitive.is_a?(Array) && !@sensitive.is_a?(String))
|
|
|
|
errors << I18n.t("vagrant.config.root.sensitive_bad_type")
|
|
|
|
end
|
2018-05-10 19:03:21 +00:00
|
|
|
|
|
|
|
@plugins.each do |plugin_name, plugin_info|
|
|
|
|
invalid_keys = plugin_info.keys - VALID_PLUGIN_KEYS
|
|
|
|
if !invalid_keys.empty?
|
|
|
|
errors << I18n.t("vagrant.config.root.plugins_bad_key",
|
|
|
|
plugin_name: plugin_name,
|
|
|
|
plugin_key: invalid_keys.join(", ")
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-15 15:23:47 +00:00
|
|
|
{"vagrant" => errors}
|
2014-01-08 03:11:08 +00:00
|
|
|
end
|
|
|
|
|
2013-04-03 23:18:37 +00:00
|
|
|
def to_s
|
|
|
|
"Vagrant"
|
|
|
|
end
|
2018-05-10 19:03:21 +00:00
|
|
|
|
|
|
|
def format_plugins(val)
|
|
|
|
result = case val
|
|
|
|
when String
|
|
|
|
{val => {}}
|
|
|
|
when Array
|
|
|
|
Hash[val.map{|item| [item.to_s, {}]}]
|
|
|
|
else
|
|
|
|
val
|
|
|
|
end
|
|
|
|
result.keys.each do |key|
|
|
|
|
result[key] = Hash[result[key].map{|k,v| [k.to_sym, v]}]
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2012-11-07 05:28:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|