cronicle 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11f5fe77a738b4c7a79a87b1251b64863fcad6ee
4
- data.tar.gz: fcc9dab5e28efb956caa314d6fc7c4b1e2453c3d
3
+ metadata.gz: bf65d92585b97645e66f532927dd044179ac70af
4
+ data.tar.gz: 21b90e95b86676a64b466dff15d8de0046526c12
5
5
  SHA512:
6
- metadata.gz: 72a43d752f2a204e52684c34be85229cb68f71df9c488870e089b2b29ab6f16ed2ff88bc0e9b31ab02062a61a3fc53c130d520c963fe679cb3f6939e1b90f35d
7
- data.tar.gz: 981d289443e799428e4cc77f3aa3b6337ea05ae6a7e6bda0827b4327b6beab20d0f491e838137438ea2b6476149fa40142e2c42d08cf9bfd63bab0469ce5c7b4
6
+ metadata.gz: fea9c1f8368743375665fc9d98354d23ebdfa8e4627739b9e45f4d83ed537dd03a6f87e1c7eb4a9873bf0697ae47a173232d44b11a3b7b98c9a3055fa36e8b34
7
+ data.tar.gz: 8712bbf81eda4185caca38cfebef69db7ffc8959e8a07213d7aff9336c187fe96ea872508e9b77f998d383a72f5a2dcc09b28cc3b2660a5f6c30b997b88721ca
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ Jobfile
17
17
  /.vagrant
18
18
  *.pem
19
19
  *.bak
20
+ /_site
data/README.md CHANGED
@@ -38,6 +38,7 @@ Options:
38
38
  [--ask-pass], [--no-ask-pass] # Ask sudo password
39
39
  [--dry-run], [--no-dry-run] # Do not actually change
40
40
  -c, [--ssh-config=SSH-CONFIG] # OpenSSH configuration file
41
+ [--ssh-options=SSH-OPTIONS] # SSH options (JSON)
41
42
  [--connection-timeout=N] # SSH connection timeout
42
43
  [--concurrency=N] # SSH concurrency
43
44
  # Default: 10
data/cronicle.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'parallel'
26
26
  spec.add_dependency 'diffy'
27
27
  spec.add_dependency 'highline'
28
+ spec.add_dependency 'unindent'
28
29
  spec.add_development_dependency 'bundler'
29
30
  spec.add_development_dependency 'rake'
30
31
  spec.add_development_dependency 'rspec', '>= 3.0.0'
data/lib/cronicle/cli.rb CHANGED
@@ -8,6 +8,7 @@ class Cronicle::CLI < Thor
8
8
  class_option 'ask-pass', :desc => 'Ask sudo password', :type => :boolean, :default => false
9
9
  class_option 'dry-run', :desc => 'Do not actually change', :type => :boolean, :default => false
10
10
  class_option 'ssh-config', :aliases => '-c', :desc => 'OpenSSH configuration file', :default => nil
11
+ class_option 'ssh-options', :desc => 'SSH options (JSON)', :default => nil
11
12
  class_option 'connection-timeout', :desc => 'SSH connection timeout', :type => :numeric, :default => nil
12
13
  class_option 'concurrency', :desc => 'SSH concurrency', :type => :numeric, :default => Cronicle::Client::DEFAULTS[:concurrency]
13
14
  class_option 'libexec', :desc => 'Cronicle libexec path', :default => Cronicle::Client::DEFAULTS[:libexec]
@@ -103,11 +104,19 @@ class Cronicle::CLI < Thor
103
104
 
104
105
  def set_ssh_options
105
106
  conn_timeout = options['connection-timeout']
106
- ssh_config = options['ssh-config']
107
+ ssh_options = {}
108
+
109
+ if options['ssh-options']
110
+ JSON.parse(options['ssh-options']).each do |key, value|
111
+ ssh_options[key.to_sym] = value
112
+ end
113
+ end
114
+
115
+ ssh_options[:config] = options['ssh-config'] if options['ssh-config']
107
116
 
108
117
  SSHKit::Backend::Netssh.configure do |ssh|
109
118
  ssh.connection_timeout = conn_timeout if conn_timeout
110
- ssh.ssh_options = {:config => ssh_config} if ssh_config
119
+ ssh.ssh_options = ssh_options unless ssh_options.empty?
111
120
  end
112
121
  end
113
122
  end
@@ -45,14 +45,14 @@ class Cronicle::DSL::Context::Job
45
45
 
46
46
  if block
47
47
  source = block.to_raw_source(:strip_enclosure => true).each_line.to_a
48
- source = source.shift + source.join.undent
48
+ source = source.shift + source.join.unindent
49
49
 
50
50
  job_hash[:content] = <<-RUBY
51
51
  #!/usr/bin/env ruby
52
52
  #{source}
53
53
  RUBY
54
54
  else
55
- job_hash[:content] = opts[:content].to_s.undent
55
+ job_hash[:content] = opts[:content].to_s.unindent
56
56
  end
57
57
  end
58
58
  end
@@ -0,0 +1,15 @@
1
+ class Net::SSH::Connection::Channel
2
+ alias on_data_orig on_data
3
+
4
+ def on_data(&block)
5
+ on_data_orig do |ch, data|
6
+ sudo_password = Thread.current[SSHKit::Backend::Netssh::SUDO_PASSWORD_KEY]
7
+
8
+ if sudo_password and data == SSHKit::Backend::Netssh::SUDO_PROMPT
9
+ ch.send_data(sudo_password + "\n")
10
+ else
11
+ block.call(ch, data) if block
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,18 +1,21 @@
1
1
  SSHKit::Backend::Netssh.config.pty = true
2
2
 
3
3
  class SSHKit::Backend::Netssh
4
+ SUDO_PASSWORD_KEY = :'__cronicle_sudo_password__'
5
+ SUDO_PROMPT = '__cronicle_sudo_prompt__'
6
+
4
7
  def sudo(command, *args)
5
8
  opts = args.last.kind_of?(Hash) ? args.pop : {}
6
9
 
7
- password = host.options[:sudo_password] || ''
8
- password = Shellwords.shellescape(password)
10
+ retval = with_sudo_password(host.options[:sudo_password]) do
11
+ with_sudo = [:sudo, '-p', SUDO_PROMPT, '-S']
12
+ with_sudo << '-u' << opts[:user] if opts[:user]
13
+ with_sudo.concat(args)
9
14
 
10
- with_sudo = [:echo, password, '|', :sudo, '-S']
11
- with_sudo << '-u' << opts[:user] if opts[:user]
12
- with_sudo.concat(args)
15
+ raise_on_non_zero_exit = opts.fetch(:raise_on_non_zero_exit, true)
16
+ send(command, *with_sudo, :raise_on_non_zero_exit => raise_on_non_zero_exit)
17
+ end
13
18
 
14
- raise_on_non_zero_exit = opts.fetch(:raise_on_non_zero_exit, true)
15
- retval = send(command, *with_sudo, :raise_on_non_zero_exit => raise_on_non_zero_exit)
16
19
  Cronicle::Utils.remove_prompt!(retval) if retval.kind_of?(String)
17
20
  retval
18
21
  end
@@ -33,7 +36,8 @@ class SSHKit::Backend::Netssh
33
36
 
34
37
  def list_crontabs
35
38
  cron_dir = find_cron_dir
36
- @crontab_list ||= sudo(:capture, :find, cron_dir, '-type', :f, '-maxdepth', 1, '2> /dev/null',
39
+ @crontab_list ||= sudo(:capture, :bash, '-c',
40
+ Shellwords.shellescape("find #{cron_dir} -type f 2> /dev/null"),
37
41
  :raise_on_non_zero_exit => false).each_line.map(&:strip)
38
42
  end
39
43
 
@@ -140,6 +144,15 @@ class SSHKit::Backend::Netssh
140
144
  def crlf_to_lf(str)
141
145
  str.gsub("\r\n", "\n")
142
146
  end
147
+
148
+ def with_sudo_password(password)
149
+ begin
150
+ Thread.current[SUDO_PASSWORD_KEY] = password
151
+ yield
152
+ ensure
153
+ Thread.current[SUDO_PASSWORD_KEY] = nil
154
+ end
155
+ end
143
156
  end
144
157
 
145
158
  class SSHKit::Host
@@ -1,3 +1,3 @@
1
1
  module Cronicle
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/cronicle.rb CHANGED
@@ -11,10 +11,11 @@ require 'sshkit'
11
11
  require 'sshkit/dsl'
12
12
  require 'tempfile'
13
13
  require 'thor'
14
+ require 'unindent'
14
15
 
15
16
  module Cronicle; end
16
17
  require 'cronicle/ext/hash_ext'
17
- require 'cronicle/ext/string_ext'
18
+ require 'cronicle/ext/net-ssh_ext'
18
19
  require 'cronicle/ext/sshkit_ext'
19
20
  require 'cronicle/logger'
20
21
  require 'cronicle/utils'
@@ -1,7 +1,7 @@
1
1
  describe 'Cronicle::Client#apply (create)' do
2
2
  context 'when empty cron' do
3
3
  let(:jobfile) do
4
- <<-RUBY.undent
4
+ <<-RUBY.unindent
5
5
  on servers: /.*/ do
6
6
  job :foo, user: :root, schedule: '1 2 * * *' do
7
7
  puts `uname`
@@ -10,7 +10,7 @@ describe 'Cronicle::Client#apply (create)' do
10
10
  end
11
11
 
12
12
  on servers: /.*/ do
13
- job :bar, user: :root, schedule: :@hourly, content: <<-SH.undent
13
+ job :bar, user: :root, schedule: :@hourly, content: <<-SH.unindent
14
14
  #!/bin/sh
15
15
  echo hello
16
16
  SH
@@ -63,18 +63,18 @@ describe 'Cronicle::Client#apply (create)' do
63
63
  expect(get_uname).to match /amzn/
64
64
  expect(get_crontabs).to eq amzn_crontab
65
65
 
66
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
66
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
67
67
  #!/usr/bin/env ruby
68
68
  puts `uname`
69
69
  puts `whoami`
70
70
  EOS
71
71
 
72
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
72
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
73
73
  #!/bin/sh
74
74
  echo hello
75
75
  EOS
76
76
 
77
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
77
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
78
78
  #!/usr/bin/env ruby
79
79
  puts 100
80
80
  EOS
@@ -86,18 +86,18 @@ describe 'Cronicle::Client#apply (create)' do
86
86
  expect(get_uname).to match /Ubuntu/
87
87
  expect(get_crontabs).to eq ubuntu_crontab
88
88
 
89
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
89
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
90
90
  #!/usr/bin/env ruby
91
91
  puts `uname`
92
92
  puts `whoami`
93
93
  EOS
94
94
 
95
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
95
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
96
96
  #!/bin/sh
97
97
  echo hello
98
98
  EOS
99
99
 
100
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
100
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
101
101
  #!/usr/bin/env ruby
102
102
  puts 200
103
103
  EOS
@@ -110,13 +110,13 @@ describe 'Cronicle::Client#apply (create)' do
110
110
  on TARGET_HOSTS do |ssh_options|
111
111
  user = ssh_options[:user]
112
112
 
113
- set_crontab user, <<-CRON.undent
113
+ set_crontab user, <<-CRON.unindent
114
114
  FOO=bar
115
115
  ZOO=baz
116
116
  1 1 1 1 1 echo #{user} > /dev/null
117
117
  CRON
118
118
 
119
- set_crontab :root, <<-CRON.undent
119
+ set_crontab :root, <<-CRON.unindent
120
120
  FOO=bar
121
121
  ZOO=baz
122
122
  1 1 1 1 1 echo root > /dev/null
@@ -125,7 +125,7 @@ describe 'Cronicle::Client#apply (create)' do
125
125
  end
126
126
 
127
127
  let(:jobfile) do
128
- <<-RUBY.undent
128
+ <<-RUBY.unindent
129
129
  on servers: /.*/ do
130
130
  job :foo, user: :root, schedule: '1 2 * * *' do
131
131
  puts `uname`
@@ -134,7 +134,7 @@ describe 'Cronicle::Client#apply (create)' do
134
134
  end
135
135
 
136
136
  on servers: /.*/ do
137
- job :bar, user: :root, schedule: :@hourly, content: <<-SH.undent
137
+ job :bar, user: :root, schedule: :@hourly, content: <<-SH.unindent
138
138
  #!/bin/sh
139
139
  echo hello
140
140
  SH
@@ -200,18 +200,18 @@ ZOO=baz
200
200
  expect(get_uname).to match /amzn/
201
201
  expect(get_crontabs).to eq amzn_crontab
202
202
 
203
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
203
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
204
204
  #!/usr/bin/env ruby
205
205
  puts `uname`
206
206
  puts `whoami`
207
207
  EOS
208
208
 
209
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
209
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
210
210
  #!/bin/sh
211
211
  echo hello
212
212
  EOS
213
213
 
214
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
214
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
215
215
  #!/usr/bin/env ruby
216
216
  puts 100
217
217
  EOS
@@ -223,18 +223,18 @@ ZOO=baz
223
223
  expect(get_uname).to match /Ubuntu/
224
224
  expect(get_crontabs).to eq ubuntu_crontab
225
225
 
226
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
226
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
227
227
  #!/usr/bin/env ruby
228
228
  puts `uname`
229
229
  puts `whoami`
230
230
  EOS
231
231
 
232
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
232
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
233
233
  #!/bin/sh
234
234
  echo hello
235
235
  EOS
236
236
 
237
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
237
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
238
238
  #!/usr/bin/env ruby
239
239
  puts 200
240
240
  EOS
@@ -3,20 +3,20 @@ describe 'Cronicle::Client#apply (update)' do
3
3
  on TARGET_HOSTS do |ssh_options|
4
4
  user = ssh_options[:user]
5
5
 
6
- set_crontab user, <<-CRON.undent
6
+ set_crontab user, <<-CRON.unindent
7
7
  FOO=bar
8
8
  ZOO=baz
9
9
  1 1 1 1 1 echo #{user} > /dev/null
10
10
  CRON
11
11
 
12
- set_crontab :root, <<-CRON.undent
12
+ set_crontab :root, <<-CRON.unindent
13
13
  FOO=bar
14
14
  ZOO=baz
15
15
  1 1 1 1 1 echo root > /dev/null
16
16
  CRON
17
17
  end
18
18
 
19
- cronicle(:apply) { <<-RUBY.undent }
19
+ cronicle(:apply) { <<-RUBY.unindent }
20
20
  on servers: /.*/ do
21
21
  job :foo, user: :root, schedule: '1 2 * * *' do
22
22
  puts `uname`
@@ -25,7 +25,7 @@ describe 'Cronicle::Client#apply (update)' do
25
25
  end
26
26
 
27
27
  on servers: /.*/ do
28
- job :bar, user: :root, schedule: :@hourly, content: <<-SH.undent
28
+ job :bar, user: :root, schedule: :@hourly, content: <<-SH.unindent
29
29
  #!/bin/sh
30
30
  echo hello
31
31
  SH
@@ -82,7 +82,7 @@ ZOO=baz
82
82
  end
83
83
 
84
84
  let(:jobfile) do
85
- <<-RUBY.undent
85
+ <<-RUBY.unindent
86
86
  on servers: /.*/ do
87
87
  job :foo, user: :root, schedule: '1 2 * * *' do
88
88
  puts `uname`
@@ -137,18 +137,18 @@ ZOO=baz
137
137
  expect(get_uname).to match /amzn/
138
138
  expect(get_crontabs).to eq amzn_crontab_orig
139
139
 
140
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
140
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
141
141
  #!/usr/bin/env ruby
142
142
  puts `uname`
143
143
  puts `whoami`
144
144
  EOS
145
145
 
146
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
146
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
147
147
  #!/bin/sh
148
148
  echo hello
149
149
  EOS
150
150
 
151
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
151
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
152
152
  #!/usr/bin/env ruby
153
153
  puts 100
154
154
  EOS
@@ -158,18 +158,18 @@ ZOO=baz
158
158
  expect(get_uname).to match /Ubuntu/
159
159
  expect(get_crontabs).to eq ubuntu_crontab_orig
160
160
 
161
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
161
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
162
162
  #!/usr/bin/env ruby
163
163
  puts `uname`
164
164
  puts `whoami`
165
165
  EOS
166
166
 
167
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
167
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
168
168
  #!/bin/sh
169
169
  echo hello
170
170
  EOS
171
171
 
172
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
172
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
173
173
  #!/usr/bin/env ruby
174
174
  puts 200
175
175
  EOS
@@ -181,13 +181,13 @@ ZOO=baz
181
181
  expect(get_uname).to match /amzn/
182
182
  expect(get_crontabs).to eq amzn_crontab
183
183
 
184
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
184
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
185
185
  #!/usr/bin/env ruby
186
186
  puts `uname`
187
187
  puts `whoami`
188
188
  EOS
189
189
 
190
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
190
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
191
191
  #!/usr/bin/env ruby
192
192
  puts 100
193
193
  EOS
@@ -197,7 +197,7 @@ ZOO=baz
197
197
  expect(get_uname).to match /Ubuntu/
198
198
  expect(get_crontabs).to eq ubuntu_crontab
199
199
 
200
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
200
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
201
201
  #!/usr/bin/env ruby
202
202
  puts `uname`
203
203
  puts `whoami`
@@ -248,18 +248,18 @@ ZOO=baz
248
248
  expect(get_uname).to match /amzn/
249
249
  expect(get_crontabs).to eq amzn_crontab_orig
250
250
 
251
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
251
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
252
252
  #!/usr/bin/env ruby
253
253
  puts `uname`
254
254
  puts `whoami`
255
255
  EOS
256
256
 
257
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
257
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
258
258
  #!/bin/sh
259
259
  echo hello
260
260
  EOS
261
261
 
262
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
262
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
263
263
  #!/usr/bin/env ruby
264
264
  puts 100
265
265
  EOS
@@ -269,18 +269,18 @@ ZOO=baz
269
269
  expect(get_uname).to match /Ubuntu/
270
270
  expect(get_crontabs).to eq ubuntu_crontab_orig
271
271
 
272
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
272
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
273
273
  #!/usr/bin/env ruby
274
274
  puts `uname`
275
275
  puts `whoami`
276
276
  EOS
277
277
 
278
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
278
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
279
279
  #!/bin/sh
280
280
  echo hello
281
281
  EOS
282
282
 
283
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
283
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
284
284
  #!/usr/bin/env ruby
285
285
  puts 200
286
286
  EOS
@@ -292,18 +292,18 @@ ZOO=baz
292
292
  expect(get_uname).to match /amzn/
293
293
  expect(get_crontabs).to eq amzn_crontab_orig
294
294
 
295
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
295
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
296
296
  #!/usr/bin/env ruby
297
297
  puts `uname`
298
298
  puts `whoami`
299
299
  EOS
300
300
 
301
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
301
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
302
302
  #!/bin/sh
303
303
  echo hello
304
304
  EOS
305
305
 
306
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
306
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
307
307
  #!/usr/bin/env ruby
308
308
  puts 100
309
309
  EOS
@@ -313,18 +313,18 @@ ZOO=baz
313
313
  expect(get_uname).to match /Ubuntu/
314
314
  expect(get_crontabs).to eq ubuntu_crontab_orig
315
315
 
316
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
316
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
317
317
  #!/usr/bin/env ruby
318
318
  puts `uname`
319
319
  puts `whoami`
320
320
  EOS
321
321
 
322
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
322
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
323
323
  #!/bin/sh
324
324
  echo hello
325
325
  EOS
326
326
 
327
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
327
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
328
328
  #!/usr/bin/env ruby
329
329
  puts 200
330
330
  EOS
@@ -16,7 +16,7 @@ describe 'Cronicle::Client#exec' do
16
16
 
17
17
  context 'run as root' do
18
18
  let(:jobfile) do
19
- <<-RUBY.undent
19
+ <<-RUBY.unindent
20
20
  on servers: /.*/ do
21
21
  job :foo, user: :root do
22
22
  puts `uname`
@@ -25,7 +25,7 @@ describe 'Cronicle::Client#exec' do
25
25
  end
26
26
 
27
27
  on servers: /.*/ do
28
- job :bar, user: :root, content: <<-SH.undent
28
+ job :bar, user: :root, content: <<-SH.unindent
29
29
  #!/bin/sh
30
30
  echo hello
31
31
  SH
@@ -39,21 +39,25 @@ describe 'Cronicle::Client#exec' do
39
39
  end
40
40
 
41
41
  it do
42
- expect(amzn_out).to eq <<-EOS.undent
42
+ expect(amzn_out).to eq <<-EOS.unindent
43
43
  foo on amazon_linux/root> Execute job
44
+ foo on amazon_linux/root>\s
44
45
  foo on amazon_linux/root> Linux
45
46
  foo on amazon_linux/root> root
46
47
  bar on amazon_linux/root> Execute job
48
+ bar on amazon_linux/root>\s
47
49
  bar on amazon_linux/root> hello
48
50
  EOS
49
51
  end
50
52
 
51
53
  it do
52
- expect(ubuntu_out).to eq <<-EOS.undent
54
+ expect(ubuntu_out).to eq <<-EOS.unindent
53
55
  foo on ubuntu/root> Execute job
56
+ foo on ubuntu/root>\s
54
57
  foo on ubuntu/root> Linux
55
58
  foo on ubuntu/root> root
56
59
  bar on ubuntu/root> Execute job
60
+ bar on ubuntu/root>\s
57
61
  bar on ubuntu/root> hello
58
62
  EOS
59
63
  end
@@ -61,7 +65,7 @@ describe 'Cronicle::Client#exec' do
61
65
 
62
66
  context 'run as root (dry-run)' do
63
67
  let(:jobfile) do
64
- <<-RUBY.undent
68
+ <<-RUBY.unindent
65
69
  on servers: /.*/ do
66
70
  job :foo, user: :root do
67
71
  puts `uname`
@@ -70,7 +74,7 @@ describe 'Cronicle::Client#exec' do
70
74
  end
71
75
 
72
76
  on servers: /.*/ do
73
- job :bar, user: :root, content: <<-SH.undent
77
+ job :bar, user: :root, content: <<-SH.unindent
74
78
  #!/bin/sh
75
79
  echo hello
76
80
  SH
@@ -84,14 +88,14 @@ describe 'Cronicle::Client#exec' do
84
88
  end
85
89
 
86
90
  it do
87
- expect(amzn_out).to eq <<-EOS.undent
91
+ expect(amzn_out).to eq <<-EOS.unindent
88
92
  foo on amazon_linux/root> Execute job (dry-run)
89
93
  bar on amazon_linux/root> Execute job (dry-run)
90
94
  EOS
91
95
  end
92
96
 
93
97
  it do
94
- expect(ubuntu_out).to eq <<-EOS.undent
98
+ expect(ubuntu_out).to eq <<-EOS.unindent
95
99
  foo on ubuntu/root> Execute job (dry-run)
96
100
  bar on ubuntu/root> Execute job (dry-run)
97
101
  EOS
@@ -100,7 +104,7 @@ describe 'Cronicle::Client#exec' do
100
104
 
101
105
  context 'run as non-root user' do
102
106
  let(:jobfile) do
103
- <<-RUBY.undent
107
+ <<-RUBY.unindent
104
108
  on servers: /amazon_linux/ do
105
109
  job :foo, user: 'ec2-user' do
106
110
  puts `uname`
@@ -122,7 +126,7 @@ describe 'Cronicle::Client#exec' do
122
126
  end
123
127
 
124
128
  it do
125
- expect(amzn_out).to eq <<-EOS.undent
129
+ expect(amzn_out).to eq <<-EOS.unindent
126
130
  foo on amazon_linux/ec2-user> Execute job
127
131
  foo on amazon_linux/ec2-user> Linux
128
132
  foo on amazon_linux/ec2-user> ec2-user
@@ -130,7 +134,7 @@ describe 'Cronicle::Client#exec' do
130
134
  end
131
135
 
132
136
  it do
133
- expect(ubuntu_out).to eq <<-EOS.undent
137
+ expect(ubuntu_out).to eq <<-EOS.unindent
134
138
  foo on ubuntu/ubuntu> Execute job
135
139
  foo on ubuntu/ubuntu> Linux
136
140
  foo on ubuntu/ubuntu> ubuntu
@@ -140,7 +144,7 @@ describe 'Cronicle::Client#exec' do
140
144
 
141
145
  context 'jon is not defined' do
142
146
  let(:jobfile) do
143
- <<-RUBY.undent
147
+ <<-RUBY.unindent
144
148
  on servers: /.*/ do
145
149
  job :foo, user: :root do
146
150
  puts `uname`
@@ -3,20 +3,20 @@ describe 'Cronicle::Client#apply (update)' do
3
3
  on TARGET_HOSTS do |ssh_options|
4
4
  user = ssh_options[:user]
5
5
 
6
- set_crontab user, <<-CRON.undent
6
+ set_crontab user, <<-CRON.unindent
7
7
  FOO=bar
8
8
  ZOO=baz
9
9
  1 1 1 1 1 echo #{user} > /dev/null
10
10
  CRON
11
11
 
12
- set_crontab :root, <<-CRON.undent
12
+ set_crontab :root, <<-CRON.unindent
13
13
  FOO=bar
14
14
  ZOO=baz
15
15
  1 1 1 1 1 echo root > /dev/null
16
16
  CRON
17
17
  end
18
18
 
19
- cronicle(:apply) { <<-RUBY.undent }
19
+ cronicle(:apply) { <<-RUBY.unindent }
20
20
  on servers: /.*/ do
21
21
  job :foo, user: :root, schedule: '1 2 * * *' do
22
22
  puts `uname`
@@ -25,7 +25,7 @@ describe 'Cronicle::Client#apply (update)' do
25
25
  end
26
26
 
27
27
  on servers: /.*/ do
28
- job :bar, user: :root, schedule: :@hourly, content: <<-SH.undent
28
+ job :bar, user: :root, schedule: :@hourly, content: <<-SH.unindent
29
29
  #!/bin/sh
30
30
  echo hello
31
31
  SH
@@ -82,7 +82,7 @@ ZOO=baz
82
82
  end
83
83
 
84
84
  let(:jobfile) do
85
- <<-RUBY.undent
85
+ <<-RUBY.unindent
86
86
  on servers: /.*/ do
87
87
  job :foo, user: :root, schedule: '1 2 * * *' do
88
88
  puts `uname`
@@ -91,7 +91,7 @@ ZOO=baz
91
91
  end
92
92
 
93
93
  on servers: /.*/ do
94
- job :bar, user: :root, schedule: :@hourly, content: <<-SH.undent
94
+ job :bar, user: :root, schedule: :@hourly, content: <<-SH.unindent
95
95
  #!/bin/sh
96
96
  echo hello
97
97
  SH
@@ -153,18 +153,18 @@ ZOO=baz
153
153
  expect(get_uname).to match /amzn/
154
154
  expect(get_crontabs).to eq amzn_crontab_orig
155
155
 
156
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
156
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
157
157
  #!/usr/bin/env ruby
158
158
  puts `uname`
159
159
  puts `whoami`
160
160
  EOS
161
161
 
162
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
162
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
163
163
  #!/bin/sh
164
164
  echo hello
165
165
  EOS
166
166
 
167
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
167
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
168
168
  #!/usr/bin/env ruby
169
169
  puts 100
170
170
  EOS
@@ -174,18 +174,18 @@ ZOO=baz
174
174
  expect(get_uname).to match /Ubuntu/
175
175
  expect(get_crontabs).to eq ubuntu_crontab_orig
176
176
 
177
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
177
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
178
178
  #!/usr/bin/env ruby
179
179
  puts `uname`
180
180
  puts `whoami`
181
181
  EOS
182
182
 
183
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
183
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
184
184
  #!/bin/sh
185
185
  echo hello
186
186
  EOS
187
187
 
188
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
188
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
189
189
  #!/usr/bin/env ruby
190
190
  puts 200
191
191
  EOS
@@ -197,18 +197,18 @@ ZOO=baz
197
197
  expect(get_uname).to match /amzn/
198
198
  expect(get_crontabs).to eq amzn_crontab
199
199
 
200
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
200
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
201
201
  #!/usr/bin/env ruby
202
202
  puts `uname`
203
203
  #puts `whoami`
204
204
  EOS
205
205
 
206
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
206
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
207
207
  #!/bin/sh
208
208
  echo hello
209
209
  EOS
210
210
 
211
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
211
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
212
212
  #!/usr/bin/env ruby
213
213
  puts 100
214
214
  EOS
@@ -218,18 +218,18 @@ ZOO=baz
218
218
  expect(get_uname).to match /Ubuntu/
219
219
  expect(get_crontabs).to eq ubuntu_crontab
220
220
 
221
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
221
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
222
222
  #!/usr/bin/env ruby
223
223
  puts `uname`
224
224
  #puts `whoami`
225
225
  EOS
226
226
 
227
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
227
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
228
228
  #!/bin/sh
229
229
  echo hello
230
230
  EOS
231
231
 
232
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo2')).to eq <<-EOS.undent
232
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo2')).to eq <<-EOS.unindent
233
233
  #!/usr/bin/env ruby
234
234
  puts 200
235
235
  EOS
@@ -279,18 +279,18 @@ ZOO=baz
279
279
  expect(get_uname).to match /amzn/
280
280
  expect(get_crontabs).to eq amzn_crontab_orig
281
281
 
282
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
282
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
283
283
  #!/usr/bin/env ruby
284
284
  puts `uname`
285
285
  puts `whoami`
286
286
  EOS
287
287
 
288
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
288
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
289
289
  #!/bin/sh
290
290
  echo hello
291
291
  EOS
292
292
 
293
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
293
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
294
294
  #!/usr/bin/env ruby
295
295
  puts 100
296
296
  EOS
@@ -300,18 +300,18 @@ ZOO=baz
300
300
  expect(get_uname).to match /Ubuntu/
301
301
  expect(get_crontabs).to eq ubuntu_crontab_orig
302
302
 
303
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
303
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
304
304
  #!/usr/bin/env ruby
305
305
  puts `uname`
306
306
  puts `whoami`
307
307
  EOS
308
308
 
309
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
309
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
310
310
  #!/bin/sh
311
311
  echo hello
312
312
  EOS
313
313
 
314
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
314
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
315
315
  #!/usr/bin/env ruby
316
316
  puts 200
317
317
  EOS
@@ -323,18 +323,18 @@ ZOO=baz
323
323
  expect(get_uname).to match /amzn/
324
324
  expect(get_crontabs).to eq amzn_crontab_orig
325
325
 
326
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
326
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
327
327
  #!/usr/bin/env ruby
328
328
  puts `uname`
329
329
  puts `whoami`
330
330
  EOS
331
331
 
332
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
332
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
333
333
  #!/bin/sh
334
334
  echo hello
335
335
  EOS
336
336
 
337
- expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.undent
337
+ expect(get_file('/var/lib/cronicle/libexec/ec2-user/foo')).to eq <<-EOS.unindent
338
338
  #!/usr/bin/env ruby
339
339
  puts 100
340
340
  EOS
@@ -344,18 +344,18 @@ ZOO=baz
344
344
  expect(get_uname).to match /Ubuntu/
345
345
  expect(get_crontabs).to eq ubuntu_crontab_orig
346
346
 
347
- expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.undent
347
+ expect(get_file('/var/lib/cronicle/libexec/root/foo')).to eq <<-EOS.unindent
348
348
  #!/usr/bin/env ruby
349
349
  puts `uname`
350
350
  puts `whoami`
351
351
  EOS
352
352
 
353
- expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.undent
353
+ expect(get_file('/var/lib/cronicle/libexec/root/bar')).to eq <<-EOS.unindent
354
354
  #!/bin/sh
355
355
  echo hello
356
356
  EOS
357
357
 
358
- expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.undent
358
+ expect(get_file('/var/lib/cronicle/libexec/ubuntu/foo')).to eq <<-EOS.unindent
359
359
  #!/usr/bin/env ruby
360
360
  puts 200
361
361
  EOS
@@ -19,7 +19,7 @@ describe Cronicle::HostList do
19
19
 
20
20
  context 'when list is passed' do
21
21
  let(:source) do
22
- <<-EOS.undent
22
+ <<-EOS.unindent
23
23
  foo
24
24
  bar
25
25
  EOS
@@ -41,7 +41,7 @@ describe Cronicle::HostList do
41
41
  context 'when JSON(servers) is passed' do
42
42
  context 'when single server' do
43
43
  let(:source) do
44
- <<-EOS.undent
44
+ <<-EOS.unindent
45
45
  {
46
46
  "servers": "foo"
47
47
  }
@@ -63,7 +63,7 @@ describe Cronicle::HostList do
63
63
 
64
64
  context 'when multiple servers' do
65
65
  let(:source) do
66
- <<-EOS.undent
66
+ <<-EOS.unindent
67
67
  {
68
68
  "servers": ["foo", "bar"]
69
69
  }
@@ -85,7 +85,7 @@ describe Cronicle::HostList do
85
85
 
86
86
  context 'when multiple servers with role' do
87
87
  let(:source) do
88
- <<-EOS.undent
88
+ <<-EOS.unindent
89
89
  {
90
90
  "servers": {
91
91
  "foo": "db",
@@ -112,7 +112,7 @@ describe Cronicle::HostList do
112
112
  context 'when JSON(roles) is passed' do
113
113
  context 'when single server' do
114
114
  let(:source) do
115
- <<-EOS.undent
115
+ <<-EOS.unindent
116
116
  {
117
117
  "roles": {
118
118
  "web": "bar"
@@ -136,7 +136,7 @@ describe Cronicle::HostList do
136
136
 
137
137
  context 'when multiple servers' do
138
138
  let(:source) do
139
- <<-EOS.undent
139
+ <<-EOS.unindent
140
140
  {
141
141
  "roles": {
142
142
  "db": ["foo", "bar"],
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.1.1
4
+ version: 0.1.2
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-02-08 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sourcify
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: unindent
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -192,8 +206,8 @@ files:
192
206
  - lib/cronicle/dsl/context/job.rb
193
207
  - lib/cronicle/exporter.rb
194
208
  - lib/cronicle/ext/hash_ext.rb
209
+ - lib/cronicle/ext/net-ssh_ext.rb
195
210
  - lib/cronicle/ext/sshkit_ext.rb
196
- - lib/cronicle/ext/string_ext.rb
197
211
  - lib/cronicle/host_list.rb
198
212
  - lib/cronicle/logger.rb
199
213
  - lib/cronicle/utils.rb
@@ -1,11 +0,0 @@
1
- class String
2
- def undent
3
- min_space_num = self.split("\n").delete_if {|s| s =~ /^\s*$/ }.map {|s| (s[/^\s+/] || '').length }.min
4
-
5
- if min_space_num and min_space_num > 0
6
- gsub(/^[ \t]{,#{min_space_num}}/, '')
7
- else
8
- self
9
- end
10
- end
11
- end