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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 455e08fb6d89772ae26e8aafe48860c97e478bd1
4
- data.tar.gz: 24e931c5c1c05ed6806a4c0a669dfa240229010d
3
+ metadata.gz: 228a945844501639913bc971d61276654210c011
4
+ data.tar.gz: 5670f5b5440d5920e0ce636f4343a0165b0f3836
5
5
  SHA512:
6
- metadata.gz: 034974211ab749ba87fab1230d1f39703434064134903ba5f0c728697dd7329f1eb6b70a3e1abf18d171955cbe7cedb1fc10ed16af25ac67e7967114620f7881
7
- data.tar.gz: c90be0ed15425253c2ecb05e182da9cc283a855942a224bf7a95c9316e38b607830a3d5957369fabe8d1c2ece2e847f6c38710c46521dd63ae957b6a1a22c27b
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
- module Conditions
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 :FindInMap, 'cloud_former/functions/find_in_map'
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
- module Conditions
3
- class Condition
4
- def initialize(name)
5
- @name = name
6
- end
2
+ class Condition
3
+ attr_reader :function
7
4
 
8
- def get_name
9
- @name
10
- end
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
@@ -1,9 +1,8 @@
1
1
  module CloudFormer
2
- module Conditions
3
- class Equals < Condition
2
+ module Functions
3
+ class Equals < Function
4
4
 
5
- def initialize(name, value1, value2)
6
- super(name)
5
+ def initialize(value1, value2)
7
6
  @value1 = value1
8
7
  @value2 = value2
9
8
  end
@@ -13,8 +13,8 @@ module CloudFormer
13
13
  'Fn::FindInMap' => [
14
14
  @map_name,
15
15
  transform_key(@top_level_key),
16
- transform_key(@second_level_key)
17
- ]
16
+ transform_key(@second_level_key),
17
+ ],
18
18
  }
19
19
  end
20
20
 
@@ -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,14 @@
1
+ module CloudFormer
2
+ module Functions
3
+ class Not < Function
4
+
5
+ def initialize(function)
6
+ @function = function
7
+ end
8
+
9
+ def dump_json
10
+ { 'Fn::Not' => [@function.dump_json] }
11
+ end
12
+ end
13
+ end
14
+ 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
@@ -1,3 +1,3 @@
1
1
  module CloudFormer
2
- VERSION = '0.5.13'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -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::Conditions::Equals.new('TestEquals', 1, 2)
19
+ CloudFormer::Condition.new('TestEquals', simple_equals_func)
14
20
  end
15
21
  let(:param_equals) do
16
- CloudFormer::Conditions::Equals.new('TestEquals', parameter, 2)
22
+ CloudFormer::Condition.new('TestEquals', param_equals_func)
17
23
  end
18
24
 
19
- it 'should include parameters' do
20
- template.add_condition(simple_equals)
21
- expect(template.dump_json).to eq(
22
- 'AWSTemplateFormatVersion' => '2010-09-09',
23
- "Conditions" => {
24
- "TestEquals" => {
25
- "Fn::Equals" => ["1", "2"],
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
- end
30
-
31
- it 'should include slightly mode complex parameters' do
32
- template.add_parameter(parameter)
33
- template.add_condition(param_equals)
34
- expect(template.dump_json).to eq(
35
- 'AWSTemplateFormatVersion' => '2010-09-09',
36
- "Parameters" => {
37
- "sweet" => { "Type" => "String" },
38
- },
39
- "Conditions" => {
40
- "TestEquals" => {
41
- "Fn::Equals" => [{ "Ref" => "sweet" }, "2"],
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.5.13
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/conditions/equals.rb
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
@@ -1,6 +0,0 @@
1
- module CloudFormer
2
- module Conditions
3
- class And < Condition
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module CloudFormer
2
- module Conditions
3
- class If < Condition
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module CloudFormer
2
- module Conditions
3
- class Not < Condition
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module CloudFormer
2
- module Conditions
3
- class Or < Condition
4
- end
5
- end
6
- end