script_executor 1.7.7 → 1.7.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +12 -18
- data/Gemfile.lock +28 -30
- data/gem_commands.thor +58 -0
- data/lib/script_executor/base_provision.rb +7 -7
- data/lib/script_executor/executable.rb +6 -6
- data/lib/script_executor/local_command.rb +16 -16
- data/lib/script_executor/output_buffer.rb +1 -1
- data/lib/script_executor/remote_command.rb +16 -16
- data/lib/script_executor/script_locator.rb +3 -3
- data/lib/script_executor/version.rb +1 -1
- data/script_executor.gemspec +11 -10
- data/script_executor.gemspec.erb +1 -1
- data/spec/base_provision_spec.rb +7 -7
- data/spec/executable_spec.rb +28 -29
- data/spec/script_locator_spec.rb +10 -10
- data/spec/scripts_parser_spec.rb +8 -8
- data/spec/support/base.conf.json +1 -1
- data/spec/thor_spec.rb +2 -2
- metadata +55 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9260fd1ef57e6a779709400660f5592a17588a7d
|
4
|
+
data.tar.gz: 848028cef518620b0976c483c6b1fd5f459910d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00274576926648bbb93503ce623d26fc83c1e91b8c9e2db55c1214091263a98a80ddfd707f6d1854d3cb6b4c99559ee4afa01ff58209aa5dd1d81c16572661de'
|
7
|
+
data.tar.gz: 24789ca514387eb737d4477b95b20fecd74b25651f5b77a03aedcb4349162db3ab7b904e7fcfefaca8f5624621a5df991c7be54d96e3476fdee8c066c52fef6e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.1
|
data/Gemfile
CHANGED
@@ -1,27 +1,21 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
group :default do
|
4
|
-
gem
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem 'thor',
|
4
|
+
gem 'highline', '1.7.8'
|
5
|
+
gem 'net-ssh', '4.1.0'
|
6
|
+
gem 'text-interpolator', '1.1.9'
|
7
|
+
gem 'json_pure', '2.1.0'
|
8
|
+
gem 'parslet', '1.8.0'
|
9
|
+
gem 'thor', '0.19.4'
|
10
10
|
end
|
11
11
|
|
12
12
|
group :development do
|
13
|
-
gem
|
14
|
-
gem
|
15
|
-
gem 'awesome_print',
|
13
|
+
gem 'gemspec_deps_gen', '1.1.2'
|
14
|
+
gem 'gemcutter', '0.7.1'
|
15
|
+
gem 'awesome_print', '1.8.0'
|
16
16
|
end
|
17
17
|
|
18
|
-
group :test do
|
19
|
-
gem
|
18
|
+
group :test, :default do
|
19
|
+
gem 'rspec', '3.6.0'
|
20
20
|
end
|
21
21
|
|
22
|
-
# group :debug do
|
23
|
-
# gem "ruby-debug-base19x", "0.11.30.pre12"
|
24
|
-
# gem "ruby-debug-ide", "0.4.17"
|
25
|
-
# end
|
26
|
-
|
27
|
-
|
data/Gemfile.lock
CHANGED
@@ -1,49 +1,47 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
awesome_print (1.
|
5
|
-
|
6
|
-
diff-lcs (1.2.5)
|
4
|
+
awesome_print (1.8.0)
|
5
|
+
diff-lcs (1.3)
|
7
6
|
file_utils (1.1.2)
|
8
7
|
gemcutter (0.7.1)
|
9
8
|
gemspec_deps_gen (1.1.2)
|
10
9
|
bundler
|
11
10
|
file_utils
|
12
11
|
highline (1.7.8)
|
13
|
-
json_pure (1.
|
14
|
-
net-ssh (
|
15
|
-
parslet (1.
|
16
|
-
|
17
|
-
|
18
|
-
rspec-
|
19
|
-
rspec-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rspec-expectations (3.3.1)
|
12
|
+
json_pure (2.1.0)
|
13
|
+
net-ssh (4.1.0)
|
14
|
+
parslet (1.8.0)
|
15
|
+
rspec (3.6.0)
|
16
|
+
rspec-core (~> 3.6.0)
|
17
|
+
rspec-expectations (~> 3.6.0)
|
18
|
+
rspec-mocks (~> 3.6.0)
|
19
|
+
rspec-core (3.6.0)
|
20
|
+
rspec-support (~> 3.6.0)
|
21
|
+
rspec-expectations (3.6.0)
|
24
22
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
23
|
+
rspec-support (~> 3.6.0)
|
24
|
+
rspec-mocks (3.6.0)
|
27
25
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-support (3.
|
26
|
+
rspec-support (~> 3.6.0)
|
27
|
+
rspec-support (3.6.0)
|
30
28
|
text-interpolator (1.1.9)
|
31
|
-
thor (0.19.
|
29
|
+
thor (0.19.4)
|
32
30
|
|
33
31
|
PLATFORMS
|
34
32
|
ruby
|
35
33
|
|
36
34
|
DEPENDENCIES
|
37
|
-
awesome_print (
|
38
|
-
gemcutter (
|
39
|
-
gemspec_deps_gen (
|
40
|
-
highline (
|
41
|
-
json_pure (
|
42
|
-
net-ssh (
|
43
|
-
parslet (
|
44
|
-
rspec (
|
45
|
-
text-interpolator (
|
46
|
-
thor (
|
35
|
+
awesome_print (= 1.8.0)
|
36
|
+
gemcutter (= 0.7.1)
|
37
|
+
gemspec_deps_gen (= 1.1.2)
|
38
|
+
highline (= 1.7.8)
|
39
|
+
json_pure (= 2.1.0)
|
40
|
+
net-ssh (= 4.1.0)
|
41
|
+
parslet (= 1.8.0)
|
42
|
+
rspec (= 3.6.0)
|
43
|
+
text-interpolator (= 1.1.9)
|
44
|
+
thor (= 0.19.4)
|
47
45
|
|
48
46
|
BUNDLED WITH
|
49
|
-
1.
|
47
|
+
1.15.1
|
data/gem_commands.thor
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require "thor"
|
6
|
+
require "script_executor/version"
|
7
|
+
require "gemspec_deps_gen/gemspec_deps_gen"
|
8
|
+
|
9
|
+
class GemCommands < Thor
|
10
|
+
|
11
|
+
def initialize *params
|
12
|
+
super
|
13
|
+
|
14
|
+
@version = ScriptExecutor::VERSION
|
15
|
+
@project_name = File.basename(Dir.pwd)
|
16
|
+
end
|
17
|
+
|
18
|
+
no_commands do
|
19
|
+
def generate
|
20
|
+
generator = GemspecDepsGen.new
|
21
|
+
|
22
|
+
generator.generate_dependencies "spec", "#{@project_name}.gemspec.erb", "#{@project_name}.gemspec"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "build", "build"
|
27
|
+
def build
|
28
|
+
generate
|
29
|
+
|
30
|
+
system "gem build #{@project_name}.gemspec"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "install", "install"
|
34
|
+
def install
|
35
|
+
system "gem install #{@project_name}-#{@version}.gem"
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "uninstall", "uninstall"
|
39
|
+
def uninstall
|
40
|
+
system "gem uninstall #{@project_name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "release", "release"
|
44
|
+
def release
|
45
|
+
invoke :build
|
46
|
+
system "gem push #{@project_name}-#{@version}.gem"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "rspec", "rspec"
|
50
|
+
def rspec *args
|
51
|
+
system "`which rspec` #{args.join(' ')}"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
if File.basename($0) != 'thor'
|
57
|
+
GemCommands.start
|
58
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
-
require
|
2
|
+
require 'highline'
|
3
3
|
|
4
4
|
require 'text_interpolator'
|
5
5
|
require 'script_executor/executable'
|
@@ -10,7 +10,7 @@ class BaseProvision
|
|
10
10
|
|
11
11
|
attr_reader :interpolator, :env, :script_list, :server_info
|
12
12
|
|
13
|
-
def initialize
|
13
|
+
def initialize(config_file_name, scripts_file_names)
|
14
14
|
@terminal = HighLine.new
|
15
15
|
@interpolator = TextInterpolator.new
|
16
16
|
|
@@ -27,17 +27,17 @@ class BaseProvision
|
|
27
27
|
create_script_methods
|
28
28
|
end
|
29
29
|
|
30
|
-
def run
|
30
|
+
def run(script_name, type=:string, env={})
|
31
31
|
execute(server_info) do
|
32
32
|
evaluate_script_body(script_list[script_name.to_sym][:code], env, type)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def ask_password
|
37
|
-
@terminal.ask(message) {
|
36
|
+
def ask_password(message)
|
37
|
+
@terminal.ask(message) {|q| q.echo = '*'}
|
38
38
|
end
|
39
39
|
|
40
|
-
def read_config
|
40
|
+
def read_config(config_file_name)
|
41
41
|
hash = JSON.parse(File.read(config_file_name), :symbolize_names => true)
|
42
42
|
|
43
43
|
result = interpolator.interpolate hash
|
@@ -55,7 +55,7 @@ class BaseProvision
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def create_thor_methods
|
58
|
+
def create_thor_methods(parent_class, type=:string)
|
59
59
|
if parent_class.ancestors.collect(&:to_s).include?('Thor')
|
60
60
|
provision = self
|
61
61
|
|
@@ -3,7 +3,7 @@ require 'script_executor/remote_command'
|
|
3
3
|
|
4
4
|
module Executable
|
5
5
|
|
6
|
-
def execute
|
6
|
+
def execute(params={}, &code)
|
7
7
|
params = params.clone # try not to destroy external hash
|
8
8
|
|
9
9
|
if params.class != Hash
|
@@ -17,7 +17,7 @@ module Executable
|
|
17
17
|
commands = locate_commands script, &code
|
18
18
|
|
19
19
|
if commands.nil?
|
20
|
-
output.puts
|
20
|
+
output.puts 'No command was provided!'
|
21
21
|
else
|
22
22
|
commands = sudo(commands) if params[:sudo]
|
23
23
|
|
@@ -38,7 +38,7 @@ module Executable
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def locate_commands
|
41
|
+
def locate_commands(script, &code)
|
42
42
|
if block_given?
|
43
43
|
commands_from_block &code
|
44
44
|
elsif script
|
@@ -48,7 +48,7 @@ module Executable
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def commands_from_block
|
51
|
+
def commands_from_block(&code)
|
52
52
|
s1 = code.call.split(/\n/)
|
53
53
|
s2 = s1.reject {|el| el.strip.size == 0 || el.empty?}
|
54
54
|
s3 = s2.collect {|el| el.strip}
|
@@ -56,7 +56,7 @@ module Executable
|
|
56
56
|
s3.join("\n")
|
57
57
|
end
|
58
58
|
|
59
|
-
def commands_from_object
|
59
|
+
def commands_from_object(object)
|
60
60
|
if object.class == String
|
61
61
|
object
|
62
62
|
elsif object.class == Array
|
@@ -66,7 +66,7 @@ module Executable
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
def sudo
|
69
|
+
def sudo(commands)
|
70
70
|
"sudo -S -p 'sudo password: ' -s -- '#{commands}'"
|
71
71
|
end
|
72
72
|
|
@@ -6,7 +6,7 @@ class LocalCommand
|
|
6
6
|
|
7
7
|
attr_reader :password, :suppress_output, :capture_output, :output_stream, :simulate
|
8
8
|
|
9
|
-
def initialize
|
9
|
+
def initialize(params)
|
10
10
|
params = sanitize_parameters params
|
11
11
|
|
12
12
|
@password = params[:password]
|
@@ -16,16 +16,16 @@ class LocalCommand
|
|
16
16
|
@output_stream = params[:output_stream]
|
17
17
|
end
|
18
18
|
|
19
|
-
def execute
|
19
|
+
def execute(commands, line_action)
|
20
20
|
print_commands commands, $stdout
|
21
21
|
|
22
22
|
unless simulate
|
23
23
|
storage = capture_output ? OutputBuffer.new : nil
|
24
24
|
output = if output_stream
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
output_stream
|
26
|
+
else
|
27
|
+
suppress_output ? nil : $stdout
|
28
|
+
end
|
29
29
|
|
30
30
|
commands = commands + inline_password(password) if password
|
31
31
|
|
@@ -50,10 +50,10 @@ class LocalCommand
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def print_commands
|
53
|
+
def print_commands(commands, output)
|
54
54
|
if simulate
|
55
|
-
output.puts
|
56
|
-
output.puts
|
55
|
+
output.puts 'Script:'
|
56
|
+
output.puts '-------'
|
57
57
|
|
58
58
|
lines = StringIO.new commands
|
59
59
|
|
@@ -61,10 +61,10 @@ class LocalCommand
|
|
61
61
|
output.puts line
|
62
62
|
end
|
63
63
|
|
64
|
-
output.puts
|
64
|
+
output.puts '-------'
|
65
65
|
else
|
66
|
-
output.puts
|
67
|
-
output.puts
|
66
|
+
output.puts 'Local execution:'
|
67
|
+
output.puts '-------'
|
68
68
|
|
69
69
|
lines = StringIO.new commands
|
70
70
|
|
@@ -72,15 +72,15 @@ class LocalCommand
|
|
72
72
|
output.puts line
|
73
73
|
end
|
74
74
|
|
75
|
-
output.puts
|
75
|
+
output.puts '-------'
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
def inline_password
|
80
|
-
password ? "<<EOF\n#{password}\nEOF" :
|
79
|
+
def inline_password(password)
|
80
|
+
password ? "<<EOF\n#{password}\nEOF" : ''
|
81
81
|
end
|
82
82
|
|
83
|
-
def sanitize_parameters
|
83
|
+
def sanitize_parameters(params)
|
84
84
|
params.each do |key, _|
|
85
85
|
params.delete(key) unless permitted_params.include? key.to_sym
|
86
86
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'script_executor/output_buffer'
|
2
2
|
require 'net/ssh'
|
3
|
-
require
|
3
|
+
require 'highline'
|
4
4
|
|
5
5
|
class RemoteCommand
|
6
6
|
attr_reader :host, :user, :options, :suppress_output, :capture_output, :output_stream, :simulate
|
7
7
|
|
8
|
-
def initialize
|
8
|
+
def initialize(params)
|
9
9
|
params = sanitize_parameters params
|
10
10
|
|
11
11
|
@host = params.delete(:domain)
|
@@ -20,8 +20,8 @@ class RemoteCommand
|
|
20
20
|
@options = params
|
21
21
|
end
|
22
22
|
|
23
|
-
def execute
|
24
|
-
options[:password] = HighLine.new.ask("Enter password for #{user}: ") {
|
23
|
+
def execute(commands, line_action)
|
24
|
+
options[:password] = HighLine.new.ask("Enter password for #{user}: ") {|q| q.echo = '*'} if options[:password].nil?
|
25
25
|
options[:user] = user
|
26
26
|
|
27
27
|
print commands, $stdout
|
@@ -29,10 +29,10 @@ class RemoteCommand
|
|
29
29
|
unless simulate
|
30
30
|
storage = capture_output ? OutputBuffer.new : nil
|
31
31
|
output = if output_stream
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
output_stream
|
33
|
+
else
|
34
|
+
suppress_output ? nil : $stdout
|
35
|
+
end
|
36
36
|
|
37
37
|
Net::SSH.start(host, user, options) do |session|
|
38
38
|
session.exec(commands) do |channel, _, line|
|
@@ -62,12 +62,12 @@ class RemoteCommand
|
|
62
62
|
|
63
63
|
private
|
64
64
|
|
65
|
-
def print
|
65
|
+
def print(commands, output)
|
66
66
|
ssh_command = ssh_command(user, host, options[:port], options[:identity_file])
|
67
67
|
|
68
68
|
if simulate
|
69
69
|
output.puts "Remote script: '#{ssh_command}'"
|
70
|
-
output.puts
|
70
|
+
output.puts '-------'
|
71
71
|
|
72
72
|
lines = StringIO.new commands
|
73
73
|
|
@@ -75,10 +75,10 @@ class RemoteCommand
|
|
75
75
|
output.puts line
|
76
76
|
end
|
77
77
|
|
78
|
-
output.puts
|
78
|
+
output.puts '-------'
|
79
79
|
else
|
80
80
|
output.puts "Remote execution on: '#{ssh_command}'"
|
81
|
-
output.puts
|
81
|
+
output.puts '-------'
|
82
82
|
|
83
83
|
lines = StringIO.new commands
|
84
84
|
|
@@ -86,11 +86,11 @@ class RemoteCommand
|
|
86
86
|
output.puts line
|
87
87
|
end
|
88
88
|
|
89
|
-
output.puts
|
89
|
+
output.puts '-------'
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
def ssh_command
|
93
|
+
def ssh_command(user, host, port, identity_file)
|
94
94
|
cmd = user ? host : "#{user}@#{host}"
|
95
95
|
|
96
96
|
cmd << " -i #{identity_file}" if identity_file
|
@@ -102,11 +102,11 @@ class RemoteCommand
|
|
102
102
|
"ssh #{cmd}"
|
103
103
|
end
|
104
104
|
|
105
|
-
def ask_password?
|
105
|
+
def ask_password?(line)
|
106
106
|
line =~ /^\[sudo\] password for user:/ || line =~ /sudo password:/ || line =~ /Password:/
|
107
107
|
end
|
108
108
|
|
109
|
-
def sanitize_parameters
|
109
|
+
def sanitize_parameters(params)
|
110
110
|
params.each do |key, _|
|
111
111
|
params.delete(key) unless permitted_params.include? key.to_sym
|
112
112
|
end
|
@@ -10,7 +10,7 @@ module ScriptLocator
|
|
10
10
|
@errors ||= []
|
11
11
|
end
|
12
12
|
|
13
|
-
def scripts
|
13
|
+
def scripts(file)
|
14
14
|
data = extract_data file
|
15
15
|
|
16
16
|
begin
|
@@ -24,7 +24,7 @@ module ScriptLocator
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def evaluate_script_body
|
27
|
+
def evaluate_script_body(content, env, type=:erb)
|
28
28
|
content = content.join("\n") if content.kind_of? Array
|
29
29
|
|
30
30
|
case type
|
@@ -48,7 +48,7 @@ module ScriptLocator
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def extract_data
|
51
|
+
def extract_data(file)
|
52
52
|
content = File.read(file)
|
53
53
|
|
54
54
|
index = content.index("__END__\n")
|
data/script_executor.gemspec
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path(File.dirname(__FILE__) + '/lib/script_executor/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "script_executor"
|
7
7
|
spec.summary = %q{This library helps to execute code, locally or remote over ssh}
|
8
|
-
spec.description = %q{This library helps to execute code, locally or remote over ssh}
|
8
|
+
spec.description = %q{This library helps to execute code, locally or remote over ssh.}
|
9
9
|
spec.email = "alexander.shvets@gmail.com"
|
10
10
|
spec.authors = ["Alexander Shvets"]
|
11
11
|
spec.homepage = "http://github.com/shvets/script_executor"
|
@@ -17,15 +17,16 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "highline", ["
|
21
|
-
spec.add_runtime_dependency "net-ssh", ["
|
22
|
-
spec.add_runtime_dependency "text-interpolator", ["
|
23
|
-
spec.add_runtime_dependency "json_pure", ["
|
24
|
-
spec.add_runtime_dependency "parslet", ["
|
25
|
-
spec.add_runtime_dependency "thor", ["
|
26
|
-
spec.
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
20
|
+
spec.add_runtime_dependency "highline", ["= 1.7.8"]
|
21
|
+
spec.add_runtime_dependency "net-ssh", ["= 4.1.0"]
|
22
|
+
spec.add_runtime_dependency "text-interpolator", ["= 1.1.9"]
|
23
|
+
spec.add_runtime_dependency "json_pure", ["= 2.1.0"]
|
24
|
+
spec.add_runtime_dependency "parslet", ["= 1.8.0"]
|
25
|
+
spec.add_runtime_dependency "thor", ["= 0.19.4"]
|
26
|
+
spec.add_runtime_dependency "rspec", ["= 3.6.0"]
|
27
|
+
spec.add_development_dependency "gemspec_deps_gen", ["= 1.1.2"]
|
28
|
+
spec.add_development_dependency "gemcutter", ["= 0.7.1"]
|
29
|
+
spec.add_development_dependency "awesome_print", ["= 1.8.0"]
|
29
30
|
|
30
31
|
end
|
31
32
|
|
data/script_executor.gemspec.erb
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path(File.dirname(__FILE__) + '/lib/script_executor/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "script_executor"
|
7
7
|
spec.summary = %q{This library helps to execute code, locally or remote over ssh}
|
8
|
-
spec.description = %q{This library helps to execute code, locally or remote over ssh}
|
8
|
+
spec.description = %q{This library helps to execute code, locally or remote over ssh.}
|
9
9
|
spec.email = "alexander.shvets@gmail.com"
|
10
10
|
spec.authors = ["Alexander Shvets"]
|
11
11
|
spec.homepage = "http://github.com/shvets/script_executor"
|
data/spec/base_provision_spec.rb
CHANGED
@@ -2,18 +2,18 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'script_executor/base_provision'
|
4
4
|
|
5
|
-
describe BaseProvision do
|
5
|
+
RSpec.describe BaseProvision do
|
6
6
|
subject { BaseProvision.new 'spec/support/base.conf.json', ['spec/support/script0.sh'] }
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'parses content from file' do
|
10
10
|
expect(subject.script_list.size).to equal(3)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
params = OpenStruct.new({name: 'some name',
|
14
|
+
describe '#run' do
|
15
|
+
it 'executes command with :erb type' do
|
16
|
+
params = OpenStruct.new({name: 'some name', 'project': {'home': 'root'}})
|
17
17
|
|
18
18
|
b = params.instance_eval { binding }
|
19
19
|
|
@@ -22,7 +22,7 @@ describe BaseProvision do
|
|
22
22
|
ap result
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
25
|
+
it 'executes command with :string type' do
|
26
26
|
params = {name: 'other name'}
|
27
27
|
|
28
28
|
result = subject.run 'test2', :string, subject.env.merge(params)
|
data/spec/executable_spec.rb
CHANGED
@@ -3,27 +3,27 @@ require 'rspec/mocks'
|
|
3
3
|
|
4
4
|
require 'executable'
|
5
5
|
|
6
|
-
describe Executable do
|
6
|
+
RSpec.describe Executable do
|
7
7
|
subject { Object.new.extend Executable }
|
8
8
|
|
9
9
|
before :all do
|
10
10
|
@password ||= HighLine.new.ask("Enter password for #{ENV['USER']}: ") { |q| q.echo = '*' }
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
13
|
+
describe 'local execution' do
|
14
14
|
before :all do
|
15
15
|
@local_info = {
|
16
16
|
:capture_output => true
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
result = subject.execute @local_info.merge(:script =>
|
20
|
+
it 'executes commands from :script parameter' do
|
21
|
+
result = subject.execute @local_info.merge(:script => 'whoami')
|
22
22
|
|
23
23
|
expect(result).to eq ENV['USER']
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'executes commands from the block of code' do
|
27
27
|
result = subject.execute @local_info do
|
28
28
|
%Q(
|
29
29
|
whoami
|
@@ -34,23 +34,22 @@ describe Executable do
|
|
34
34
|
expect(result).to eq "#{ENV['USER']}\n#{ENV['USER']}"
|
35
35
|
end
|
36
36
|
|
37
|
-
it
|
37
|
+
it 'executes commands from the block of code as sudo' do
|
38
38
|
result = subject.execute @local_info.merge(:sudo => true, :password => @password) do
|
39
39
|
%Q(
|
40
40
|
whoami
|
41
|
-
whoami
|
42
41
|
)
|
43
42
|
end
|
44
43
|
|
45
|
-
expect(result).to
|
44
|
+
expect(result).to match "root"
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
describe
|
48
|
+
describe 'remote execution' do
|
50
49
|
before :all do
|
51
50
|
@remote_info = {
|
52
51
|
:simulate => false,
|
53
|
-
:domain =>
|
52
|
+
:domain => 'localhost',
|
54
53
|
:user => ENV['USER'],
|
55
54
|
:password => @password,
|
56
55
|
:remote => true,
|
@@ -58,35 +57,35 @@ describe Executable do
|
|
58
57
|
}
|
59
58
|
end
|
60
59
|
|
61
|
-
it
|
62
|
-
result = subject.execute @remote_info.merge(:script =>
|
60
|
+
it 'executes commands from :script parameter' do
|
61
|
+
result = subject.execute @remote_info.merge(:script => 'whoami')
|
63
62
|
|
64
|
-
expect(result).to
|
63
|
+
expect(result).to match ENV['USER']
|
65
64
|
end
|
66
65
|
|
67
|
-
it
|
66
|
+
it 'executes commands from the block of code' do
|
68
67
|
result = subject.execute @remote_info do
|
69
68
|
%Q(
|
70
69
|
whoami
|
71
70
|
)
|
72
71
|
end
|
73
72
|
|
74
|
-
expect(result).to
|
73
|
+
expect(result).to match ENV['USER']
|
75
74
|
end
|
76
75
|
|
77
|
-
it
|
78
|
-
result = subject.execute @remote_info.merge(:script =>
|
76
|
+
it 'executes commands with :host parameter instead of :domain parameter' do
|
77
|
+
result = subject.execute @remote_info.merge(:script => 'whoami', :host => 'localhost', :domain => nil)
|
79
78
|
|
80
|
-
expect(result).to
|
79
|
+
expect(result).to match ENV['USER']
|
81
80
|
end
|
82
81
|
|
83
|
-
it
|
84
|
-
result = subject.execute @remote_info.merge(:script =>
|
82
|
+
it 'executes commands with :host parameter instead of :domain parameter' do
|
83
|
+
result = subject.execute @remote_info.merge(:script => 'whoami', home: 'some_home')
|
85
84
|
|
86
|
-
expect(result).to
|
85
|
+
expect(result).to match ENV['USER']
|
87
86
|
end
|
88
87
|
|
89
|
-
#it "
|
88
|
+
#it "executes sudo command" do
|
90
89
|
# result = subject.execute @remote_info.merge(:sudo => true, :password => @password, :suppress_output => false) do
|
91
90
|
# %Q(
|
92
91
|
# ~/apache-tomcat-7.0.34/bin/shutdown.sh
|
@@ -97,24 +96,24 @@ describe Executable do
|
|
97
96
|
#end
|
98
97
|
end
|
99
98
|
|
100
|
-
describe
|
99
|
+
describe 'vagrant' do
|
101
100
|
before :all do
|
102
101
|
@remote_info = {
|
103
|
-
:domain =>
|
104
|
-
:user =>
|
105
|
-
:password =>
|
102
|
+
:domain => '22.22.22.22',
|
103
|
+
:user => 'vagrant',
|
104
|
+
:password => 'vagrant',
|
106
105
|
:port => 2222,
|
107
106
|
:remote => true,
|
108
107
|
:capture_output => true
|
109
108
|
}
|
110
109
|
end
|
111
110
|
|
112
|
-
it
|
111
|
+
it 'executes commands from :script parameter' do
|
113
112
|
expect_any_instance_of(RemoteCommand).to receive(:execute).and_return 'vagrant'
|
114
113
|
|
115
|
-
result = subject.execute @remote_info.merge(:script =>
|
114
|
+
result = subject.execute @remote_info.merge(:script => 'whoami')
|
116
115
|
|
117
|
-
expect(result).to eq
|
116
|
+
expect(result).to eq 'vagrant'
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
data/spec/script_locator_spec.rb
CHANGED
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
require 'script_locator'
|
4
4
|
|
5
|
-
describe ScriptLocator do
|
5
|
+
RSpec.describe ScriptLocator do
|
6
6
|
|
7
7
|
subject { Object.new.extend ScriptLocator }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
9
|
+
describe '#scripts' do
|
10
|
+
it 'reads after __END__' do
|
11
11
|
file = __FILE__
|
12
12
|
|
13
13
|
scripts = subject.scripts(file)
|
@@ -15,7 +15,7 @@ describe ScriptLocator do
|
|
15
15
|
expect(scripts).not_to be_nil
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'reads from file completely if it does not have __END__ tag' do
|
19
19
|
file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
|
20
20
|
|
21
21
|
scripts = subject.scripts(file)
|
@@ -24,25 +24,25 @@ describe ScriptLocator do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
28
|
-
it
|
27
|
+
describe '#evaluate_script_body' do
|
28
|
+
it 'locates script inside current file' do
|
29
29
|
scripts = subject.scripts(__FILE__)
|
30
30
|
|
31
|
-
name =
|
31
|
+
name = 'alisa'
|
32
32
|
|
33
33
|
result = subject.evaluate_script_body(scripts[:test1][:code], binding)
|
34
34
|
|
35
35
|
expect(result).to match /#{name}/
|
36
36
|
|
37
|
-
expect(scripts[:test1][:comment]).to eq
|
37
|
+
expect(scripts[:test1][:comment]).to eq 'Some description'
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'locates script inside external file and evaluates it as string' do
|
41
41
|
file = File.expand_path('support/script4.sh', File.dirname(__FILE__))
|
42
42
|
|
43
43
|
scripts = subject.scripts(file)
|
44
44
|
|
45
|
-
env = {:name =>
|
45
|
+
env = {:name => 'alisa'}
|
46
46
|
|
47
47
|
result = subject.evaluate_script_body(scripts[:test1][:code], env, :string)
|
48
48
|
|
data/spec/scripts_parser_spec.rb
CHANGED
@@ -3,10 +3,10 @@ require 'spec_helper'
|
|
3
3
|
require 'script_executor/scripts_parser'
|
4
4
|
require 'script_executor/scripts_transform'
|
5
5
|
|
6
|
-
describe ScriptsParser do
|
6
|
+
RSpec.describe ScriptsParser do
|
7
7
|
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe '#parse' do
|
9
|
+
it 'parses content from file 1' do
|
10
10
|
content = File.read('spec/support/script1.sh')
|
11
11
|
|
12
12
|
parsed_content = subject.parse(content)
|
@@ -16,7 +16,7 @@ describe ScriptsParser do
|
|
16
16
|
ap transform parsed_content
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'parses content from file 2' do
|
20
20
|
content = File.read('spec/support/script2.sh')
|
21
21
|
|
22
22
|
parsed_content = subject.parse(content)
|
@@ -26,7 +26,7 @@ describe ScriptsParser do
|
|
26
26
|
ap transform parsed_content
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
29
|
+
it 'parses content from file 3' do
|
30
30
|
content = File.read('spec/support/script3.sh')
|
31
31
|
|
32
32
|
parsed_content = subject.parse(content)
|
@@ -36,7 +36,7 @@ describe ScriptsParser do
|
|
36
36
|
ap transform parsed_content
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'parses content from file 4' do
|
40
40
|
content = File.read('spec/support/script4.sh')
|
41
41
|
|
42
42
|
parsed_content = subject.parse(content)
|
@@ -46,7 +46,7 @@ describe ScriptsParser do
|
|
46
46
|
ap transform parsed_content
|
47
47
|
end
|
48
48
|
|
49
|
-
it
|
49
|
+
it 'parses content from file 5' do
|
50
50
|
content = File.read('spec/support/script5.sh')
|
51
51
|
|
52
52
|
parsed_content = subject.parse(content)
|
@@ -78,7 +78,7 @@ describe ScriptsParser do
|
|
78
78
|
# end
|
79
79
|
end
|
80
80
|
|
81
|
-
def transform
|
81
|
+
def transform(content)
|
82
82
|
script_transform = ScriptsTransform.new
|
83
83
|
|
84
84
|
script_transform.transform content
|
data/spec/support/base.conf.json
CHANGED
data/spec/thor_spec.rb
CHANGED
@@ -14,7 +14,7 @@ class ThorSpec < Thor
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe ThorSpec do
|
17
|
-
describe
|
17
|
+
describe '#invoke' do
|
18
18
|
it "executes thor without parameters" do
|
19
19
|
ThorSpec.provision.env[:name] = 'name'
|
20
20
|
|
@@ -23,7 +23,7 @@ describe ThorSpec do
|
|
23
23
|
expect(ThorSpec.provision.errors).to be_empty
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'executes thor with parameters' do
|
27
27
|
ThorSpec.provision.env[:name] = 'name'
|
28
28
|
|
29
29
|
subject.invoke :test3, ['a', 'b','c']
|
metadata
CHANGED
@@ -1,142 +1,156 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: script_executor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Shvets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.7.8
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.7.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: net-ssh
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: text-interpolator
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.1.9
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.1.9
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json_pure
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.1.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.1.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: parslet
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.8.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.8.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: thor
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.19.4
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.19.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.6.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.6.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: gemspec_deps_gen
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - '='
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 1.1.2
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - '='
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 1.1.2
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: gemcutter
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- -
|
129
|
+
- - '='
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: 0.7.1
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- -
|
136
|
+
- - '='
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 0.7.1
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: awesome_print
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
|
-
- -
|
143
|
+
- - '='
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
145
|
+
version: 1.8.0
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
|
-
- -
|
150
|
+
- - '='
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
139
|
-
description: This library helps to execute code, locally or remote over ssh
|
152
|
+
version: 1.8.0
|
153
|
+
description: This library helps to execute code, locally or remote over ssh.
|
140
154
|
email: alexander.shvets@gmail.com
|
141
155
|
executables: []
|
142
156
|
extensions: []
|
@@ -151,6 +165,7 @@ files:
|
|
151
165
|
- LICENSE
|
152
166
|
- README.md
|
153
167
|
- Rakefile
|
168
|
+
- gem_commands.thor
|
154
169
|
- lib/executable.rb
|
155
170
|
- lib/script_executor.rb
|
156
171
|
- lib/script_executor/base_provision.rb
|
@@ -199,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
214
|
version: '0'
|
200
215
|
requirements: []
|
201
216
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.6.11
|
203
218
|
signing_key:
|
204
219
|
specification_version: 4
|
205
220
|
summary: This library helps to execute code, locally or remote over ssh
|