lono 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lono/template.rb +25 -3
- data/lib/lono/version.rb +1 -1
- data/lib/starter_project/templates/user_data/db.sh.erb +3 -0
- data/spec/lib/lono_spec.rb +14 -0
- metadata +3 -3
data/lib/lono/template.rb
CHANGED
@@ -50,17 +50,39 @@ module Lono
|
|
50
50
|
%Q|{"Ref"=>"#{name}"}|
|
51
51
|
end
|
52
52
|
|
53
|
+
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html
|
54
|
+
def findinmap(*args)
|
55
|
+
args.map! {|x| x =~ /=>/ ? x : x.inspect }
|
56
|
+
%Q|{"Fn::FindInMap" => [ #{args.join(',')} ]}|
|
57
|
+
end
|
58
|
+
|
53
59
|
# transform each line of the bash script into a UserData compatiable with CF template.
|
54
60
|
# any {"Ref"=>"..."} string get turned into CF Hash elements
|
55
61
|
def transform(line)
|
56
|
-
|
57
|
-
data = line
|
58
|
-
|
62
|
+
# Fn::FindInMap transform, also takes care of nested Ref transform
|
63
|
+
data = evaluate(line,/({"Fn::FindInMap" => \[ .* \]})/)
|
64
|
+
|
65
|
+
# Ref transform
|
66
|
+
already_transformed = data.size > 1
|
67
|
+
unless already_transformed
|
68
|
+
data = evaluate(line,/({"Ref"=>".*?"})/)
|
69
|
+
end
|
70
|
+
|
71
|
+
# add newline at the end
|
59
72
|
if data[-1].is_a?(String)
|
60
73
|
data[0..-2] + ["#{data[-1]}\n"]
|
61
74
|
else
|
62
75
|
data + ["\n"]
|
63
76
|
end
|
64
77
|
end
|
78
|
+
|
79
|
+
# if regex found in line, the match is eval into ruby code
|
80
|
+
# returns array of evaluated items
|
81
|
+
# if regex pattern not found
|
82
|
+
# returns array with original line
|
83
|
+
def evaluate(line, regex)
|
84
|
+
data = line.split(regex)
|
85
|
+
data.map {|l| l.is_a?(String) && l.match(regex) ? eval(l) : l }
|
86
|
+
end
|
65
87
|
end
|
66
88
|
end
|
data/lib/lono/version.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/bin/bash -lexv
|
2
2
|
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
|
3
3
|
|
4
|
+
FINDINMAP_TEST=<%= findinmap("MapName", "TopLevelKey", "SecondLevelKey") %>
|
5
|
+
HOSTNAME_PREFIX=<%= findinmap("EnvironmentMapping", "HostnamePrefix", ref("Environment")) %>
|
6
|
+
|
4
7
|
echo <%= ref("AWS::StackName") %> > /tmp/stack_name
|
5
8
|
# Helper function
|
6
9
|
function error_exit
|
data/spec/lib/lono_spec.rb
CHANGED
@@ -34,6 +34,20 @@ describe Lono do
|
|
34
34
|
user_data = json['Resources']['server']['Properties']['UserData']['Fn::Base64']['Fn::Join'][1]
|
35
35
|
user_data.should include({"Ref" => "AWS::StackName"})
|
36
36
|
user_data.should include({"Ref" => "WaitHandle"})
|
37
|
+
user_data.should include({
|
38
|
+
"Fn::FindInMap" => [
|
39
|
+
"EnvironmentMapping",
|
40
|
+
"HostnamePrefix",
|
41
|
+
{"Ref" => "Environment"}
|
42
|
+
]
|
43
|
+
})
|
44
|
+
user_data.should include({
|
45
|
+
"Fn::FindInMap" => [
|
46
|
+
"MapName",
|
47
|
+
"TopLevelKey",
|
48
|
+
"SecondLevelKey"
|
49
|
+
]
|
50
|
+
})
|
37
51
|
end
|
38
52
|
|
39
53
|
it "should transform bash script to CF template user_data" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -244,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
244
|
version: '0'
|
245
245
|
requirements: []
|
246
246
|
rubyforge_project:
|
247
|
-
rubygems_version: 1.8.
|
247
|
+
rubygems_version: 1.8.25
|
248
248
|
signing_key:
|
249
249
|
specification_version: 3
|
250
250
|
summary: Lono is a Cloud Formation Template ruby generator. Lono generates Cloud
|