cronicle 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/cronicle.rb +1 -0
- data/lib/cronicle/cli.rb +1 -1
- data/lib/cronicle/driver.rb +12 -21
- data/lib/cronicle/ext/sshkit_ext.rb +16 -3
- data/lib/cronicle/log_sniffer.rb +12 -0
- data/lib/cronicle/logger.rb +0 -25
- data/lib/cronicle/version.rb +1 -1
- data/spec/cronicle_exec_spec.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55990d68d863dd005a1f29102d53d908e20fab99
|
4
|
+
data.tar.gz: 8b01d9445e7e8c8d35ef5214efd14e129db06352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d1e3492bb2986148c5c29e41954da0bb0825000af875d8abbe898c7a81d87345c18cd2909a7a2e0fae9e9d16c64343f51fe1fed6a9af18c9147a0bde8064d89
|
7
|
+
data.tar.gz: 45de3981f26f42a144d12c55fe60e9e7e1b2c05fb30fad3adc6d3d52d339145fa8ffefe371d9fc17cffa6ebafab425e4feb59741b96e66c9eacda6da84b3c38a
|
data/README.md
CHANGED
data/lib/cronicle.rb
CHANGED
data/lib/cronicle/cli.rb
CHANGED
@@ -4,7 +4,7 @@ class Cronicle::CLI < Thor
|
|
4
4
|
class_option 'file', :aliases => '-f', :desc => 'Job definition file', :default => 'Jobfile'
|
5
5
|
class_option 'hosts', :aliases => '-h', :desc => 'Hosts definition file'
|
6
6
|
class_option 'target-roles', :aliases => '-r', :desc => 'Target host role list', :type => :array
|
7
|
-
class_option 'sudo-password', :aliases => '-p', :desc => 'Sudo password'
|
7
|
+
class_option 'sudo-password', :aliases => '-p', :desc => 'Sudo password', :default => ENV['CRONICLE_SUDO_PASSWORD']
|
8
8
|
class_option 'ssh-user', :desc => 'SSH login user', :default => ENV['CRONICLE_SSH_USER']
|
9
9
|
class_option 'ask-pass', :desc => 'Ask sudo password', :type => :boolean, :default => false
|
10
10
|
class_option 'dry-run', :desc => 'Do not actually change', :type => :boolean, :default => false
|
data/lib/cronicle/driver.rb
CHANGED
@@ -54,36 +54,27 @@ class Cronicle::Driver
|
|
54
54
|
end
|
55
55
|
|
56
56
|
upload_script(temp_dir, name, job[:content]) do |temp_script|
|
57
|
-
|
58
|
-
command = nil
|
57
|
+
host_user_job = {:host => host.hostname, :user => user, :job => name}
|
59
58
|
|
60
|
-
|
61
|
-
|
62
|
-
bundle(user, name, temp_dir)
|
59
|
+
sniffer = proc do |obj|
|
60
|
+
out = obj.kind_of?(SSHKit::Command) ? obj.stdout : obj.to_s
|
63
61
|
|
64
|
-
|
65
|
-
|
62
|
+
out.each_line do |line|
|
63
|
+
log_for_cronicle(:info, line, host_user_job)
|
66
64
|
end
|
67
|
-
else
|
68
|
-
command = sudo(:_execute, temp_script, exec_opts)
|
69
65
|
end
|
70
66
|
|
71
|
-
|
72
|
-
Cronicle::Utils.remove_prompt!(out)
|
73
|
-
host_user_job = {:host => host.hostname, :user => user, :job => name}
|
67
|
+
exec_opts = {:user => user, :raise_on_non_zero_exit => false, :sniffer => sniffer}
|
74
68
|
|
75
|
-
|
76
|
-
|
69
|
+
if job[:bundle]
|
70
|
+
mkgemfile(user, name, job[:bundle], temp_dir)
|
71
|
+
bundle(user, name, temp_dir)
|
77
72
|
|
78
|
-
|
79
|
-
|
73
|
+
with_bundle(user, name, temp_dir) do
|
74
|
+
sudo(:_execute, bundler_path, :exec, temp_script, exec_opts)
|
80
75
|
end
|
81
|
-
end
|
82
|
-
|
83
|
-
if command.exit_status.zero?
|
84
|
-
put_log.call(:info)
|
85
76
|
else
|
86
|
-
|
77
|
+
sudo(:_execute, temp_script, exec_opts)
|
87
78
|
end
|
88
79
|
end
|
89
80
|
end
|
@@ -6,12 +6,27 @@ class SSHKit::Backend::Netssh
|
|
6
6
|
|
7
7
|
alias _execute_orig _execute
|
8
8
|
|
9
|
+
def output
|
10
|
+
@output ||= SSHKit.config.output
|
11
|
+
end
|
12
|
+
|
9
13
|
def _execute(*args)
|
14
|
+
options = args.last.kind_of?(Hash) ? args.last : {}
|
15
|
+
orig_output = output
|
16
|
+
|
10
17
|
begin
|
18
|
+
if options[:sniffer]
|
19
|
+
@output = Cronicle::LogSniffer.new(orig_output) do |obj|
|
20
|
+
options[:sniffer].call(obj)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
11
24
|
_execute_orig(*args)
|
12
25
|
rescue => e
|
13
26
|
log_for_cronicle(:error, args.join(' '), :color => :red)
|
14
27
|
raise e
|
28
|
+
ensure
|
29
|
+
@output = orig_output
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
@@ -22,9 +37,7 @@ class SSHKit::Backend::Netssh
|
|
22
37
|
with_sudo = [:sudo, '-p', SUDO_PROMPT, '-S']
|
23
38
|
with_sudo << :sudo << '-u' << opts[:user] if opts[:user]
|
24
39
|
with_sudo.concat(args)
|
25
|
-
|
26
|
-
raise_on_non_zero_exit = opts.fetch(:raise_on_non_zero_exit, true)
|
27
|
-
send(command, *with_sudo, :raise_on_non_zero_exit => raise_on_non_zero_exit)
|
40
|
+
send(command, *with_sudo, opts)
|
28
41
|
end
|
29
42
|
|
30
43
|
Cronicle::Utils.remove_prompt!(retval) if retval.kind_of?(String)
|
data/lib/cronicle/logger.rb
CHANGED
@@ -63,31 +63,6 @@ class Cronicle::Logger < ::Logger
|
|
63
63
|
Cronicle::Logger.log(level, message, opts)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
|
-
class SSHKitIO
|
68
|
-
def initialize(io = $stdout)
|
69
|
-
@io = io
|
70
|
-
end
|
71
|
-
|
72
|
-
def <<(obj)
|
73
|
-
@io << mask_password(obj)
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
MASK_REGEXP = /\becho\s+([^|]+)\s+\|\s+sudo\s+-S\s+/
|
79
|
-
MASK = 'XXXXXXXX'
|
80
|
-
|
81
|
-
def mask_password(obj)
|
82
|
-
if obj.kind_of?(String) and obj =~ MASK_REGEXP
|
83
|
-
password = $1
|
84
|
-
obj.sub(password, MASK)
|
85
|
-
else
|
86
|
-
obj
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
66
|
end
|
91
67
|
|
92
|
-
SSHKit.config.output = SSHKit::Formatter::Pretty.new(Cronicle::Logger::SSHKitIO.new)
|
93
68
|
SSHKit.config.output_verbosity = :warn
|
data/lib/cronicle/version.rb
CHANGED
data/spec/cronicle_exec_spec.rb
CHANGED
@@ -55,10 +55,13 @@ describe 'Cronicle::Client#exec' do
|
|
55
55
|
foo on ubuntu/root> Execute job
|
56
56
|
foo on ubuntu/root>\s
|
57
57
|
foo on ubuntu/root> Linux
|
58
|
+
foo on ubuntu/root>\s
|
58
59
|
foo on ubuntu/root> root
|
60
|
+
foo on ubuntu/root>\s
|
59
61
|
bar on ubuntu/root> Execute job
|
60
62
|
bar on ubuntu/root>\s
|
61
63
|
bar on ubuntu/root> hello
|
64
|
+
bar on ubuntu/root>\s
|
62
65
|
EOS
|
63
66
|
end
|
64
67
|
end
|
@@ -139,7 +142,9 @@ describe 'Cronicle::Client#exec' do
|
|
139
142
|
foo on ubuntu/ubuntu> Execute job
|
140
143
|
foo on ubuntu/ubuntu>\s
|
141
144
|
foo on ubuntu/ubuntu> Linux
|
145
|
+
foo on ubuntu/ubuntu>\s
|
142
146
|
foo on ubuntu/ubuntu> ubuntu
|
147
|
+
foo on ubuntu/ubuntu>\s
|
143
148
|
EOS
|
144
149
|
end
|
145
150
|
end
|
@@ -206,7 +211,9 @@ describe 'Cronicle::Client#exec' do
|
|
206
211
|
foo on ubuntu/ubuntu> Execute job
|
207
212
|
foo on ubuntu/ubuntu>\s
|
208
213
|
foo on ubuntu/ubuntu> "My Mash on ubuntu"
|
214
|
+
foo on ubuntu/ubuntu>\s
|
209
215
|
foo on ubuntu/ubuntu> true
|
216
|
+
foo on ubuntu/ubuntu>\s
|
210
217
|
EOS
|
211
218
|
end
|
212
219
|
end
|
@@ -238,6 +245,7 @@ describe 'Cronicle::Client#exec' do
|
|
238
245
|
foo on amazon_linux/ec2-user> Execute job
|
239
246
|
foo on amazon_linux/ec2-user>\s
|
240
247
|
foo on amazon_linux/ec2-user> BAR
|
248
|
+
foo on amazon_linux/ec2-user>\s
|
241
249
|
EOS
|
242
250
|
end
|
243
251
|
|
@@ -246,6 +254,7 @@ describe 'Cronicle::Client#exec' do
|
|
246
254
|
foo on ubuntu/ubuntu> Execute job
|
247
255
|
foo on ubuntu/ubuntu>\s
|
248
256
|
foo on ubuntu/ubuntu> 100
|
257
|
+
foo on ubuntu/ubuntu>\s
|
249
258
|
EOS
|
250
259
|
end
|
251
260
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronicle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sourcify
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/cronicle/ext/net-ssh_ext.rb
|
224
224
|
- lib/cronicle/ext/sshkit_ext.rb
|
225
225
|
- lib/cronicle/host_list.rb
|
226
|
+
- lib/cronicle/log_sniffer.rb
|
226
227
|
- lib/cronicle/logger.rb
|
227
228
|
- lib/cronicle/utils.rb
|
228
229
|
- lib/cronicle/version.rb
|