cloud_former 0.5.13 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloud_former.rb +7 -9
- data/lib/cloud_former/conditions/condition.rb +13 -8
- data/lib/cloud_former/functions/and.rb +26 -0
- data/lib/cloud_former/{conditions → functions}/equals.rb +3 -4
- data/lib/cloud_former/functions/find_in_map.rb +2 -2
- data/lib/cloud_former/functions/if.rb +28 -0
- data/lib/cloud_former/functions/not.rb +14 -0
- data/lib/cloud_former/functions/or.rb +26 -0
- data/lib/cloud_former/version.rb +1 -1
- data/spec/conditions_spec.rb +95 -26
- metadata +6 -6
- data/lib/cloud_former/conditions/and.rb +0 -6
- data/lib/cloud_former/conditions/if.rb +0 -6
- data/lib/cloud_former/conditions/not.rb +0 -6
- data/lib/cloud_former/conditions/or.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 228a945844501639913bc971d61276654210c011
|
4
|
+
data.tar.gz: 5670f5b5440d5920e0ce636f4343a0165b0f3836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0b2d65941582dd6531efec310865eeb5294b0e657a56b833ecd3f8b069fdc7bda5bb6a5bfe3140f413ce67db9e4b3f584a0b66f661aba34e899bc82a6bcfca0
|
7
|
+
data.tar.gz: e7fce25974730950842addbfd79ca0f3fad68af2cb5dc5f0550b02612c1ada22809f7317540d79155b21659b21d4c8687043bafdadf41c5a30d1c624026dc930
|
data/lib/cloud_former.rb
CHANGED
@@ -83,14 +83,7 @@ module CloudFormer
|
|
83
83
|
autoload :MetricDimension, 'cloud_former/resource_properties/cloud_watch/metric_dimension'
|
84
84
|
end
|
85
85
|
|
86
|
-
|
87
|
-
autoload :And, 'cloud_former/conditions/and'
|
88
|
-
autoload :Condition, 'cloud_former/conditions/condition'
|
89
|
-
autoload :Equals, 'cloud_former/conditions/equals'
|
90
|
-
autoload :If, 'cloud_former/conditions/if'
|
91
|
-
autoload :Not, 'cloud_former/conditions/not'
|
92
|
-
autoload :Or, 'cloud_former/conditions/or'
|
93
|
-
end
|
86
|
+
autoload :Condition, 'cloud_former/conditions/condition'
|
94
87
|
|
95
88
|
module DirectoryService
|
96
89
|
autoload :MicrosoftAD, 'cloud_former/resources/directory_service/microsoft_ad'
|
@@ -169,11 +162,16 @@ module CloudFormer
|
|
169
162
|
end
|
170
163
|
|
171
164
|
module Functions
|
165
|
+
autoload :And, 'cloud_former/functions/and'
|
172
166
|
autoload :Base64, 'cloud_former/functions/base_64'
|
167
|
+
autoload :Equals, 'cloud_former/functions/equals'
|
168
|
+
autoload :FindInMap, 'cloud_former/functions/find_in_map'
|
173
169
|
autoload :GetAtt, 'cloud_former/functions/get_att'
|
174
170
|
autoload :GetAZs, 'cloud_former/functions/get_azs'
|
175
|
-
autoload :
|
171
|
+
autoload :If, 'cloud_former/functions/if'
|
176
172
|
autoload :Join, 'cloud_former/functions/join'
|
173
|
+
autoload :Not, 'cloud_former/functions/not'
|
174
|
+
autoload :Or, 'cloud_former/functions/or'
|
177
175
|
end
|
178
176
|
|
179
177
|
module IAM
|
@@ -1,13 +1,18 @@
|
|
1
1
|
module CloudFormer
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(name)
|
5
|
-
@name = name
|
6
|
-
end
|
2
|
+
class Condition
|
3
|
+
attr_reader :function
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
def initialize(name, function)
|
6
|
+
@name = name
|
7
|
+
@function = function
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_name
|
11
|
+
@name
|
12
|
+
end
|
13
|
+
|
14
|
+
def dump_json
|
15
|
+
function.dump_json
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CloudFormer
|
2
|
+
module Functions
|
3
|
+
class And < Function
|
4
|
+
|
5
|
+
def initialize(*conditions)
|
6
|
+
@conditions = conditions
|
7
|
+
end
|
8
|
+
|
9
|
+
def dump_json
|
10
|
+
mapped = @conditions.map do |cond|
|
11
|
+
if cond.is_a?(Condition)
|
12
|
+
{ 'Condition' => cond.get_name }
|
13
|
+
elsif cond.is_a?(Function)
|
14
|
+
cond.dump_json
|
15
|
+
elsif cond.respond_to?(:get_name)
|
16
|
+
{ 'Ref' => cond.get_name }
|
17
|
+
elsif cond.respond_to?(:to_s)
|
18
|
+
cond.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
{ 'Fn::And' => mapped }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CloudFormer
|
2
|
+
module Functions
|
3
|
+
class If < Function
|
4
|
+
|
5
|
+
def initialize(condition, true_value, false_value)
|
6
|
+
@condition = condition
|
7
|
+
@true_value = true_value
|
8
|
+
@false_value = false_value
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump_json
|
12
|
+
if @true_value.respond_to?(:get_name)
|
13
|
+
tv = { 'Ref' => @value1.get_name }
|
14
|
+
elsif @true_value.respond_to?(:to_s)
|
15
|
+
tv = @true_value.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
if @false_value.respond_to?(:get_name)
|
19
|
+
fv = { 'Ref' => @false_value.get_name }
|
20
|
+
elsif @false_value.respond_to?(:to_s)
|
21
|
+
fv = @false_value.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
{ 'Fn::If' => [@condition.get_name, tv, fv] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CloudFormer
|
2
|
+
module Functions
|
3
|
+
class Not < Function
|
4
|
+
|
5
|
+
def initialize(*conditions)
|
6
|
+
@conditions = conditions
|
7
|
+
end
|
8
|
+
|
9
|
+
def dump_json
|
10
|
+
mapped = @conditions.map do |cond|
|
11
|
+
if cond.is_a?(Condition)
|
12
|
+
{ 'Condition' => cond.get_name }
|
13
|
+
elsif cond.is_a?(Function)
|
14
|
+
cond.dump_json
|
15
|
+
elsif cond.respond_to?(:get_name)
|
16
|
+
{ 'Ref' => cond.get_name }
|
17
|
+
elsif cond.respond_to?(:to_s)
|
18
|
+
cond.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
{ 'Fn::Or' => mapped }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/cloud_former/version.rb
CHANGED
data/spec/conditions_spec.rb
CHANGED
@@ -9,38 +9,107 @@ describe CloudFormer::Template do
|
|
9
9
|
user_name 'Aubrey'
|
10
10
|
end
|
11
11
|
end
|
12
|
+
let(:simple_equals_func) do
|
13
|
+
CloudFormer::Functions::Equals.new(1, 2)
|
14
|
+
end
|
15
|
+
let(:param_equals_func) do
|
16
|
+
CloudFormer::Functions::Equals.new(parameter1, 2)
|
17
|
+
end
|
12
18
|
let(:simple_equals) do
|
13
|
-
CloudFormer::
|
19
|
+
CloudFormer::Condition.new('TestEquals', simple_equals_func)
|
14
20
|
end
|
15
21
|
let(:param_equals) do
|
16
|
-
CloudFormer::
|
22
|
+
CloudFormer::Condition.new('TestEquals', param_equals_func)
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
"
|
25
|
+
describe 'equals' do
|
26
|
+
it 'should include parameters' do
|
27
|
+
template.add_condition(simple_equals)
|
28
|
+
expect(template.dump_json).to eq(
|
29
|
+
'AWSTemplateFormatVersion' => '2010-09-09',
|
30
|
+
"Conditions" => {
|
31
|
+
"TestEquals" => {
|
32
|
+
"Fn::Equals" => ["1", "2"],
|
33
|
+
},
|
26
34
|
},
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should include slightly mode complex parameters' do
|
39
|
+
template.add_parameter(parameter1)
|
40
|
+
template.add_condition(param_equals)
|
41
|
+
expect(template.dump_json).to eq(
|
42
|
+
'AWSTemplateFormatVersion' => '2010-09-09',
|
43
|
+
"Parameters" => {
|
44
|
+
"sweet" => { "Type" => "String" },
|
45
|
+
},
|
46
|
+
"Conditions" => {
|
47
|
+
"TestEquals" => {
|
48
|
+
"Fn::Equals" => [{ "Ref" => "sweet" }, "2"],
|
49
|
+
},
|
50
|
+
},
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'if' do
|
56
|
+
let(:simple_if_func) do
|
57
|
+
CloudFormer::Functions::If.new(simple_equals, 1, 2)
|
58
|
+
end
|
59
|
+
let(:simple_if) do
|
60
|
+
CloudFormer::Condition.new('TestIf', simple_if_func)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should work with simple values' do
|
64
|
+
template.add_condition(simple_equals)
|
65
|
+
template.add_condition(simple_if)
|
66
|
+
expect(template.dump_json).to eq(
|
67
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
68
|
+
"Conditions" => {
|
69
|
+
"TestEquals" => { "Fn::Equals" => ["1", "2"] },
|
70
|
+
"TestIf" => { "Fn::If" => ["TestEquals", "1", "2"] },
|
42
71
|
},
|
43
|
-
|
44
|
-
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'and' do
|
77
|
+
let(:simple_and_func) do
|
78
|
+
CloudFormer::Functions::And.new(simple_equals_func, param_equals)
|
79
|
+
end
|
80
|
+
let(:simple_and) do
|
81
|
+
CloudFormer::Condition.new('TestAnd', simple_and_func)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should work' do
|
85
|
+
template.add_condition(param_equals)
|
86
|
+
template.add_condition(simple_and)
|
87
|
+
expect(template.dump_json).to eq(
|
88
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
89
|
+
"Conditions" => {
|
90
|
+
"TestEquals" => { "Fn::Equals" => [{ "Ref" => "sweet" }, "2"] },
|
91
|
+
"TestAnd" => { "Fn::And" => [{ "Fn::Equals" => ["1", "2"] }, { "Condition" => "TestEquals" }] },
|
92
|
+
},
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'not' do
|
98
|
+
let(:simple_not_func) do
|
99
|
+
CloudFormer::Functions::Not.new(simple_equals_func)
|
100
|
+
end
|
101
|
+
let(:simple_not) do
|
102
|
+
CloudFormer::Condition.new('TestNot', simple_not_func)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should work' do
|
106
|
+
template.add_condition(simple_not)
|
107
|
+
expect(template.dump_json).to eq(
|
108
|
+
"AWSTemplateFormatVersion" => "2010-09-09",
|
109
|
+
"Conditions" => {
|
110
|
+
"TestNot" => { "Fn::Not" => [{ "Fn::Equals" => ["1", "2"] }] },
|
111
|
+
},
|
112
|
+
)
|
113
|
+
end
|
45
114
|
end
|
46
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_former
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
@@ -99,18 +99,18 @@ files:
|
|
99
99
|
- cloud_former.gemspec
|
100
100
|
- lib/cloud_former.rb
|
101
101
|
- lib/cloud_former/boolean.rb
|
102
|
-
- lib/cloud_former/conditions/and.rb
|
103
102
|
- lib/cloud_former/conditions/condition.rb
|
104
|
-
- lib/cloud_former/
|
105
|
-
- lib/cloud_former/conditions/if.rb
|
106
|
-
- lib/cloud_former/conditions/not.rb
|
107
|
-
- lib/cloud_former/conditions/or.rb
|
103
|
+
- lib/cloud_former/functions/and.rb
|
108
104
|
- lib/cloud_former/functions/base_64.rb
|
105
|
+
- lib/cloud_former/functions/equals.rb
|
109
106
|
- lib/cloud_former/functions/find_in_map.rb
|
110
107
|
- lib/cloud_former/functions/function.rb
|
111
108
|
- lib/cloud_former/functions/get_att.rb
|
112
109
|
- lib/cloud_former/functions/get_azs.rb
|
110
|
+
- lib/cloud_former/functions/if.rb
|
113
111
|
- lib/cloud_former/functions/join.rb
|
112
|
+
- lib/cloud_former/functions/not.rb
|
113
|
+
- lib/cloud_former/functions/or.rb
|
114
114
|
- lib/cloud_former/has_properties_and_attributes.rb
|
115
115
|
- lib/cloud_former/makes_json.rb
|
116
116
|
- lib/cloud_former/metadata_resources/cloud_formation/authentication.rb
|