cloud_former 0.5.11 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +47 -4
- data/cloud_former.gemspec +3 -2
- data/lib/cloud_former/conditions/and.rb +6 -0
- data/lib/cloud_former/conditions/condition.rb +13 -0
- data/lib/cloud_former/conditions/equals.rb +28 -0
- data/lib/cloud_former/conditions/if.rb +6 -0
- data/lib/cloud_former/conditions/not.rb +6 -0
- data/lib/cloud_former/conditions/or.rb +6 -0
- data/lib/cloud_former/template.rb +13 -0
- data/lib/cloud_former/version.rb +1 -1
- data/lib/cloud_former.rb +9 -0
- data/spec/conditions_spec.rb +46 -0
- data/spec/template_spec.rb +14 -17
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bbd10279a64112c993fb0b38f75eae4f643aba
|
4
|
+
data.tar.gz: 6a8030ea2638dde56cb4046c7bd4182c331b66fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a81e66c520ccc88f73d77720f58555af8e2b2bea09411622210cf5bfbb90456dc7ea1440b218909085eac5fac27e0904cc4001371d41a0c9b9994f05c143dfe
|
7
|
+
data.tar.gz: ce9b8e427965f7c3a81465019a6c9bd899f2dc2e0105136a9025fdb7267026772f8dbcf0315bb664787998eaa872f41dc083f3d66b1b1b21b1fb9e3c1a6e1a5e
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
|
4
|
+
Metrics/BlockNesting:
|
5
|
+
Enabled: false
|
6
|
+
|
1
7
|
Metrics/LineLength:
|
2
8
|
Max: 140
|
3
9
|
|
@@ -23,16 +29,41 @@ Metrics/CyclomaticComplexity:
|
|
23
29
|
Metrics/PerceivedComplexity:
|
24
30
|
Max: 600
|
25
31
|
|
32
|
+
# See: https://github.com/bbatsov/rubocop/issues/2614
|
33
|
+
Performance/Casecmp:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Performance/RedundantBlockCall:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Performance/TimesMap:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/Alias:
|
43
|
+
Enabled: false
|
44
|
+
|
26
45
|
Style/ClassAndModuleChildren:
|
27
46
|
Enabled: false
|
28
47
|
|
48
|
+
Style/ConditionalAssignment:
|
49
|
+
Enabled: false
|
50
|
+
|
29
51
|
Style/GuardClause:
|
30
52
|
Enabled: false
|
31
53
|
|
54
|
+
Style/IndentArray:
|
55
|
+
EnforcedStyle: consistent
|
56
|
+
|
57
|
+
Style/IndentArray:
|
58
|
+
EnforcedStyle: consistent
|
59
|
+
|
32
60
|
Style/IfUnlessModifier:
|
33
61
|
Enabled: false
|
34
62
|
|
35
|
-
Style/
|
63
|
+
Style/MutableConstant:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/NegatedIf:
|
36
67
|
Enabled: false
|
37
68
|
|
38
69
|
Style/PredicateName:
|
@@ -50,8 +81,8 @@ Style/StringLiterals:
|
|
50
81
|
Style/SpaceInsideBrackets:
|
51
82
|
Enabled: false
|
52
83
|
|
53
|
-
Style/
|
54
|
-
|
84
|
+
Style/UnneededInterpolation:
|
85
|
+
Enabled: false
|
55
86
|
|
56
87
|
Style/WordArray:
|
57
88
|
MinSize: 5
|
@@ -62,10 +93,22 @@ Style/EmptyLinesAroundClassBody:
|
|
62
93
|
Style/MultilineOperationIndentation:
|
63
94
|
EnforcedStyle: indented
|
64
95
|
|
96
|
+
Style/MultilineMethodCallIndentation:
|
97
|
+
EnforcedStyle: indented
|
98
|
+
|
99
|
+
Style/Next:
|
100
|
+
Enabled: false
|
101
|
+
|
65
102
|
Style/PerlBackrefs:
|
66
103
|
Enabled: false
|
67
104
|
|
68
|
-
Style/
|
105
|
+
Style/TrailingCommaInLiteral:
|
106
|
+
EnforcedStyleForMultiline: comma
|
107
|
+
|
108
|
+
Style/TrivialAccessors:
|
109
|
+
Enabled: false
|
110
|
+
|
111
|
+
Style/TrailingCommaInArguments:
|
69
112
|
EnforcedStyleForMultiline: comma
|
70
113
|
|
71
114
|
Lint/EndAlignment:
|
data/cloud_former.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = CloudFormer::VERSION
|
9
9
|
spec.authors = ["Aubrey Holland"]
|
10
10
|
spec.email = ["aubreyholland@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
11
|
+
spec.summary = 'A Ruby DSL for creating CloudFormation templates'
|
12
|
+
spec.description = 'This gem creates a Ruby DSL around the AWS CloudFormation JSON template structure.'
|
13
13
|
spec.homepage = 'http://github.com/custora/cloud_former'
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.5"
|
24
24
|
spec.add_development_dependency "rake", '~> 10.3'
|
25
25
|
spec.add_development_dependency "rspec", '~> 3.0'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
26
27
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CloudFormer
|
2
|
+
module Conditions
|
3
|
+
class Equals < Condition
|
4
|
+
|
5
|
+
def initialize(name, value1, value2)
|
6
|
+
super(name)
|
7
|
+
@value1 = value1
|
8
|
+
@value2 = value2
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump_json
|
12
|
+
if @value1.respond_to?(:get_name)
|
13
|
+
val1 = { 'Ref' => @value1.get_name }
|
14
|
+
elsif @value1.respond_to?(:to_s)
|
15
|
+
val1 = @value1.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
if @value2.respond_to?(:get_name)
|
19
|
+
val2 = { 'Ref' => @value2.get_name }
|
20
|
+
elsif @value2.respond_to?(:to_s)
|
21
|
+
val2 = @value2.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
{ 'Fn::Equals' => [val1, val2] }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -5,6 +5,7 @@ module CloudFormer
|
|
5
5
|
@resources = []
|
6
6
|
@parameters = []
|
7
7
|
@outputs = []
|
8
|
+
@conditions = []
|
8
9
|
end
|
9
10
|
|
10
11
|
def add_parameter(parameter)
|
@@ -19,6 +20,10 @@ module CloudFormer
|
|
19
20
|
@outputs << [key, value]
|
20
21
|
end
|
21
22
|
|
23
|
+
def add_condition(condition)
|
24
|
+
@conditions << condition
|
25
|
+
end
|
26
|
+
|
22
27
|
def dump_json
|
23
28
|
res = { 'AWSTemplateFormatVersion' => '2010-09-09' }
|
24
29
|
|
@@ -30,6 +35,14 @@ module CloudFormer
|
|
30
35
|
res['Parameters'] = parameter_res
|
31
36
|
end
|
32
37
|
|
38
|
+
if @conditions.any?
|
39
|
+
condition_res = {}
|
40
|
+
@conditions.each do |condition|
|
41
|
+
condition_res[condition.get_name] = condition.dump_json
|
42
|
+
end
|
43
|
+
res['Conditions'] = condition_res
|
44
|
+
end
|
45
|
+
|
33
46
|
if @resources.any?
|
34
47
|
resource_res = {}
|
35
48
|
@resources.each do |resource|
|
data/lib/cloud_former/version.rb
CHANGED
data/lib/cloud_former.rb
CHANGED
@@ -83,6 +83,15 @@ 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
|
94
|
+
|
86
95
|
module DirectoryService
|
87
96
|
autoload :MicrosoftAD, 'cloud_former/resources/directory_service/microsoft_ad'
|
88
97
|
autoload :SimpleAD, 'cloud_former/resources/directory_service/simple_ad'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CloudFormer::Template do
|
4
|
+
let(:template) { CloudFormer::Template.new }
|
5
|
+
let(:parameter1) { CloudFormer::StringParameter.new('sweet') }
|
6
|
+
let(:resource) do
|
7
|
+
CloudFormer::IAM::AccessKey.new('KEY') do
|
8
|
+
status 'Active'
|
9
|
+
user_name 'Aubrey'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
let(:simple_equals) do
|
13
|
+
CloudFormer::Conditions::Equals.new('TestEquals', 1, 2)
|
14
|
+
end
|
15
|
+
let(:param_equals) do
|
16
|
+
CloudFormer::Conditions::Equals.new('TestEquals', parameter, 2)
|
17
|
+
end
|
18
|
+
|
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"],
|
26
|
+
},
|
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"],
|
42
|
+
},
|
43
|
+
},
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
data/spec/template_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CloudFormer::Template do
|
4
|
-
|
5
4
|
let(:template) { CloudFormer::Template.new }
|
6
5
|
let(:parameter) { CloudFormer::StringParameter.new('sweet') }
|
7
6
|
let(:resource) do
|
@@ -16,38 +15,36 @@ describe CloudFormer::Template do
|
|
16
15
|
end
|
17
16
|
|
18
17
|
it 'should include the AWSTemplateFormatVersion by default' do
|
19
|
-
expect(template.dump_json).to eq(
|
20
|
-
'AWSTemplateFormatVersion' => '2010-09-09'
|
21
|
-
|
18
|
+
expect(template.dump_json).to eq(
|
19
|
+
'AWSTemplateFormatVersion' => '2010-09-09',
|
20
|
+
)
|
22
21
|
end
|
23
22
|
|
24
23
|
it 'should include parameters' do
|
25
24
|
template.add_parameter(parameter)
|
26
|
-
expect(template.dump_json).to eq(
|
25
|
+
expect(template.dump_json).to eq(
|
27
26
|
'AWSTemplateFormatVersion' => '2010-09-09',
|
28
27
|
'Parameters' => {
|
29
28
|
'sweet' => {
|
30
|
-
'Type' => 'String'
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
29
|
+
'Type' => 'String',
|
30
|
+
},
|
31
|
+
},
|
32
|
+
)
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'should include resources' do
|
37
36
|
template.add_resource(resource)
|
38
|
-
expect(template.dump_json).to eq(
|
37
|
+
expect(template.dump_json).to eq(
|
39
38
|
'AWSTemplateFormatVersion' => '2010-09-09',
|
40
39
|
'Resources' => {
|
41
40
|
resource.name => {
|
42
41
|
'Type' => resource.aws_type,
|
43
42
|
'Properties' => {
|
44
43
|
'Status' => 'Active',
|
45
|
-
'UserName' => 'Aubrey'
|
46
|
-
}
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
44
|
+
'UserName' => 'Aubrey',
|
45
|
+
},
|
46
|
+
},
|
47
|
+
},
|
48
|
+
)
|
50
49
|
end
|
51
|
-
|
52
|
-
|
53
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_former
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aubrey Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: This gem creates a Ruby DSL around the AWS CloudFormation JSON template
|
70
84
|
structure.
|
71
85
|
email:
|
@@ -85,6 +99,12 @@ files:
|
|
85
99
|
- cloud_former.gemspec
|
86
100
|
- lib/cloud_former.rb
|
87
101
|
- lib/cloud_former/boolean.rb
|
102
|
+
- lib/cloud_former/conditions/and.rb
|
103
|
+
- 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
|
88
108
|
- lib/cloud_former/functions/base_64.rb
|
89
109
|
- lib/cloud_former/functions/find_in_map.rb
|
90
110
|
- lib/cloud_former/functions/function.rb
|
@@ -268,6 +288,7 @@ files:
|
|
268
288
|
- lib/cloud_former/resources/sqs/queue_policy.rb
|
269
289
|
- lib/cloud_former/template.rb
|
270
290
|
- lib/cloud_former/version.rb
|
291
|
+
- spec/conditions_spec.rb
|
271
292
|
- spec/has_properties_and_attributes_spec.rb
|
272
293
|
- spec/metadata_spec.rb
|
273
294
|
- spec/output_spec.rb
|
@@ -303,11 +324,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
324
|
version: '0'
|
304
325
|
requirements: []
|
305
326
|
rubyforge_project:
|
306
|
-
rubygems_version: 2.
|
327
|
+
rubygems_version: 2.5.1
|
307
328
|
signing_key:
|
308
329
|
specification_version: 4
|
309
330
|
summary: A Ruby DSL for creating CloudFormation templates
|
310
331
|
test_files:
|
332
|
+
- spec/conditions_spec.rb
|
311
333
|
- spec/has_properties_and_attributes_spec.rb
|
312
334
|
- spec/metadata_spec.rb
|
313
335
|
- spec/output_spec.rb
|