itamae 1.2.13 → 1.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/itamae/backend.rb +24 -4
- data/lib/itamae/ext/specinfra.rb +37 -0
- data/lib/itamae/resource/base.rb +0 -19
- data/lib/itamae/resource/file.rb +37 -16
- data/lib/itamae/resource/remote_directory.rb +1 -1
- data/lib/itamae/version.txt +1 -1
- data/spec/integration/default_spec.rb +8 -0
- data/spec/integration/recipes/default.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2b12deeb334b692503acf71eb8055c762321c8
|
4
|
+
data.tar.gz: 59299025a68e4dded3bf4f5b35964cf8283e7aa8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e32608366152de7f363b6659e15091388ae4db4eec2503269bd01c8cadddffe499a1e4adc82dd9f8f7d2371739d509c0aea152d48eed74ffc778c006171cf00c
|
7
|
+
data.tar.gz: 509f6de4c65776642c32b77abb361c0ecb865babcc82e2825f46b424f6f1cc6edd58b936bd224828cc0e8b9dd4ad4c356ea378522e53296df847a9434a1b35f3
|
data/CHANGELOG.md
CHANGED
data/lib/itamae/backend.rb
CHANGED
@@ -107,12 +107,32 @@ module Itamae
|
|
107
107
|
@backend.command.get(*args)
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
111
|
-
|
110
|
+
def receive_file(src, dst = nil)
|
111
|
+
if dst
|
112
|
+
Logger.debug "Receiving a file from '#{src}' to '#{dst}'..."
|
113
|
+
else
|
114
|
+
Logger.debug "Receiving a file from '#{src}'..."
|
115
|
+
end
|
116
|
+
@backend.receive_file(src, dst)
|
112
117
|
end
|
113
118
|
|
114
|
-
def
|
115
|
-
|
119
|
+
def send_file(src, dst)
|
120
|
+
Logger.debug "Sending a file from '#{src}' to '#{dst}'..."
|
121
|
+
unless ::File.exist?(src)
|
122
|
+
raise Error, "The file '#{src}' doesn't exist."
|
123
|
+
end
|
124
|
+
@backend.send_file(src, dst)
|
125
|
+
end
|
126
|
+
|
127
|
+
def send_directory(src, dst)
|
128
|
+
Logger.debug "Sending a directory from '#{src}' to '#{dst}'..."
|
129
|
+
unless ::File.directory?(src)
|
130
|
+
raise Error, "'#{src}' is not directory."
|
131
|
+
end
|
132
|
+
unless ::File.exist?(src)
|
133
|
+
raise Error, "The directory '#{src}' doesn't exist."
|
134
|
+
end
|
135
|
+
@backend.send_directory(src, dst)
|
116
136
|
end
|
117
137
|
|
118
138
|
def host_inventory
|
data/lib/itamae/ext/specinfra.rb
CHANGED
@@ -1,2 +1,39 @@
|
|
1
1
|
# TODO: Send patches to Specinfra
|
2
2
|
|
3
|
+
module Specinfra
|
4
|
+
module Backend
|
5
|
+
class Base
|
6
|
+
def receive_file(from, to = nil)
|
7
|
+
raise NotImplementedError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Exec < Base
|
12
|
+
def receive_file(from, to = nil)
|
13
|
+
if to
|
14
|
+
FileUtils.cp(from, to)
|
15
|
+
else
|
16
|
+
::File.read(from)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Ssh < Exec
|
22
|
+
def receive_file(from, to = nil)
|
23
|
+
scp_download!(from, to)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def scp_download!(from, to, opt={})
|
29
|
+
if get_config(:scp).nil?
|
30
|
+
set_config(:scp, create_scp)
|
31
|
+
end
|
32
|
+
|
33
|
+
scp = get_config(:scp)
|
34
|
+
scp.download!(from, to, opt)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/lib/itamae/resource/base.rb
CHANGED
@@ -249,25 +249,6 @@ module Itamae
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
-
def send_file(src, dst)
|
253
|
-
Logger.debug "Sending a file from '#{src}' to '#{dst}'..."
|
254
|
-
unless ::File.exist?(src)
|
255
|
-
raise Error, "The file '#{src}' doesn't exist."
|
256
|
-
end
|
257
|
-
backend.send_file(src, dst)
|
258
|
-
end
|
259
|
-
|
260
|
-
def send_directory(src, dst)
|
261
|
-
Logger.debug "Sending a directory from '#{src}' to '#{dst}'..."
|
262
|
-
unless ::File.directory?(src)
|
263
|
-
raise Error, "'#{src}' is not directory."
|
264
|
-
end
|
265
|
-
unless ::File.exist?(src)
|
266
|
-
raise Error, "The directory '#{src}' doesn't exist."
|
267
|
-
end
|
268
|
-
backend.send_directory(src, dst)
|
269
|
-
end
|
270
|
-
|
271
252
|
def do_not_run_because_of_only_if?
|
272
253
|
@only_if_command &&
|
273
254
|
run_command(@only_if_command, error: false).exit_status != 0
|
data/lib/itamae/resource/file.rb
CHANGED
@@ -9,28 +9,23 @@ module Itamae
|
|
9
9
|
define_attribute :mode, type: String
|
10
10
|
define_attribute :owner, type: String
|
11
11
|
define_attribute :group, type: String
|
12
|
+
define_attribute :block, type: Proc, default: proc {}
|
12
13
|
|
13
14
|
def pre_action
|
14
|
-
begin
|
15
|
-
src = if content_file
|
16
|
-
content_file
|
17
|
-
else
|
18
|
-
f = Tempfile.open('itamae')
|
19
|
-
f.write(attributes.content)
|
20
|
-
f.close
|
21
|
-
f.path
|
22
|
-
end
|
23
|
-
|
24
|
-
@temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
|
25
|
-
send_file(src, @temppath)
|
26
|
-
ensure
|
27
|
-
f.unlink if f
|
28
|
-
end
|
29
|
-
|
30
15
|
case @current_action
|
31
16
|
when :create
|
32
17
|
attributes.exist = true
|
18
|
+
when :delete
|
19
|
+
attributes.exist = false
|
20
|
+
when :edit
|
21
|
+
attributes.exist = true
|
22
|
+
|
23
|
+
content = backend.receive_file(attributes.path)
|
24
|
+
attributes.block.call(content)
|
25
|
+
attributes.content = content
|
33
26
|
end
|
27
|
+
|
28
|
+
send_tempfile
|
34
29
|
end
|
35
30
|
|
36
31
|
def set_current_attributes
|
@@ -85,6 +80,14 @@ module Itamae
|
|
85
80
|
end
|
86
81
|
end
|
87
82
|
|
83
|
+
def action_edit(options)
|
84
|
+
run_command(['chmod', '--reference', attributes.path, @temppath])
|
85
|
+
run_command(['chown', '--reference', attributes.path, @temppath])
|
86
|
+
run_specinfra(:move_file, @temppath, attributes.path)
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
88
91
|
def show_file_diff
|
89
92
|
diff = run_command(["diff", "-u", attributes.path, @temppath], error: false)
|
90
93
|
if diff.exit_status == 0
|
@@ -111,6 +114,24 @@ module Itamae
|
|
111
114
|
def content_file
|
112
115
|
nil
|
113
116
|
end
|
117
|
+
|
118
|
+
def send_tempfile
|
119
|
+
begin
|
120
|
+
src = if content_file
|
121
|
+
content_file
|
122
|
+
else
|
123
|
+
f = Tempfile.open('itamae')
|
124
|
+
f.write(attributes.content)
|
125
|
+
f.close
|
126
|
+
f.path
|
127
|
+
end
|
128
|
+
|
129
|
+
@temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
|
130
|
+
backend.send_file(src, @temppath)
|
131
|
+
ensure
|
132
|
+
f.unlink if f
|
133
|
+
end
|
134
|
+
end
|
114
135
|
end
|
115
136
|
end
|
116
137
|
end
|
@@ -15,7 +15,7 @@ module Itamae
|
|
15
15
|
src = ::File.expand_path(directory, ::File.dirname(@recipe.path))
|
16
16
|
|
17
17
|
@temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
|
18
|
-
send_directory(src, @temppath)
|
18
|
+
backend.send_directory(src, @temppath)
|
19
19
|
|
20
20
|
case @current_action
|
21
21
|
when :create
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.14
|
@@ -146,3 +146,11 @@ describe file('/tmp/multi_immediately_notifies') do
|
|
146
146
|
it { should be_file }
|
147
147
|
its(:content) { should eq("1\n2\n3\n4\n") }
|
148
148
|
end
|
149
|
+
|
150
|
+
describe file('/tmp/file_edit_sample') do
|
151
|
+
it { should be_file }
|
152
|
+
its(:content) { should eq("Hello, Itamae") }
|
153
|
+
it { should be_mode 444 }
|
154
|
+
it { should be_owned_by "itamae" }
|
155
|
+
it { should be_grouped_into "itamae" }
|
156
|
+
end
|
@@ -277,3 +277,19 @@ end
|
|
277
277
|
execute 'echo 4 >> /tmp/multi_immediately_notifies' do
|
278
278
|
action :nothing
|
279
279
|
end
|
280
|
+
|
281
|
+
#####
|
282
|
+
|
283
|
+
file '/tmp/file_edit_sample' do
|
284
|
+
content 'Hello, world'
|
285
|
+
owner 'itamae'
|
286
|
+
group 'itamae'
|
287
|
+
mode '444'
|
288
|
+
end
|
289
|
+
|
290
|
+
file '/tmp/file_edit_sample' do
|
291
|
+
action :edit
|
292
|
+
block do |content|
|
293
|
+
content.gsub!('world', 'Itamae')
|
294
|
+
end
|
295
|
+
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.2.
|
4
|
+
version: 1.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|