Merge pull request #3535 from mitchellh/winrm-command-filters-code-review-feedback

Winrm command filters code review feedback
This commit is contained in:
Shawn Neal 2014-04-24 08:45:13 -07:00
commit 82fa208c39
11 changed files with 10 additions and 49 deletions

View File

@ -1,9 +1,7 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
# Handles loading and applying all available WinRM command filters # Handles loading and applying all available WinRM command filters
class CommandFilter class CommandFilter
@@cmd_filters = [ @@cmd_filters = [
"cat", "cat",
"chmod", "chmod",
@ -12,7 +10,7 @@ module VagrantPlugins
"rm", "rm",
"test", "test",
"uname", "uname",
"which" "which",
] ]
# Filter the given Vagrant command to ensure compatibility with Windows # Filter the given Vagrant command to ensure compatibility with Windows
@ -42,7 +40,6 @@ module VagrantPlugins
end end
end end
end end
end end
end end
end end

View File

@ -1,10 +1,8 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Handles the special case of determining the guest OS using cat # Handles the special case of determining the guest OS using cat
class Cat class Cat
def filter(command) def filter(command)
# cat /etc/release | grep -i OmniOS # cat /etc/release | grep -i OmniOS
# cat /etc/redhat-release # cat /etc/redhat-release
@ -19,9 +17,7 @@ module VagrantPlugins
# grep command # grep command
command.start_with?('cat /etc/') command.start_with?('cat /etc/')
end end
end
end
end end
end end
end end

View File

@ -1,21 +1,17 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'chmod' command to a PowerShell equivalent (none)
# Converts a *nix 'chmod' command to a PowerShell equivalent
class Chmod class Chmod
def filter(command) def filter(command)
# Not support on Windows, the communicator will skip this command # Not supported on Windows, the communicator should skip this command
'' ''
end end
def accept?(command) def accept?(command)
command.start_with?('chmod ') command.start_with?('chmod ')
end end
end
end
end end
end end
end end

View File

@ -1,21 +1,17 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'chown' command to a PowerShell equivalent (none)
# Converts a *nix 'chown' command to a PowerShell equivalent
class Chown class Chown
def filter(command) def filter(command)
# Not support on Windows, the communicator will skip this command # Not supported on Windows, the communicator should skip this command
'' ''
end end
def accept?(command) def accept?(command)
command.start_with?('chown ') command.start_with?('chown ')
end end
end
end
end end
end end
end end

View File

@ -1,8 +1,7 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'grep' command to a PowerShell equivalent (none)
# Converts a *nix 'grep' command to a PowerShell equivalent
class Grep class Grep
def filter(command) def filter(command)
@ -18,9 +17,7 @@ module VagrantPlugins
def accept?(command) def accept?(command)
command.start_with?('grep ') command.start_with?('grep ')
end end
end
end
end end
end end
end end

View File

@ -1,10 +1,8 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'rm' command to a PowerShell equivalent # Converts a *nix 'rm' command to a PowerShell equivalent
class Rm class Rm
def filter(command) def filter(command)
# rm -Rf /some/dir # rm -Rf /some/dir
# rm /some/dir # rm /some/dir
@ -20,9 +18,7 @@ module VagrantPlugins
def accept?(command) def accept?(command)
command.start_with?('rm ') command.start_with?('rm ')
end end
end
end
end end
end end
end end

View File

@ -1,10 +1,8 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'test' command to a PowerShell equivalent # Converts a *nix 'test' command to a PowerShell equivalent
class Test class Test
def filter(command) def filter(command)
# test -d /tmp/dir # test -d /tmp/dir
# test -f /tmp/afile # test -f /tmp/afile
@ -28,7 +26,6 @@ module VagrantPlugins
command.start_with?("test ") command.start_with?("test ")
end end
private private
def check_for_directory(path) def check_for_directory(path)
@ -60,9 +57,7 @@ module VagrantPlugins
exit 1 exit 1
EOH EOH
end end
end
end
end end
end end
end end

View File

@ -1,10 +1,8 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'uname' command to a PowerShell equivalent (none)
# Converts a *nix 'uname' command to a PowerShell equivalent
class Uname class Uname
def filter(command) def filter(command)
# uname -s | grep 'Darwin' # uname -s | grep 'Darwin'
# uname -s | grep VMkernel # uname -s | grep VMkernel
@ -23,9 +21,7 @@ module VagrantPlugins
def accept?(command) def accept?(command)
command.start_with?('uname ') command.start_with?('uname ')
end end
end
end
end end
end end
end end

View File

@ -1,10 +1,8 @@
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
module CommandFilters module CommandFilters
# Converts a *nix 'which' command to a PowerShell equivalent # Converts a *nix 'which' command to a PowerShell equivalent
class Which class Which
def filter(command) def filter(command)
executable = command.strip.split(/\s+/)[1] executable = command.strip.split(/\s+/)[1]
return <<-EOH return <<-EOH
@ -18,9 +16,7 @@ module VagrantPlugins
def accept?(command) def accept?(command)
command.start_with?('which ') command.start_with?('which ')
end end
end
end
end end
end end
end end

View File

@ -17,10 +17,10 @@ module VagrantPlugins
end end
def initialize(machine) def initialize(machine)
@cmd_filter = CommandFilter.new()
@logger = Log4r::Logger.new("vagrant::communication::winrm")
@machine = machine @machine = machine
@shell = nil @shell = nil
@logger = Log4r::Logger.new("vagrant::communication::winrm")
@cmd_filter = CommandFilter.new()
@logger.info("Initializing WinRMCommunicator") @logger.info("Initializing WinRMCommunicator")
end end

View File

@ -2,11 +2,9 @@ require "log4r"
module VagrantPlugins module VagrantPlugins
module CommunicatorWinRM module CommunicatorWinRM
# Manages the file system on the remote guest allowing for file tranfer # Manages the file system on the remote guest allowing for file tranfer
# between the guest and host. # between the guest and host.
class FileManager class FileManager
def initialize(shell) def initialize(shell)
@logger = Log4r::Logger.new("vagrant::communication::filemanager") @logger = Log4r::Logger.new("vagrant::communication::filemanager")
@shell = shell @shell = shell
@ -39,7 +37,6 @@ module VagrantPlugins
IO.binwrite(host_dest_file_path, out) IO.binwrite(host_dest_file_path, out)
end end
private private
# Recursively uploads the given directory from the host to the guest # Recursively uploads the given directory from the host to the guest
@ -160,7 +157,6 @@ module VagrantPlugins
:to => to, :to => to,
:message => out.inspect if out[:exitcode] != 0 :message => out.inspect if out[:exitcode] != 0
end end
end
end #class
end end
end end