itamae 1.1.19 → 1.1.20
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/itamae/recipe.rb +4 -0
- data/lib/itamae/resource/file.rb +7 -3
- data/lib/itamae/resource/remote_file.rb +40 -5
- data/lib/itamae/resource/template.rb +16 -4
- data/lib/itamae/version.txt +1 -1
- data/spec/integration/default_spec.rb +13 -9
- data/spec/integration/recipes/default.rb +11 -0
- data/spec/integration/recipes/files/remote_file_auto +1 -0
- data/spec/integration/recipes/templates/template_auto.erb +6 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ca9a458f030e2ec5d60c1bc8bd01d328a38203d
|
4
|
+
data.tar.gz: 69040c5649fe0ed36b626e51aca7bd936d2e66e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f30b1edb852c3835a93da78fe30414de0f29e526d1418c3404c022adc3ded024ec25d08d0967ae614e2c6eedd980e6db28fb7a3a917ea40bb404d0f2dc52b5
|
7
|
+
data.tar.gz: 324f116bd8332b90e5157456d888822e096df35c668dae41eec01f29ba96bb50370edf5b1276bc169b2624de639f32b4d27a190576602cab1d1df3f293587beb
|
data/CHANGELOG.md
CHANGED
data/lib/itamae/recipe.rb
CHANGED
data/lib/itamae/resource/file.rb
CHANGED
@@ -6,15 +6,14 @@ module Itamae
|
|
6
6
|
define_attribute :action, default: :create
|
7
7
|
define_attribute :path, type: String, default_name: true
|
8
8
|
define_attribute :content, type: String, default: ''
|
9
|
-
define_attribute :content_file, type: String
|
10
9
|
define_attribute :mode, type: String
|
11
10
|
define_attribute :owner, type: String
|
12
11
|
define_attribute :group, type: String
|
13
12
|
|
14
13
|
def pre_action
|
15
14
|
begin
|
16
|
-
src = if
|
17
|
-
|
15
|
+
src = if content_file
|
16
|
+
content_file
|
18
17
|
else
|
19
18
|
f = Tempfile.open('itamae')
|
20
19
|
f.write(attributes.content)
|
@@ -107,6 +106,11 @@ module Itamae
|
|
107
106
|
end
|
108
107
|
end
|
109
108
|
end
|
109
|
+
|
110
|
+
# will be overridden
|
111
|
+
def content_file
|
112
|
+
nil
|
113
|
+
end
|
110
114
|
end
|
111
115
|
end
|
112
116
|
end
|
@@ -3,13 +3,48 @@ require 'itamae'
|
|
3
3
|
module Itamae
|
4
4
|
module Resource
|
5
5
|
class RemoteFile < File
|
6
|
-
|
6
|
+
SourceNotFoundError = Class.new(StandardError)
|
7
7
|
|
8
|
-
|
9
|
-
attributes.content_file =
|
10
|
-
::File.expand_path(attributes.source, ::File.dirname(@recipe.path))
|
8
|
+
define_attribute :source, type: [String, Symbol], default: :auto
|
11
9
|
|
12
|
-
|
10
|
+
private
|
11
|
+
|
12
|
+
def content_file
|
13
|
+
source_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def source_file
|
17
|
+
@source_file ||= find_source_file
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_source_file
|
21
|
+
if attributes.source == :auto
|
22
|
+
dirs = attributes.path.split(::File::SEPARATOR)
|
23
|
+
dirs.shift if dirs.first == ""
|
24
|
+
|
25
|
+
searched_paths = []
|
26
|
+
dirs.size.times do |i|
|
27
|
+
path = ::File.join(@recipe.dir, source_file_dir, "#{dirs[i..-1].join("/")}#{source_file_ext}")
|
28
|
+
if ::File.exist?(path)
|
29
|
+
Logger.debug "#{path} is used as a source file."
|
30
|
+
return path
|
31
|
+
else
|
32
|
+
searched_paths << path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
raise SourceNotFoundError, "source file is not found (searched paths: #{searched_paths.join(', ')})"
|
37
|
+
else
|
38
|
+
::File.expand_path(attributes.source, @recipe.dir)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def source_file_dir
|
43
|
+
"files"
|
44
|
+
end
|
45
|
+
|
46
|
+
def source_file_ext
|
47
|
+
""
|
13
48
|
end
|
14
49
|
end
|
15
50
|
end
|
@@ -4,17 +4,29 @@ require 'tempfile'
|
|
4
4
|
|
5
5
|
module Itamae
|
6
6
|
module Resource
|
7
|
-
class Template <
|
8
|
-
define_attribute :source, type: String, required: true
|
7
|
+
class Template < RemoteFile
|
9
8
|
define_attribute :variables, type: Hash, default: {}
|
10
9
|
|
11
10
|
def pre_action
|
12
|
-
|
13
|
-
attributes.content = RenderContext.new(self).render_file(src)
|
11
|
+
attributes.content = RenderContext.new(self).render_file(source_file)
|
14
12
|
|
15
13
|
super
|
16
14
|
end
|
17
15
|
|
16
|
+
private
|
17
|
+
|
18
|
+
def content_file
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def source_file_dir
|
23
|
+
"templates"
|
24
|
+
end
|
25
|
+
|
26
|
+
def source_file_ext
|
27
|
+
".erb"
|
28
|
+
end
|
29
|
+
|
18
30
|
class RenderContext
|
19
31
|
def initialize(resource)
|
20
32
|
@resource = resource
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.20
|
@@ -22,9 +22,11 @@ describe package('resolvconf') do
|
|
22
22
|
it { should_not be_installed }
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
%w!/tmp/remote_file /tmp/remote_file_auto!.each do |f|
|
26
|
+
describe file(f) do
|
27
|
+
it { should be_file }
|
28
|
+
its(:content) { should match(/Hello Itamae/) }
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
32
|
describe file('/tmp/directory') do
|
@@ -34,12 +36,14 @@ describe file('/tmp/directory') do
|
|
34
36
|
it { should be_grouped_into "itamae" }
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
%w!/tmp/template /tmp/template_auto!.each do |f|
|
40
|
+
describe file(f) do
|
41
|
+
it { should be_file }
|
42
|
+
its(:content) { should match(/Hello/) }
|
43
|
+
its(:content) { should match(/Good bye/) }
|
44
|
+
its(:content) { should match(/^total memory: \d+kB$/) }
|
45
|
+
its(:content) { should match(/^uninitialized node key: $/) }
|
46
|
+
end
|
43
47
|
end
|
44
48
|
|
45
49
|
describe file('/tmp/file') do
|
@@ -85,6 +85,12 @@ remote_file "/tmp/remote_file" do
|
|
85
85
|
source "hello.txt"
|
86
86
|
end
|
87
87
|
|
88
|
+
remote_file "/tmp/remote_file_auto" do
|
89
|
+
source :auto
|
90
|
+
end
|
91
|
+
|
92
|
+
######
|
93
|
+
|
88
94
|
directory "/tmp/directory" do
|
89
95
|
mode "700"
|
90
96
|
owner "itamae"
|
@@ -96,6 +102,11 @@ template "/tmp/template" do
|
|
96
102
|
variables(goodbye: "Good bye")
|
97
103
|
end
|
98
104
|
|
105
|
+
template "/tmp/template_auto" do
|
106
|
+
source :auto
|
107
|
+
variables(goodbye: "Good bye")
|
108
|
+
end
|
109
|
+
|
99
110
|
file "/tmp/file" do
|
100
111
|
content "Hello World"
|
101
112
|
mode "777"
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello Itamae
|
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.1.
|
4
|
+
version: 1.1.20
|
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-03-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -189,11 +189,13 @@ files:
|
|
189
189
|
- spec/integration/default_spec.rb
|
190
190
|
- spec/integration/recipes/default.rb
|
191
191
|
- spec/integration/recipes/default2.rb
|
192
|
+
- spec/integration/recipes/files/remote_file_auto
|
192
193
|
- spec/integration/recipes/hello.erb
|
193
194
|
- spec/integration/recipes/hello.txt
|
194
195
|
- spec/integration/recipes/included.rb
|
195
196
|
- spec/integration/recipes/node.json
|
196
197
|
- spec/integration/recipes/redefine.rb
|
198
|
+
- spec/integration/recipes/templates/template_auto.erb
|
197
199
|
- spec/integration/spec_helper.rb
|
198
200
|
- spec/unit/lib/itamae/config_spec.rb
|
199
201
|
- spec/unit/lib/itamae/logger_spec.rb
|
@@ -233,11 +235,13 @@ test_files:
|
|
233
235
|
- spec/integration/default_spec.rb
|
234
236
|
- spec/integration/recipes/default.rb
|
235
237
|
- spec/integration/recipes/default2.rb
|
238
|
+
- spec/integration/recipes/files/remote_file_auto
|
236
239
|
- spec/integration/recipes/hello.erb
|
237
240
|
- spec/integration/recipes/hello.txt
|
238
241
|
- spec/integration/recipes/included.rb
|
239
242
|
- spec/integration/recipes/node.json
|
240
243
|
- spec/integration/recipes/redefine.rb
|
244
|
+
- spec/integration/recipes/templates/template_auto.erb
|
241
245
|
- spec/integration/spec_helper.rb
|
242
246
|
- spec/unit/lib/itamae/config_spec.rb
|
243
247
|
- spec/unit/lib/itamae/logger_spec.rb
|