2014-11-14 20:51:35 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module LocalExecPush
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
2014-11-17 18:16:39 +00:00
|
|
|
# The path (relative to the machine root) to a local script that will be
|
|
|
|
# executed.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :script
|
|
|
|
|
2014-11-14 20:51:35 +00:00
|
|
|
# The command (as a string) to execute.
|
|
|
|
# @return [String]
|
2014-11-17 18:16:39 +00:00
|
|
|
attr_accessor :inline
|
2014-11-14 20:51:35 +00:00
|
|
|
|
2015-12-10 07:58:02 +00:00
|
|
|
# The arguments to provide when executing the script.
|
|
|
|
# @return [Array<String>]
|
|
|
|
attr_accessor :args
|
|
|
|
|
2014-11-14 20:51:35 +00:00
|
|
|
def initialize
|
2014-11-17 18:16:39 +00:00
|
|
|
@script = UNSET_VALUE
|
|
|
|
@inline = UNSET_VALUE
|
2015-12-10 07:58:02 +00:00
|
|
|
@args = UNSET_VALUE
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2014-11-17 18:16:39 +00:00
|
|
|
@script = nil if @script == UNSET_VALUE
|
|
|
|
@inline = nil if @inline == UNSET_VALUE
|
2015-12-10 07:58:02 +00:00
|
|
|
@args = nil if @args == UNSET_VALUE
|
|
|
|
|
|
|
|
if @args && args_valid?
|
|
|
|
@args = @args.is_a?(Array) ? @args.map { |a| a.to_s } : @args.to_s
|
|
|
|
end
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
2014-11-17 18:16:39 +00:00
|
|
|
if missing?(@script) && missing?(@inline)
|
2014-11-14 20:51:35 +00:00
|
|
|
errors << I18n.t("local_exec_push.errors.missing_attribute",
|
2014-11-17 18:16:39 +00:00
|
|
|
attribute: "script",
|
2014-11-14 20:51:35 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-11-17 18:16:39 +00:00
|
|
|
if !missing?(@script) && !missing?(@inline)
|
|
|
|
errors << I18n.t("local_exec_push.errors.cannot_specify_script_and_inline")
|
|
|
|
end
|
|
|
|
|
2015-12-10 07:58:02 +00:00
|
|
|
if !args_valid?
|
|
|
|
errors << I18n.t("local_exec_push.errors.args_bad_type")
|
|
|
|
end
|
|
|
|
|
2014-11-14 20:51:35 +00:00
|
|
|
{ "Local Exec push" => errors }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Determine if the given string is "missing" (blank)
|
|
|
|
# @return [true, false]
|
|
|
|
def missing?(obj)
|
|
|
|
obj.to_s.strip.empty?
|
|
|
|
end
|
2015-12-10 07:58:02 +00:00
|
|
|
|
|
|
|
# Args are optional, but if they're provided we only support them as a
|
|
|
|
# string or as an array.
|
|
|
|
def args_valid?
|
|
|
|
return true if !args
|
|
|
|
return true if args.is_a?(String)
|
2017-02-14 09:13:29 +00:00
|
|
|
return true if args.is_a?(Integer)
|
2015-12-10 07:58:02 +00:00
|
|
|
if args.is_a?(Array)
|
|
|
|
args.each do |a|
|
2017-02-14 09:13:29 +00:00
|
|
|
return false if !a.kind_of?(String) && !a.kind_of?(Integer)
|
2015-12-10 07:58:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2014-11-14 20:51:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|