hobo-inviqa 0.0.7.pre.rc3 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -19
- data/Guardfile +2 -2
- data/Hobofile +1 -5
- data/bin/hobo +18 -12
- data/hobo.gemspec +0 -3
- data/lib/hobo.rb +1 -8
- data/lib/hobo/cli.rb +3 -14
- data/lib/hobo/error_handlers/debug.rb +2 -5
- data/lib/hobo/error_handlers/friendly.rb +8 -8
- data/lib/hobo/errors.rb +1 -11
- data/lib/hobo/helper/shell.rb +2 -3
- data/lib/hobo/helper/vm_command.rb +14 -164
- data/lib/hobo/lib/host_check.rb +6 -20
- data/lib/hobo/lib/host_check/deps.rb +4 -22
- data/lib/hobo/lib/host_check/git.rb +17 -41
- data/lib/hobo/lib/host_check/ruby.rb +20 -30
- data/lib/hobo/lib/host_check/vagrant.rb +6 -37
- data/lib/hobo/lib/s3sync.rb +44 -22
- data/lib/hobo/lib/seed/project.rb +4 -8
- data/lib/hobo/patches/slop.rb +2 -21
- data/lib/hobo/tasks/assets.rb +15 -12
- data/lib/hobo/tasks/deps.rb +6 -40
- data/lib/hobo/tasks/host.rb +19 -0
- data/lib/hobo/tasks/tools.rb +6 -10
- data/lib/hobo/tasks/vm.rb +11 -64
- data/lib/hobo/ui.rb +10 -27
- data/lib/hobo/util.rb +2 -36
- data/lib/hobo/version.rb +2 -2
- data/spec/hobo/asset_applicator_spec.rb +2 -2
- data/spec/hobo/cli_spec.rb +24 -35
- data/spec/hobo/config/file_spec.rb +3 -1
- data/spec/hobo/error_handlers/debug_spec.rb +5 -39
- data/spec/hobo/error_handlers/friendly_spec.rb +21 -38
- data/spec/hobo/help_formatter_spec.rb +3 -3
- data/spec/hobo/helpers/file_locator_spec.rb +2 -2
- data/spec/hobo/helpers/shell_spec.rb +2 -2
- data/spec/hobo/helpers/vm_command_spec.rb +24 -36
- data/spec/hobo/lib/s3sync_spec.rb +3 -6
- data/spec/hobo/lib/seed/project_spec.rb +3 -2
- data/spec/hobo/lib/seed/replacer_spec.rb +2 -1
- data/spec/hobo/lib/seed/seed_spec.rb +3 -2
- data/spec/hobo/logging_spec.rb +2 -2
- data/spec/hobo/metadata_spec.rb +2 -2
- data/spec/hobo/null_spec.rb +2 -2
- data/spec/hobo/paths_spec.rb +2 -1
- data/spec/hobo/ui_spec.rb +20 -104
- data/spec/spec_helper.rb +0 -1
- metadata +48 -57
- checksums.yaml +0 -15
- data/.editorconfig +0 -10
- data/lib/hobo/error_handlers/exit_code_map.rb +0 -16
- data/lib/hobo/helper/http_download.rb +0 -41
- data/lib/hobo/tasks/config.rb +0 -15
- data/lib/hobo/tasks/system.rb +0 -15
- data/lib/hobo/tasks/system/completions.rb +0 -76
- data/spec/hobo/util_spec.rb +0 -75
data/Gemfile.lock
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hobo-inviqa (0.0.7
|
4
|
+
hobo-inviqa (0.0.7)
|
5
5
|
aws-sdk (~> 1.34.0)
|
6
6
|
bundler (~> 1.5.2)
|
7
7
|
deepstruct (~> 0.0.5)
|
8
8
|
highline (~> 1.6.20)
|
9
|
-
net-ssh-simple (~> 1.6.3)
|
10
|
-
os (~> 0.9.6)
|
11
9
|
rake (~> 10.1.1)
|
12
10
|
rake-hooks (~> 1.2.3)
|
13
11
|
ruby-progressbar (~> 1.4.1)
|
14
12
|
semantic (~> 1.3.0)
|
15
13
|
slop (~> 3.4.7)
|
16
|
-
teerb (~> 0.0.1)
|
17
14
|
|
18
15
|
GEM
|
19
16
|
remote: https://rubygems.org/
|
@@ -22,11 +19,10 @@ GEM
|
|
22
19
|
childprocess (>= 0.3.6)
|
23
20
|
cucumber (>= 1.1.1)
|
24
21
|
rspec-expectations (>= 2.7.0)
|
25
|
-
aws-sdk (1.34.
|
22
|
+
aws-sdk (1.34.0)
|
26
23
|
json (~> 1.4)
|
27
24
|
nokogiri (>= 1.4.4)
|
28
25
|
uuidtools (~> 2.1)
|
29
|
-
blockenspiel (0.4.5)
|
30
26
|
builder (3.2.2)
|
31
27
|
celluloid (0.15.2)
|
32
28
|
timers (~> 1.1.0)
|
@@ -61,8 +57,7 @@ GEM
|
|
61
57
|
guard-rspec (4.2.6)
|
62
58
|
guard (~> 2.1)
|
63
59
|
rspec (>= 2.14, < 4.0)
|
64
|
-
|
65
|
-
highline (1.6.21)
|
60
|
+
highline (1.6.20)
|
66
61
|
json (1.8.1)
|
67
62
|
listen (2.5.0)
|
68
63
|
celluloid (>= 0.15.2)
|
@@ -74,18 +69,9 @@ GEM
|
|
74
69
|
mini_portile (0.5.2)
|
75
70
|
multi_json (1.8.4)
|
76
71
|
multi_test (0.0.3)
|
77
|
-
net-scp (1.1.2)
|
78
|
-
net-ssh (>= 2.6.5)
|
79
|
-
net-ssh (2.7.0)
|
80
|
-
net-ssh-simple (1.6.3)
|
81
|
-
blockenspiel (~> 0.4.3)
|
82
|
-
hashie (>= 1.1.0)
|
83
|
-
net-scp (~> 1.1.0)
|
84
|
-
net-ssh (~> 2.7.0)
|
85
72
|
nio4r (1.0.0)
|
86
73
|
nokogiri (1.6.1)
|
87
74
|
mini_portile (~> 0.5.0)
|
88
|
-
os (0.9.6)
|
89
75
|
pry (0.9.12.6)
|
90
76
|
coderay (~> 1.0)
|
91
77
|
method_source (~> 0.8)
|
@@ -105,10 +91,9 @@ GEM
|
|
105
91
|
rspec-expectations (2.14.5)
|
106
92
|
diff-lcs (>= 1.1.3, < 2.0)
|
107
93
|
rspec-mocks (2.14.5)
|
108
|
-
ruby-progressbar (1.4.
|
94
|
+
ruby-progressbar (1.4.1)
|
109
95
|
semantic (1.3.0)
|
110
96
|
slop (3.4.7)
|
111
|
-
teerb (0.0.1)
|
112
97
|
thor (0.18.1)
|
113
98
|
timers (1.1.0)
|
114
99
|
uuidtools (2.1.4)
|
data/Guardfile
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
guard :rspec do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
8
8
|
end
|
9
9
|
|
@@ -11,4 +11,4 @@ guard 'cucumber' do
|
|
11
11
|
watch(%r{^features/.+\.feature$})
|
12
12
|
watch(%r{^features/support/.+$}) { 'features' }
|
13
13
|
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
14
|
-
end
|
14
|
+
end
|
data/Hobofile
CHANGED
data/bin/hobo
CHANGED
@@ -5,21 +5,29 @@ $:.push File.expand_path(File.join("..", "..", "lib"), __FILE__)
|
|
5
5
|
|
6
6
|
require 'hobo'
|
7
7
|
require 'slop'
|
8
|
-
require 'teerb'
|
9
|
-
require 'tmpdir'
|
10
8
|
|
11
9
|
error_handler = Hobo::ErrorHandlers::Friendly.new
|
12
|
-
|
13
10
|
Hobo.ui = Hobo::Ui.new
|
14
11
|
Hobo.logger = Logger.new(STDOUT)
|
15
12
|
Hobo.logger.level = Logger::WARN
|
13
|
+
Hobo.logger.formatter = proc do |severity, datetime, progname, msg|
|
14
|
+
"#{datetime.strftime("%Y-%m-%d %H:%M:%S")}: #{severity}: #{msg}\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
# win32console unfortunately has issues with Open3
|
18
|
+
# Simply disabling color for now; --ansi can be explicitly passed if required
|
19
|
+
# We also take the opportunity to disable ansi for pipes
|
20
|
+
Hobo.ui.use_color false if Gem.win_platform? || !STDOUT.tty?
|
21
|
+
|
22
|
+
# win32console unfortunately has issues with Open3
|
23
|
+
# Simply disabling color for now; --ansi can be explicitly passed if required
|
24
|
+
# We also take the opportunity to disable ansi for pipes
|
25
|
+
Hobo.ui.use_color false if Gem.win_platform? || !STDOUT.tty?
|
16
26
|
|
17
27
|
# Options parsed here will be hidden from the main app
|
18
28
|
slop = Slop.parse! do
|
19
29
|
on '--debug', 'Enable debugging' do
|
20
30
|
error_handler = Hobo::ErrorHandlers::Debug.new
|
21
|
-
debug_log = File.open(File.join(Dir.tmpdir, 'hobo_debug.log'), 'w+')
|
22
|
-
Hobo.logger = Logger.new(TeeRb::IODelegate.new(STDOUT, debug_log))
|
23
31
|
Hobo.logger.level = Logger::DEBUG
|
24
32
|
end
|
25
33
|
|
@@ -31,16 +39,14 @@ slop = Slop.parse! do
|
|
31
39
|
level = self.to_hash[:'log-level'].upcase
|
32
40
|
Hobo.logger.level = Logger.const_get(level) if [ 'DEBUG', 'INFO' ].include? level
|
33
41
|
end
|
34
|
-
end
|
35
42
|
|
36
|
-
|
37
|
-
|
43
|
+
on '--ansi', 'Enable / disable ansi output' do |*args|
|
44
|
+
Hobo.ui.use_color self.to_hash[:ansi]
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
48
|
begin
|
41
|
-
Hobo::
|
42
|
-
Hobo.cli = Hobo::Cli.new(slop: slop)
|
43
|
-
Hobo.cli.start
|
49
|
+
Hobo::Cli.new(slop: slop).start
|
44
50
|
rescue Exception => error
|
45
51
|
exit error_handler.handle(error)
|
46
|
-
end
|
52
|
+
end
|
data/hobo.gemspec
CHANGED
@@ -27,9 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency "semantic", "~> 1.3.0"
|
28
28
|
spec.add_dependency "aws-sdk", "~> 1.34.0"
|
29
29
|
spec.add_dependency "ruby-progressbar", "~> 1.4.1"
|
30
|
-
spec.add_dependency "teerb", "~> 0.0.1"
|
31
|
-
spec.add_dependency "os", "~> 0.9.6"
|
32
|
-
spec.add_dependency "net-ssh-simple", "~> 1.6.3"
|
33
30
|
|
34
31
|
spec.add_development_dependency "aruba", "~> 0.5.4"
|
35
32
|
spec.add_development_dependency "rspec", "~> 2.14.1"
|
data/lib/hobo.rb
CHANGED
@@ -4,7 +4,6 @@ require 'rake/hooks'
|
|
4
4
|
require 'tempfile'
|
5
5
|
require 'shellwords'
|
6
6
|
require 'deepstruct'
|
7
|
-
require 'os'
|
8
7
|
|
9
8
|
# DSL enhancements
|
10
9
|
require 'hobo/metadata'
|
@@ -17,11 +16,9 @@ require 'hobo/version'
|
|
17
16
|
require 'hobo/null'
|
18
17
|
require 'hobo/paths'
|
19
18
|
require 'hobo/errors'
|
20
|
-
require 'hobo/logging'
|
21
19
|
require 'hobo/ui'
|
22
20
|
require 'hobo/util'
|
23
21
|
require 'hobo/help_formatter'
|
24
|
-
require 'hobo/error_handlers/exit_code_map'
|
25
22
|
require 'hobo/error_handlers/debug'
|
26
23
|
require 'hobo/error_handlers/friendly'
|
27
24
|
require 'hobo/config/file'
|
@@ -29,14 +26,10 @@ require 'hobo/logging'
|
|
29
26
|
require 'hobo/config'
|
30
27
|
require 'hobo/asset_applicator'
|
31
28
|
|
32
|
-
# Asset sync
|
33
|
-
require 'hobo/lib/s3sync'
|
34
|
-
|
35
29
|
# Task helpers
|
36
30
|
require 'hobo/helper/shell'
|
37
31
|
require 'hobo/helper/file_locator'
|
38
32
|
require 'hobo/helper/vm_command'
|
39
|
-
require 'hobo/helper/http_download'
|
40
33
|
|
41
34
|
# Libs
|
42
35
|
require 'hobo/lib/seed/project'
|
@@ -51,4 +44,4 @@ require 'hobo/lib/host_check/deps'
|
|
51
44
|
require 'hobo/lib/host_check'
|
52
45
|
|
53
46
|
# App
|
54
|
-
require 'hobo/cli'
|
47
|
+
require 'hobo/cli'
|
data/lib/hobo/cli.rb
CHANGED
@@ -3,10 +3,6 @@ require 'deepstruct'
|
|
3
3
|
|
4
4
|
module Hobo
|
5
5
|
|
6
|
-
class << self
|
7
|
-
attr_accessor :cli
|
8
|
-
end
|
9
|
-
|
10
6
|
class Halt < Error
|
11
7
|
end
|
12
8
|
|
@@ -23,7 +19,6 @@ module Hobo
|
|
23
19
|
end
|
24
20
|
|
25
21
|
def start args = ARGV
|
26
|
-
|
27
22
|
load_user_config
|
28
23
|
load_builtin_tasks
|
29
24
|
load_hobofiles
|
@@ -36,9 +31,6 @@ module Hobo
|
|
36
31
|
# Parse out global args first
|
37
32
|
@slop.parse! args
|
38
33
|
opts = @slop.to_hash
|
39
|
-
|
40
|
-
Hobo::Lib::HostCheck.check(:filter => /vagrant.*|.*present/, :raise => true) unless opts[:'skip-host-checks']
|
41
|
-
|
42
34
|
@help_opts[:all] = opts[:all]
|
43
35
|
Hobo.ui.interactive = !(opts[:'non-interactive'] == true)
|
44
36
|
|
@@ -71,11 +63,9 @@ module Hobo
|
|
71
63
|
|
72
64
|
def load_builtin_tasks
|
73
65
|
require 'hobo/tasks/assets'
|
74
|
-
require 'hobo/tasks/config'
|
75
66
|
require 'hobo/tasks/debug'
|
76
67
|
require 'hobo/tasks/deps'
|
77
|
-
require 'hobo/tasks/
|
78
|
-
require 'hobo/tasks/system/completions'
|
68
|
+
require 'hobo/tasks/host'
|
79
69
|
require 'hobo/tasks/seed'
|
80
70
|
require 'hobo/tasks/vm'
|
81
71
|
require 'hobo/tasks/tools'
|
@@ -109,7 +99,6 @@ module Hobo
|
|
109
99
|
slop.on '-a', '--all', 'Show hidden commands'
|
110
100
|
slop.on '-h', '--help', 'Display help'
|
111
101
|
slop.on '--non-interactive', 'Run non-interactively. Defaults will be automatically used where possible.'
|
112
|
-
slop.on '--skip-host-checks', 'Skip host checks'
|
113
102
|
|
114
103
|
slop.on '-v', '--version', 'Print version information' do
|
115
104
|
Hobo.ui.info "Hobo version #{Hobo::VERSION}"
|
@@ -189,7 +178,7 @@ module Hobo
|
|
189
178
|
run do |opts, args|
|
190
179
|
Dir.chdir Hobo.project_path if Hobo.in_project?
|
191
180
|
raise ::Hobo::ProjectOnlyError.new if opts.project_only && !Hobo.in_project?
|
192
|
-
task.opts = opts.to_hash
|
181
|
+
task.opts = opts.to_hash
|
193
182
|
raise ::Hobo::MissingArgumentsError.new(name, args, hobo) if args && task.arg_names.length > args.length
|
194
183
|
task.invoke *args
|
195
184
|
args.pop(task.arg_names.size)
|
@@ -215,4 +204,4 @@ module Hobo
|
|
215
204
|
out
|
216
205
|
end
|
217
206
|
end
|
218
|
-
end
|
207
|
+
end
|
@@ -1,12 +1,9 @@
|
|
1
1
|
module Hobo
|
2
2
|
module ErrorHandlers
|
3
3
|
class Debug
|
4
|
-
include Hobo::ErrorHandlers::ExitCodeMap
|
5
|
-
|
6
4
|
def handle error
|
7
|
-
|
8
|
-
return EXIT_CODES[error.class.to_s] || DEFAULT_EXIT_CODE
|
5
|
+
raise error
|
9
6
|
end
|
10
7
|
end
|
11
8
|
end
|
12
|
-
end
|
9
|
+
end
|
@@ -3,8 +3,6 @@ require 'tmpdir' # Needed for Dir.tmpdir
|
|
3
3
|
module Hobo
|
4
4
|
module ErrorHandlers
|
5
5
|
class Friendly
|
6
|
-
include Hobo::ErrorHandlers::ExitCodeMap
|
7
|
-
|
8
6
|
def handle error
|
9
7
|
log_file = File.join(Dir.tmpdir, 'hobo_error.log')
|
10
8
|
|
@@ -12,6 +10,7 @@ module Hobo
|
|
12
10
|
case error.class.to_s
|
13
11
|
when "Interrupt"
|
14
12
|
Hobo.ui.warning "\n\nCaught Interrupt. Aborting\n"
|
13
|
+
return 1
|
15
14
|
when "Hobo::ExternalCommandError"
|
16
15
|
FileUtils.cp error.output.path, log_file
|
17
16
|
|
@@ -26,19 +25,21 @@ module Hobo
|
|
26
25
|
|
27
26
|
The output of the command has been logged to #{log_file}
|
28
27
|
ERROR
|
28
|
+
return 3
|
29
29
|
when "Hobo::InvalidCommandOrOpt"
|
30
30
|
Hobo.ui.error "\n#{error.message}"
|
31
31
|
Hobo.ui.info error.cli.help_formatter.help if error.cli
|
32
|
+
return 4
|
32
33
|
when "Hobo::MissingArgumentsError"
|
33
34
|
Hobo.ui.error "\n#{error.message}"
|
34
35
|
Hobo.ui.info error.cli.help_formatter.help(target: error.command) if error.cli
|
36
|
+
return 5
|
35
37
|
when "Hobo::UserError"
|
36
38
|
Hobo.ui.error "\n#{error.message}\n"
|
39
|
+
return 6
|
37
40
|
when "Hobo::ProjectOnlyError"
|
38
41
|
Hobo.ui.error "\nHobo requires you to be in a project directory for this command!\n"
|
39
|
-
|
40
|
-
Hobo.ui.error "\nHobo has detected a problem with your system configuration:\n"
|
41
|
-
Hobo.ui.warning error.advice.gsub(/^/, ' ')
|
42
|
+
return 7
|
42
43
|
else
|
43
44
|
File.write(log_file, "(#{error.class}) #{error.message}\n\n#{error.backtrace.join("\n")}")
|
44
45
|
Hobo.ui.error <<-ERROR
|
@@ -48,10 +49,9 @@ module Hobo
|
|
48
49
|
|
49
50
|
The backtrace has been logged to #{log_file}
|
50
51
|
ERROR
|
52
|
+
return 128
|
51
53
|
end
|
52
|
-
|
53
|
-
return EXIT_CODES[error.class.to_s] || DEFAULT_EXIT_CODE
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
data/lib/hobo/errors.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Hobo
|
2
2
|
class Error < StandardError
|
3
|
-
attr_reader :exit_code
|
4
3
|
end
|
5
4
|
|
6
5
|
class RubyVersionError < Error
|
@@ -65,13 +64,4 @@ module Hobo
|
|
65
64
|
super("A tool that hobo depends on could not be detected (#{dep})")
|
66
65
|
end
|
67
66
|
end
|
68
|
-
|
69
|
-
class HostCheckError < Error
|
70
|
-
attr_accessor :summary, :advice
|
71
|
-
def initialize summary, advice
|
72
|
-
@summary = summary
|
73
|
-
@advice = advice
|
74
|
-
super("Host check failed: #{summary}")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
67
|
+
end
|
data/lib/hobo/helper/shell.rb
CHANGED
@@ -39,8 +39,7 @@ module Hobo
|
|
39
39
|
:capture => false,
|
40
40
|
:indent => 0,
|
41
41
|
:realtime => false,
|
42
|
-
:env => {}
|
43
|
-
:ignore_errors => false
|
42
|
+
:env => {}
|
44
43
|
}.merge! opts
|
45
44
|
|
46
45
|
Hobo::Logging.logger.debug("helper.shell: Invoking '#{args.join(" ")}' with #{opts.to_s}")
|
@@ -72,7 +71,7 @@ module Hobo
|
|
72
71
|
buffer.fsync
|
73
72
|
buffer.rewind
|
74
73
|
|
75
|
-
raise ::Hobo::ExternalCommandError.new(args.join(" "), external.value.exitstatus, buffer) if external.value.exitstatus != 0
|
74
|
+
raise ::Hobo::ExternalCommandError.new(args.join(" "), external.value.exitstatus, buffer) if external.value.exitstatus != 0
|
76
75
|
|
77
76
|
return opts[:capture] ? buffer.read.strip : nil
|
78
77
|
end
|
@@ -1,26 +1,20 @@
|
|
1
|
-
require '
|
2
|
-
require 'net/ssh/simple'
|
1
|
+
require 'hobo/helper/shell'
|
3
2
|
|
4
3
|
module Hobo
|
5
4
|
module Helper
|
6
5
|
def vm_shell command, opts = {}
|
7
|
-
shell VmCommand.new(command
|
6
|
+
shell VmCommand.new(command).to_s, opts
|
8
7
|
end
|
9
8
|
|
10
9
|
def vm_mysql opts = {}
|
11
10
|
opts = {
|
12
11
|
:auto_echo => true,
|
13
12
|
:db => "",
|
14
|
-
:user => maybe(Hobo.project_config.mysql.username) || "",
|
15
|
-
:pass => maybe(Hobo.project_config.mysql.password) || ""
|
16
|
-
:mysql => 'mysql'
|
13
|
+
:user => maybe(Hobo.project_config.mysql.username) || "root",
|
14
|
+
:pass => maybe(Hobo.project_config.mysql.password) || "root"
|
17
15
|
}.merge(opts)
|
18
16
|
|
19
|
-
opts[:user]
|
20
|
-
opts[:pass] = "-p#{opts[:pass].shellescape}" unless opts[:pass].empty?
|
21
|
-
opts[:db] = opts[:db].shellescape unless opts[:db].empty?
|
22
|
-
|
23
|
-
VmCommand.new "#{opts[:mysql]} #{opts[:user]} #{opts[:pass]} #{opts[:db]}".strip, opts
|
17
|
+
VmCommand.new "mysql -u#{opts[:user].shellescape} -p#{opts[:pass].shellescape} #{opts[:db].shellescape}", opts
|
24
18
|
end
|
25
19
|
|
26
20
|
def vm_command command = nil, opts = {}
|
@@ -29,89 +23,17 @@ module Hobo
|
|
29
23
|
|
30
24
|
private
|
31
25
|
|
32
|
-
class VmInspector
|
33
|
-
attr_accessor :ssh_config, :project_mount_path
|
34
|
-
|
35
|
-
def project_mount_path
|
36
|
-
configured_path = maybe(Hobo.project_config.vm.project_mount_path)
|
37
|
-
return configured_path if configured_path
|
38
|
-
return @project_mount_path if @project_mount_path
|
39
|
-
|
40
|
-
tmp = Tempfile.new('vm_command_locator', Hobo.project_path)
|
41
|
-
|
42
|
-
begin
|
43
|
-
tmp.write(Hobo.project_path)
|
44
|
-
|
45
|
-
locator_file = File.basename(tmp.path)
|
46
|
-
|
47
|
-
pattern = OS.windows? ? 'vboxsf' : Hobo.project_path.shellescape
|
48
|
-
|
49
|
-
sed = 's/.* on \(.*\) type.*/\1\/%%/g'.gsub('%%', locator_file)
|
50
|
-
locator_results = VmCommand.new(
|
51
|
-
"mount | grep #{pattern} | sed -e\"#{sed}\" | xargs md5sum",
|
52
|
-
:capture => true,
|
53
|
-
:pwd => '/'
|
54
|
-
).run
|
55
|
-
ensure
|
56
|
-
tmp.unlink
|
57
|
-
end
|
58
|
-
|
59
|
-
match = locator_results.match(/^([a-z0-9]{32})\s+(.*)$/)
|
60
|
-
|
61
|
-
raise Exception.new("Unable to locate project mount point in VM") if !match
|
62
|
-
|
63
|
-
@vm_project_mount_path = File.dirname(match[2])
|
64
|
-
|
65
|
-
# Stash it in config
|
66
|
-
Hobo.project_config[:vm] ||= {}
|
67
|
-
Hobo.project_config[:vm][:project_mount_path] = @vm_project_mount_path
|
68
|
-
Hobo::Config::File.save(Hobo.project_config_file, Hobo.project_config)
|
69
|
-
|
70
|
-
return @vm_project_mount_path
|
71
|
-
end
|
72
|
-
|
73
|
-
def ssh_config
|
74
|
-
return @ssh_config if @ssh_config
|
75
|
-
config = nil
|
76
|
-
locate "*Vagrantfile" do
|
77
|
-
config = bundle_shell "vagrant ssh-config", :capture => true
|
78
|
-
end
|
79
|
-
|
80
|
-
raise Exception.new "Could not retrieve VM ssh configuration" unless config
|
81
|
-
|
82
|
-
patterns = {
|
83
|
-
:ssh_user => /^\s*User (.*)$/,
|
84
|
-
:ssh_identity => /^\s*IdentityFile (.*)$/,
|
85
|
-
:ssh_host => /^\s*HostName (.*)$/,
|
86
|
-
:ssh_port => /^\s*Port (\d+)/
|
87
|
-
}
|
88
|
-
|
89
|
-
output = {}
|
90
|
-
|
91
|
-
patterns.each do |k, pattern|
|
92
|
-
match = config.match(pattern)
|
93
|
-
output[k] = match[1] if match
|
94
|
-
end
|
95
|
-
|
96
|
-
return @ssh_config = output
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
26
|
class VmCommand
|
101
|
-
class << self
|
102
|
-
attr_accessor :vm_inspector
|
103
|
-
@@vm_inspector = VmInspector.new
|
104
|
-
end
|
105
|
-
|
106
27
|
attr_accessor :opts, :command
|
107
28
|
|
108
29
|
def initialize command, opts = {}
|
109
30
|
@command = command
|
110
31
|
@opts = {
|
111
32
|
:auto_echo => false,
|
112
|
-
:psuedo_tty =>
|
113
|
-
:
|
114
|
-
:
|
33
|
+
:psuedo_tty => true,
|
34
|
+
:ssh_identity => "#{ENV['HOME'].shellescape}/.vagrant.d/insecure_private_key",
|
35
|
+
:ssh_user => "vagrant",
|
36
|
+
:ssh_host => maybe(Hobo.project_config.hostname) || ""
|
115
37
|
}.merge(opts)
|
116
38
|
end
|
117
39
|
|
@@ -122,84 +44,12 @@ module Hobo
|
|
122
44
|
return self
|
123
45
|
end
|
124
46
|
|
125
|
-
def < pipe
|
126
|
-
pipe = "echo '#{pipe.shellescape}'" if opts[:auto_echo]
|
127
|
-
@pipe_in_vm = pipe
|
128
|
-
@opts[:psuedo_tty] = false
|
129
|
-
return self
|
130
|
-
end
|
131
|
-
|
132
|
-
# TODO Refactor in to ssh helper with similar opts to shell helper
|
133
|
-
# TODO Migrate all vm_shell functionality this direction
|
134
|
-
def run
|
135
|
-
return if @command.nil?
|
136
|
-
opts = @@vm_inspector.ssh_config.merge(@opts)
|
137
|
-
|
138
|
-
Net::SSH::Simple.sync do
|
139
|
-
ssh_opts = {
|
140
|
-
:user => opts[:ssh_user],
|
141
|
-
:port => opts[:ssh_port],
|
142
|
-
:forward_agent => true,
|
143
|
-
:global_known_hosts_file => "/dev/null",
|
144
|
-
:paranoid => false,
|
145
|
-
:user_known_hosts_file => "/dev/null"
|
146
|
-
}
|
147
|
-
|
148
|
-
ssh_opts[:keys] = [opts[:ssh_identity]] if opts[:ssh_identity]
|
149
|
-
|
150
|
-
tmp = Tempfile.new "vm_command_exec"
|
151
|
-
|
152
|
-
begin
|
153
|
-
filename = File.basename(tmp.path)
|
154
|
-
remote_file = "/tmp/#{filename}"
|
155
|
-
tmp.write "#{@command}#{opts[:append]}"
|
156
|
-
tmp.close
|
157
|
-
|
158
|
-
scp_put opts[:ssh_host], tmp.path, remote_file, ssh_opts
|
159
|
-
result = ssh opts[:ssh_host], "cd #{opts[:pwd]}; exec /bin/bash #{remote_file}", ssh_opts
|
160
|
-
ssh opts[:ssh_host], "rm #{remote_file}", ssh_opts
|
161
|
-
|
162
|
-
# Throw exception if exit code not 0
|
163
|
-
|
164
|
-
return opts[:capture] ? result.stdout : result.success
|
165
|
-
ensure
|
166
|
-
tmp.unlink
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# TODO Speed up Vagrant SSH connections
|
172
|
-
# May need to be disabled for windows (mm_send_fd: UsePrivilegeSeparation=yes not supported)
|
173
|
-
# https://gist.github.com/jedi4ever/5657094
|
174
|
-
|
175
47
|
def to_s
|
176
|
-
|
177
|
-
|
178
|
-
psuedo_tty = opts[:psuedo_tty] ? "-t" : ""
|
179
|
-
|
180
|
-
ssh_command = [
|
181
|
-
"ssh",
|
182
|
-
"-o 'UserKnownHostsFile /dev/null'",
|
183
|
-
"-o 'StrictHostKeyChecking no'",
|
184
|
-
"-o 'ForwardAgent yes'",
|
185
|
-
"-o 'LogLevel FATAL'",
|
186
|
-
"-p #{opts[:ssh_port]}",
|
187
|
-
"-i #{opts[:ssh_identity].shellescape}",
|
188
|
-
psuedo_tty,
|
189
|
-
"#{opts[:ssh_user].shellescape}@#{opts[:ssh_host].shellescape}"
|
190
|
-
].join(" ")
|
191
|
-
|
192
|
-
pwd_set_command = " -- \"cd #{@opts[:pwd].shellescape}; exec /bin/bash"
|
193
|
-
|
194
|
-
vm_command = [
|
195
|
-
@pipe_in_vm,
|
196
|
-
@command
|
197
|
-
].compact.join(" | ")
|
198
|
-
|
48
|
+
psuedo_tty = @opts[:psuedo_tty] ? "-t" : ""
|
199
49
|
command = [
|
200
|
-
|
201
|
-
|
202
|
-
].compact.join("
|
50
|
+
"ssh -i #{opts[:ssh_identity]} #{psuedo_tty} #{opts[:ssh_user].shellescape}@#{opts[:ssh_host].shellescape}",
|
51
|
+
@command
|
52
|
+
].compact.join(" -- ")
|
203
53
|
|
204
54
|
[
|
205
55
|
@pipe,
|
@@ -214,4 +64,4 @@ module Hobo
|
|
214
64
|
end
|
215
65
|
end
|
216
66
|
|
217
|
-
include Hobo::Helper
|
67
|
+
include Hobo::Helper
|