diff --git a/plugins/pushes/file/config.rb b/plugins/pushes/file/config.rb new file mode 100644 index 000000000..025ab78dd --- /dev/null +++ b/plugins/pushes/file/config.rb @@ -0,0 +1,26 @@ +module VagrantPlugins + module FileDeploy + class Config < Vagrant.plugin("2", :config) + attr_accessor :destination + + def initialize + @destination = UNSET_VALUE + end + + def finalize! + @destination = nil if @destination == UNSET_VALUE + end + + def validate(machine) + errors = _detected_errors + + # Validate that a destination was provided + if !destination + errors << I18n.t("vagrant.pushes.file.no_destination") + end + + { "File push" => errors } + end + end + end +end diff --git a/plugins/pushes/file/plugin.rb b/plugins/pushes/file/plugin.rb new file mode 100644 index 000000000..365e5e44c --- /dev/null +++ b/plugins/pushes/file/plugin.rb @@ -0,0 +1,23 @@ +require "vagrant" + +module VagrantPlugins + module FileDeploy + class Plugin < Vagrant.plugin("2") + name "file" + description <<-DESC + Deploy by pushing to a filepath on your local system or a remote share + attached to this system + DESC + + config(:file, :push) do + require File.expand_path("../config", __FILE__) + Config + end + + push(:file) do + require File.expand_path("../push", __FILE__) + Push + end + end + end +end diff --git a/plugins/pushes/file/push.rb b/plugins/pushes/file/push.rb new file mode 100644 index 000000000..662719ec5 --- /dev/null +++ b/plugins/pushes/file/push.rb @@ -0,0 +1,29 @@ +module VagrantPlugins + module FileDeploy + class Push < Vagrant.plugin("2", :push) + def push + @machine.communicate.tap do |comm| + destination = expand_guest_path(config.destination) + + # Make sure the remote path exists + command = "mkdir -p %s" % File.dirname(destination) + comm.execute(command) + + # Now push the deploy... + # ??? + end + end + + private + + # Expand the guest path if the guest has the capability + def expand_guest_path(destination) + if machine.guest.capability?(:shell_expand_guest_path) + machine.guest.capability(:shell_expand_guest_path, destination) + else + destination + end + end + end + end +end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 72124f7e9..bc3416529 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1892,3 +1892,7 @@ en: You must include both public and private keys. must_accept_keys: |- You must accept keys when running highstate with master! + + pushes: + file: + no_destination: "File destination must be specified." diff --git a/test/unit/plugins/pushes/file/config_test.rb b/test/unit/plugins/pushes/file/config_test.rb new file mode 100644 index 000000000..c5c7c591e --- /dev/null +++ b/test/unit/plugins/pushes/file/config_test.rb @@ -0,0 +1,34 @@ +require_relative "../../../base" + +require Vagrant.source_root.join("plugins/pushes/file/config") + +describe VagrantPlugins::FileDeploy::Config do + include_context "unit" + + subject { described_class.new } + + let(:machine) { double("machine") } + + describe "#validate" do + it "returns an error if destination is not specified" do + subject.finalize! + + result = subject.validate(machine) + + expect(result["File push"]).to eql([ + I18n.t("vagrant.pushes.file.no_destination") + ]) + end + + it "returns no errors when the config is valid" do + existing_file = File.expand_path(__FILE__) + + subject.destination = existing_file + subject.finalize! + + result = subject.validate(machine) + + expect(result["File push"]).to be_empty + end + end +end