vagrant-scp-sync 0.5.10 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b37865ce15d9a043ad16012e533166f7fd9a0b3706aead065563929008fb924
4
- data.tar.gz: ecd9d22f28a254d2c711a7975c873fe55abf861acd49b0eea40af85128718501
3
+ metadata.gz: a6dab1627126fa4175b128368987b80ba059ada1226d05346325bac4c124fe4c
4
+ data.tar.gz: ecf339d488869952c926f2226bdc0e584c6c4c9139455497a89a65441d544868
5
5
  SHA512:
6
- metadata.gz: a3513b9189a63c1161f191ed70c7dadbdbfbd4aba0d2fa01ed5916526f019c342cd698c22b48c1458275c78087f1a6e6c639b6bbaa1ec3d5618002d1ddf098e8
7
- data.tar.gz: 8f804f9f6c82ba3929ac3a79d4f3984baed01f42b52591b7c9319b1f21ec189afe6b01fb2dde85e4bbe6a1d89c7f80ad559a17aba629ceb7c119a7852181cd85
6
+ metadata.gz: ca832eaa5a34e0f0535ec8ff2e7806cf0ba2f472e5df84e8c6f1973af1f1cbf0a2148e240b516c4f20246e077b670d0bee449c5c5a35d760d9eef83262603cee
7
+ data.tar.gz: 45ba7fa7c86c90836a8c1b78427e0e1a250ce348c8e1b34a7effcc7d1b0612c69d3a7a140ea0659e0bcd640a8b559672041caa31dd0d496af1faebce190f50e0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.11](https://github.com/STARTcloud/vagrant-scp-sync/compare/v0.5.10...v0.5.11) (2024-11-20)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * implentation complete ([987197d](https://github.com/STARTcloud/vagrant-scp-sync/commit/987197d15506d7c11b08af2e279efeb178037b71))
9
+ * linting ([c531e5b](https://github.com/STARTcloud/vagrant-scp-sync/commit/c531e5b2137781d6c670dc1cc0053d79a63637b6))
10
+ * linting ([9720ea7](https://github.com/STARTcloud/vagrant-scp-sync/commit/9720ea74d683180f213b62dc45c821b3b3e9c615))
11
+ * linting ([dbc75c3](https://github.com/STARTcloud/vagrant-scp-sync/commit/dbc75c328c7e5e042d02e8c7472a83e3898b274b))
12
+ * linting ([fbb7533](https://github.com/STARTcloud/vagrant-scp-sync/commit/fbb7533ee869bd1d761fd33b365b26bcca9557c7))
13
+ * linting ([70266d1](https://github.com/STARTcloud/vagrant-scp-sync/commit/70266d1a4aafe9e68ed9e1f5f0242268f1f3e5cc))
14
+ * linting ([3e7facd](https://github.com/STARTcloud/vagrant-scp-sync/commit/3e7facd04a4af7060773e96b6e298a2c0ae0f953))
15
+ * linting ([da0ef5d](https://github.com/STARTcloud/vagrant-scp-sync/commit/da0ef5d2435ca6cef31fc626891d1144677a34bb))
16
+ * synced folders reference ([2b8ade9](https://github.com/STARTcloud/vagrant-scp-sync/commit/2b8ade9ef7d896e11851eb004ac687031f8dd1a0))
17
+ * synced folders refernce ([3efe97c](https://github.com/STARTcloud/vagrant-scp-sync/commit/3efe97c50ea6e18e5aca4876c2fd05003401ddb0))
18
+ * synced folders refernce ([fa1dfc5](https://github.com/STARTcloud/vagrant-scp-sync/commit/fa1dfc5a04611ac623b84cd02c7c513fb390936e))
19
+
3
20
  ## [0.5.10](https://github.com/STARTcloud/vagrant-scp-sync/compare/v0.5.9...v0.5.10) (2024-11-19)
4
21
 
5
22
 
@@ -7,65 +7,104 @@ module VagrantPlugins
7
7
  module ScpSync
8
8
  # This will SCP the files
9
9
  class ScpSyncHelper
10
- def self.scp_single(machine, opts)
10
+ def self.scp_single(machine, opts, scp_path)
11
11
  ssh_info = machine.ssh_info
12
12
  raise Vagrant::Errors::SSHNotReady if ssh_info.nil?
13
13
 
14
- source_files = opts[:guestpath]
15
- target_files = opts[:hostpath]
16
- target_files = File.expand_path(target_files, machine.env.root_path)
17
- target_files = Vagrant::Util::Platform.fs_real_path(target_files).to_s
18
- target_files = Vagrant::Util::Platform.cygwin_path(target_files) if Vagrant::Util::Platform.windows?
19
- source_files += '/' unless source_files.end_with?('/')
20
- target_files += '/' unless target_files.end_with?('/')
14
+ source_files = expand_path(opts[:map], machine)
15
+ has_trailing_slash_source = opts[:map].end_with?('/')
16
+ sync_source_files = append_wildcard(source_files, has_trailing_slash_source)
17
+
18
+ target_files = expand_path(opts[:to], machine)
19
+
21
20
  opts[:owner] ||= ssh_info[:username]
22
21
  opts[:group] ||= ssh_info[:username]
23
- username = ssh_info[:username]
24
- host = ssh_info[:host]
25
- proxy_command = if @ssh_info[:proxy_command]
26
- "-o ProxyCommand='#{@ssh_info[:proxy_command]}' "
27
- else
28
- ''
29
- end
22
+
23
+ ssh_opts = build_ssh_options(ssh_info)
24
+ scp_opts = build_scp_options(opts)
25
+
26
+ delete = scp_opts.include?('--delete')
30
27
 
31
28
  if opts[:direction] == :upload || opts[:direction].nil?
32
- source = "'#{source_files}'"
33
- target = "#{username}@#{host}:'#{target_files}'"
29
+ source = sync_source_files
30
+ target = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{target_files}"
31
+ make_dir = build_ssh_command(ssh_opts, "sudo mkdir -p #{target_files}", ssh_info)
32
+ change_ownership = build_ssh_command(ssh_opts, "sudo chown -R #{opts[:owner]}:#{opts[:group]} #{target_files}", ssh_info)
33
+ change_permissions = build_ssh_command(ssh_opts, "sudo chmod 777 #{target_files}", ssh_info)
34
+ remove_dir = build_ssh_command(ssh_opts, "sudo rm -rf #{target_files}", ssh_info)
34
35
  elsif opts[:direction] == :download
35
- source = "#{username}@#{host}:'#{source_files}'"
36
- target = "'#{target_files}'"
36
+ source = "#{ssh_info[:username]}@#{ssh_info[:host]}:#{sync_source_files}"
37
+ target = target_files
38
+ make_dir = "mkdir -p #{target_files}"
37
39
  end
38
40
 
39
- command = [
40
- 'scp',
41
- '-r',
42
- '-o StrictHostKeyChecking=no',
43
- '-o UserKnownHostsFile=/dev/null',
44
- "-o port=#{@ssh_info[:port]}",
45
- '-o LogLevel=ERROR',
46
- proxy_command,
47
- @ssh_info[:private_key_path].map { |k| "-i '#{k}'" }.join(' '),
48
- source,
49
- target
50
- ].join(' ')
41
+ synchronize = build_scp_command(scp_path, ssh_opts, source, target)
42
+ execute_command(machine, remove_dir, delete, nil, opts)
43
+ execute_command(machine, make_dir, false, nil, opts)
44
+ execute_command(machine, change_ownership, false, nil, opts)
45
+ execute_command(machine, change_permissions, false, nil, opts)
46
+ execute_command(machine, synchronize, true, 'scp_sync_folder', opts)
47
+ end
51
48
 
52
- command_opts = {}
53
- command_opts[:workdir] = machine.env.root_path.to_s
49
+ def self.expand_path(path, machine)
50
+ expanded_path = File.expand_path(path, machine.env.root_path)
51
+ Vagrant::Util::Platform.fs_real_path(expanded_path).to_s
52
+ end
54
53
 
55
- machine.ui.info(I18n.t('vagrant.scp_folder', source_files: source_files, target_files: target_files))
54
+ def self.append_wildcard(path, has_trailing_slash)
55
+ has_trailing_slash ? "#{path}/*" : path
56
+ end
56
57
 
57
- command += [command_opts]
58
+ def self.build_ssh_options(ssh_info)
59
+ opts = %w[
60
+ -o StrictHostKeyChecking=no
61
+ -o UserKnownHostsFile=/dev/null
62
+ -o LogLevel=ERROR
63
+ ]
64
+ opts << "-o port=#{ssh_info[:port]}"
65
+ opts << ssh_info[:private_key_path].map { |k| "-i #{k}" }.join(' ')
66
+ opts
67
+ end
58
68
 
59
- r = Vagrant::Util::Subprocess.execute(*command)
69
+ def self.build_scp_options(opts)
70
+ opts[:scp__args] ? Array(opts[:scp__args]).dup : ['--verbose']
71
+ end
60
72
 
61
- return if r.exit_code.zero?
73
+ def self.build_ssh_command(ssh_opts, command, ssh_info)
74
+ ['ssh', *ssh_opts, "#{ssh_info[:username]}@#{ssh_info[:host]}", command].join(' ')
75
+ end
62
76
 
63
- raise Vagrant::Errors::SyncedFolderScpSyncError,
64
- command: command.inspect,
65
- source_files: source_files,
66
- target_files: target_files,
67
- stderr: r.stderr
77
+ def self.build_scp_command(scp_path, ssh_opts, source, target)
78
+ [scp_path, '-r', *ssh_opts, source, target].join(' ')
68
79
  end
80
+
81
+ def self.execute_command(machine, command, raise_error, message_key, opts)
82
+ return if command.nil?
83
+
84
+ if message_key
85
+ machine.ui.info(
86
+ I18n.t(
87
+ "vagrant_scp_sync.action.#{message_key}",
88
+ command: command,
89
+ target_files: opts[:to],
90
+ source_files: opts[:map]
91
+ )
92
+ )
93
+ end
94
+
95
+ result = Vagrant::Util::Subprocess.execute('sh', '-c', command)
96
+
97
+ raise_scp_error(message_key, command, result.stderr) if raise_error && !result.exit_code.zero?
98
+ end
99
+
100
+ def self.raise_scp_error(message_key, command, stderr)
101
+ raise Errors.const_get("SyncedFolderScpSync#{message_key.split('_').map(&:capitalize).join}Error"),
102
+ command: command,
103
+ stderr: stderr
104
+ end
105
+
106
+ private_class_method :expand_path, :append_wildcard, :build_ssh_options, :build_scp_options,
107
+ :build_ssh_command, :build_scp_command, :execute_command, :raise_scp_error
69
108
  end
70
109
  end
71
110
  end
@@ -6,7 +6,7 @@ module VagrantPlugins
6
6
  module ScpSync
7
7
  module Command
8
8
  # This class defines SCPSync
9
- class ScpSync < Vagrant.plugin(2, :command)
9
+ class ScpSync < Vagrant.plugin('2', :command)
10
10
  def self.synopsis
11
11
  'Copies data into a box via SCP'
12
12
  end
@@ -2,16 +2,43 @@
2
2
 
3
3
  require 'vagrant'
4
4
 
5
- module Vagrant
6
- module Errors
7
- # This Class denotes Errors for SCP Sync
8
- class SyncedFolderScpSyncError < VagrantError
9
- error_key(:scp_sync_error, 'vagrant_scp_sync.errors')
10
- end
5
+ module VagrantPlugins
6
+ module ScpSync
7
+ module Errors
8
+ # Namespace for Vagrant SCP Sync Errors
9
+ class VagrantScpSyncError < Vagrant::Errors::VagrantError
10
+ error_namespace('vagrant_scp_sync.errors')
11
+ end
12
+
13
+ # This Class denotes Errors for SCP Sync
14
+ class SyncedFolderScpSyncError < VagrantScpSyncError
15
+ error_key(:scp_sync_error, 'vagrant_scp_sync.errors')
16
+ end
17
+
18
+ # This Class denotes Delete Dir Errors for SCP Sync
19
+ class SyncedFolderScpSyncDeleteDirError < VagrantScpSyncError
20
+ error_key(:scp_sync_error_delete_directory, 'vagrant_scp_sync.errors')
21
+ end
22
+
23
+ # This Class denotes Make Dir Errors for SCP Sync
24
+ class SyncedFolderScpSyncMakeDirError < VagrantScpSyncError
25
+ error_key(:scp_sync_error_make_directory, 'vagrant_scp_sync.errors')
26
+ end
27
+
28
+ # This Class denotes Make Dir Errors for SCP Sync
29
+ class SyncedFolderScpSyncChangePermissionsDirError < VagrantScpSyncError
30
+ error_key(:scp_sync_error_change_permissions_directory, 'vagrant_scp_sync.errors')
31
+ end
32
+
33
+ # This Class denotes Make Dir Errors for SCP Sync
34
+ class SyncedFolderScpSyncChangeOwnershipDirError < VagrantScpSyncError
35
+ error_key(:scp_sync_error_change_ownership_directory, 'vagrant_scp_sync.errors')
36
+ end
11
37
 
12
- # This Class denotes that SCP Sync is not found
13
- class SCPNotFound < VagrantError
14
- error_key(:scp_installed_error, 'vagrant_scp_sync.errors')
38
+ # This Class denotes that SCP Sync is not found
39
+ class SCPNotFound < VagrantScpSyncError
40
+ error_key(:scp_installed_error, 'vagrant_scp_sync.errors')
41
+ end
15
42
  end
16
43
  end
17
44
  end
@@ -19,7 +19,7 @@ module VagrantPlugins
19
19
 
20
20
  command 'scp' do
21
21
  setup_i18n
22
- require_relative 'command'
22
+ require_relative 'command/scp'
23
23
  Command
24
24
  end
25
25
 
@@ -28,10 +28,47 @@ module VagrantPlugins
28
28
  SyncedFolder
29
29
  end
30
30
 
31
+ # This initializes the internationalization strings.
31
32
  def self.setup_i18n
32
33
  I18n.load_path << File.expand_path('locales/en.yml', ScpSync.source_root)
33
34
  I18n.reload!
34
35
  end
36
+
37
+ # This sets up our log level to be whatever VAGRANT_LOG is.
38
+ def self.setup_logging
39
+ require 'log4r'
40
+
41
+ level = nil
42
+ begin
43
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
44
+ rescue NameError
45
+ # This means that the logging constant wasn't found,
46
+ # which is fine. We just keep `level` as `nil`. But
47
+ # we tell the user.
48
+ level = nil
49
+ end
50
+
51
+ # Some constants, such as "true" resolve to booleans, so the
52
+ # above error checking doesn't catch it. This will check to make
53
+ # sure that the log level is an integer, as Log4r requires.
54
+ level = nil unless level.is_a?(Integer)
55
+
56
+ # Set the logging level on all "vagrant" namespaced
57
+ # logs as long as we have a valid level.
58
+
59
+ return unless level
60
+
61
+ logger = Log4r::Logger.new('vagrant_scp_sync')
62
+ logger.outputters = Log4r::Outputter.stderr
63
+ logger.level = level
64
+ logger
65
+ end
66
+
67
+ # Setup logging and i18n before any autoloading loads other classes
68
+ # with logging configured as this prevents inheritance of the log level
69
+ # from the parent logger.
70
+ setup_logging
71
+ setup_i18n
35
72
  end
36
73
  end
37
74
  end
@@ -18,11 +18,11 @@ module VagrantPlugins
18
18
  @logger = Log4r::Logger.new('vagrant_scp_sync')
19
19
  end
20
20
 
21
- def usable?(_machine, raise_error: false)
21
+ def usable?(_machine, *args)
22
22
  scp_path = Which.which('scp')
23
23
  return true if scp_path
24
24
 
25
- return false unless raise_error
25
+ return false unless args.include?(:raise_error) && args[:raise_error]
26
26
 
27
27
  raise Vagrant::Errors::SCPNotFound
28
28
  end
@@ -31,11 +31,12 @@ module VagrantPlugins
31
31
 
32
32
  def enable(machine, folders, _opts)
33
33
  ssh_info = machine.ssh_info
34
+ scp_path = Which.which('scp')
34
35
 
35
36
  machine.ui.warn(I18n.t('vagrant.scp_ssh_password')) if ssh_info[:private_key_path].empty? && ssh_info[:password]
36
37
 
37
38
  folders.each_value do |folder_opts|
38
- ScpSyncHelper.scp_single(machine, folder_opts)
39
+ ScpSyncHelper.scp_single(machine, folder_opts, scp_path)
39
40
  end
40
41
  end
41
42
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Vagrant
4
4
  module ScpSync
5
- VERSION = '0.5.10'
5
+ VERSION = '0.5.11'
6
6
  NAME = 'vagrant-scp-sync'
7
7
  end
8
8
  end
@@ -1,14 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'vagrant-scp-sync/version'
4
- require 'vagrant-scp-sync/plugin'
5
- require 'vagrant-scp-sync/errors'
3
+ require 'pathname'
6
4
 
7
5
  module VagrantPlugins
8
6
  # This is used to SCP files to/from Guests and Hosts
9
7
  module ScpSync
8
+ lib_path = Pathname.new(File.expand_path('vagrant-scp-sync', __dir__))
9
+ autoload :Errors, lib_path.join('errors')
10
10
  def self.source_root
11
11
  @source_root ||= Pathname.new(File.expand_path('..', __dir__))
12
12
  end
13
13
  end
14
14
  end
15
+
16
+ begin
17
+ require 'vagrant'
18
+ rescue LoadError
19
+ raise 'The Vagrant vagrant-zones plugin must be run within Vagrant.'
20
+ end
21
+
22
+ raise 'The Vagrant vagrant-zones plugin is only compatible with Vagrant 2+.' if Vagrant::VERSION < '2'
23
+
24
+ require 'vagrant-scp-sync/version'
25
+ require 'vagrant-scp-sync/plugin'
data/locales/en.yml CHANGED
@@ -1,18 +1,53 @@
1
1
  en:
2
2
  vagrant_scp_sync:
3
+ action:
4
+ scp_sync_folder: |-
5
+ Syncing Folder: %{source_files} ==> %{target_files}
6
+
3
7
  errors:
4
8
  not_yet_implemented: |-
5
9
  Configuration is not yet implemented
10
+ scp_sync_error_delete_directory: |-
11
+ There was an error when attemping to delete the directory for SCP Sync.
12
+ Target Files: %{target_files}
13
+
14
+ Error: %{stderr}
15
+ Full command causing error:
16
+ %{command}
17
+
18
+ scp_sync_error_change_ownership_directory: |-
19
+ There was an error when attemping to change the ownership of the directory for SCP Sync.
20
+ Target Files: %{target_files}
21
+
22
+ Error: %{stderr}
23
+ Full command causing error:
24
+ %{command}
25
+
26
+ scp_sync_error_change_permissions_directory: |-
27
+ There was an error when attemping to change the permissions of the directory for SCP Sync.
28
+ Target Files: %{target_files}
29
+
30
+ Error: %{stderr}
31
+ Full command causing error:
32
+ %{command}
33
+
34
+ scp_sync_error_make_directory: |-
35
+ There was an error when attemping to create the directory for SCP Sync.
36
+ Target Files: %{target_files}
37
+
38
+ Error: %{stderr}
39
+ Full command causing error:
40
+ %{command}
6
41
 
7
42
  scp_sync_error: |-
8
43
  There was an error when attemping to sync folders using scp.
9
44
  Please inspect the error message below for more info.
10
45
 
11
- Host path: %{hostpath}
12
- Guest path: %{guestpath}
46
+ Source Files: %{source_files}
47
+ Target Files: %{target_files}
13
48
  Error: %{stderr}
14
- Full command causing error:
49
+ Full command causing error:
15
50
  %{command}
16
51
 
17
52
  scp_installed_error: |-
18
- SCP was not detected as installed
53
+ SCP was not detected as installed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-scp-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Gilbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-19 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n