itamae 1.9.4 → 1.9.5

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: d6ca877086876cb9043c2ef01b6400e85ed2f69a
4
- data.tar.gz: 4d9d0142b4bc23876cff279291080f48bf1c07ed
3
+ metadata.gz: 69eb224b93a5e9bfb3144ea3a867c430335bd42b
4
+ data.tar.gz: 1cdcb57ab16cd5fcc3263ab47fb2c79a6d4505d8
5
5
  SHA512:
6
- metadata.gz: e12647212d06db1104f299fc2e5579cf1063dc720c3c3f662393c06678987800f484b7254a45c655bffa3ee4422048d573f2cba23e6ddc0f6e74cbd23023ed67
7
- data.tar.gz: c137de18d95c1ff7ddee2aa5110d1cb70c6b2e4e84fea742978df9bfcade9545686e961081b55279850e2aae2ec9519ece157b51401d44fa70f51ecc7433398d
6
+ metadata.gz: 7b99272fc2ec58d6ddb79054ef9613982011ac10d3674fcb2c53b22fc1f81def84f0d4975c3c151d9860c8e48919c776e26af315bd1000544191df880bb53269
7
+ data.tar.gz: 6e11b47673437f304e4a12e1bb3e0ee3a7893d9260929b7d39058f6571b08c65c35570395fcc06cfe05d41274cd1caab74b85287bc177e94df551e8f26895f82
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v1.9.5
2
+
3
+ Bugfixes
4
+
5
+ - [Set mode and owner correctly when file not changed (by @sorah)](https://github.com/itamae-kitchen/itamae/commit/438d79e4ef714f637f8f1cb50b01293e5232340a)
6
+ - [Make tempfile unreadable to secure (by @sorah)](https://github.com/itamae-kitchen/itamae/commit/7af1d29fc020e57f3587aace728fbb40e35669cf)
7
+ - [Accept any objects as a log message (by @abicky)](https://github.com/itamae-kitchen/itamae/pull/195)
8
+
1
9
  ## v1.9.4
2
10
 
3
11
  Bugfixes
data/lib/itamae/logger.rb CHANGED
@@ -48,10 +48,25 @@ module Itamae
48
48
  %w!debug info warn error fatal unknown!.each do |level|
49
49
  module_eval(<<-EOC, __FILE__, __LINE__ + 1)
50
50
  def #{level}(msg)
51
- super(" " * indent_depth + msg)
51
+ super(indent_msg(msg))
52
52
  end
53
53
  EOC
54
54
  end
55
+
56
+ private
57
+
58
+ def indent_msg(msg)
59
+ spaces = " " * indent_depth
60
+ case msg
61
+ when ::String
62
+ "#{spaces}#{msg}"
63
+ when ::Exception
64
+ "#{spaces}#{msg.message} (#{msg.class})\n" <<
65
+ (msg.backtrace || []).map {|f| "#{spaces}#{f}"}.join("\n")
66
+ else
67
+ "#{spaces}#{msg.inspect}"
68
+ end
69
+ end
55
70
  end
56
71
 
57
72
  class Formatter
@@ -60,15 +60,6 @@ module Itamae
60
60
  run_command(["touch", attributes.path])
61
61
  end
62
62
 
63
- change_target = @temppath || attributes.path
64
-
65
- if attributes.mode
66
- run_specinfra(:change_file_mode, change_target, attributes.mode)
67
- end
68
- if attributes.owner || attributes.group
69
- run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
70
- end
71
-
72
63
  if @temppath
73
64
  if run_specinfra(:check_file_is_file, attributes.path)
74
65
  unless check_command(["diff", "-q", @temppath, attributes.path])
@@ -79,10 +70,20 @@ module Itamae
79
70
  # new file
80
71
  updated!
81
72
  end
73
+ end
82
74
 
83
- if updated?
84
- run_specinfra(:move_file, @temppath, attributes.path)
85
- end
75
+ change_target = @temppath && updated? ? @temppath : attributes.path
76
+
77
+ if attributes.mode
78
+ run_specinfra(:change_file_mode, change_target, attributes.mode)
79
+ end
80
+
81
+ if attributes.owner || attributes.group
82
+ run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
83
+ end
84
+
85
+ if @temppath && updated?
86
+ run_specinfra(:move_file, @temppath, attributes.path)
86
87
  end
87
88
  end
88
89
 
@@ -170,7 +171,11 @@ module Itamae
170
171
  end
171
172
 
172
173
  @temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
174
+
175
+ run_command(["touch", @temppath])
176
+ run_specinfra(:change_file_mode, @temppath, '0600')
173
177
  backend.send_file(src, @temppath)
178
+ run_specinfra(:change_file_mode, @temppath, '0600')
174
179
  ensure
175
180
  f.unlink if f
176
181
  end
@@ -1 +1 @@
1
- 1.9.4
1
+ 1.9.5
@@ -232,3 +232,11 @@ end
232
232
  describe file('/tmp/file_edit_notifies') do
233
233
  its(:content) { should eq("1") }
234
234
  end
235
+
236
+ describe file('/tmp/file_without_content_change_updates_mode_and_owner') do
237
+ its(:content) { should eq("Hello, world") }
238
+ it { should be_mode 666 }
239
+ it { should be_owned_by "itamae2" }
240
+ it { should be_grouped_into "itamae2" }
241
+ end
242
+
@@ -402,6 +402,24 @@ end
402
402
 
403
403
  ###
404
404
 
405
+ file '/tmp/file_without_content_change_updates_mode_and_owner' do
406
+ action :create
407
+ content 'Hello, world'
408
+ owner 'itamae'
409
+ group 'itamae'
410
+ mode '444'
411
+ end
412
+
413
+ file '/tmp/file_without_content_change_updates_mode_and_owner' do
414
+ action :create
415
+ content 'Hello, world' # no change
416
+ owner 'itamae2'
417
+ group 'itamae2'
418
+ mode '666'
419
+ end
420
+
421
+ ###
422
+
405
423
  unless run_command("echo -n Hello").stdout == "Hello"
406
424
  raise "run_command in a recipe failed"
407
425
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ module Itamae
4
+ describe Logger do
5
+ describe "#debug" do
6
+ context "`msg` is a String" do
7
+ it "indents the message" do
8
+ expect_any_instance_of(::Logger).to receive(:debug).with(" msg")
9
+ Itamae.logger.with_indent do
10
+ Itamae.logger.debug("msg")
11
+ end
12
+ end
13
+ end
14
+
15
+ context "`msg` is an Exception" do
16
+ let(:msg) { ::Exception.new("error") }
17
+
18
+ before do
19
+ allow(msg).to receive(:backtrace) { %w!frame1 frame2! }
20
+ end
21
+
22
+ it "indents the error message and the backtrace" do
23
+ expect_any_instance_of(::Logger).to receive(:debug).with(<<-MSG.rstrip)
24
+ error (Exception)
25
+ frame1
26
+ frame2
27
+ MSG
28
+ Itamae.logger.with_indent do
29
+ Itamae.logger.debug(msg)
30
+ end
31
+ end
32
+ end
33
+
34
+ context "`msg` is an Array" do
35
+ it "indents the message" do
36
+ expect_any_instance_of(::Logger).to receive(:debug).with(" []")
37
+ Itamae.logger.with_indent do
38
+ Itamae.logger.debug([])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.4
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-06 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -286,6 +286,7 @@ files:
286
286
  - spec/unit/lib/itamae/handler/fluentd_spec.rb
287
287
  - spec/unit/lib/itamae/handler_proxy_spec.rb
288
288
  - spec/unit/lib/itamae/handler_spec.rb
289
+ - spec/unit/lib/itamae/logger_spec.rb
289
290
  - spec/unit/lib/itamae/node_spec.rb
290
291
  - spec/unit/lib/itamae/recipe_spec.rb
291
292
  - spec/unit/lib/itamae/resource/base_spec.rb
@@ -338,6 +339,7 @@ test_files:
338
339
  - spec/unit/lib/itamae/handler/fluentd_spec.rb
339
340
  - spec/unit/lib/itamae/handler_proxy_spec.rb
340
341
  - spec/unit/lib/itamae/handler_spec.rb
342
+ - spec/unit/lib/itamae/logger_spec.rb
341
343
  - spec/unit/lib/itamae/node_spec.rb
342
344
  - spec/unit/lib/itamae/recipe_spec.rb
343
345
  - spec/unit/lib/itamae/resource/base_spec.rb