cfndsl 0.11.4 → 0.11.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/cfndsl/jsonable.rb +13 -1
- data/lib/cfndsl/version.rb +1 -1
- data/sample/autoscale.rb +1 -3
- data/sample/autoscale2.rb +1 -3
- data/spec/cfndsl_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODkxMWE3OWJjMmM4NjNhYzYxMzE3MmYyMTU3ZDQ4NDMwY2YzNTE1Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGVlYzBmODllYzZjYjZlYzFiZGNmYjZhYzI3Mzk5Y2E3OGVhMDdjZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mjc4MjJlZjBmZDk4NjliODdhMDcyYTAxM2NmNjRhMjU5NjNhZmZlNTczM2Q0
|
10
|
+
MDlhZDY5NDdhZjVkNGQzMTdlNWRjZmI2NDM5NmYzMjY5N2IzNmJjMWMzZjlm
|
11
|
+
NzQ5YzgyYTU1YzkwM2M2YWNiNGNmMzc4NTM1NmMwN2ExNjcyYjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTc3MDY5ZTBkMWJjYmUzZjA3M2MzMzEzNzkyYzMxMmQ1ZWE2MWZlNmI0M2Zk
|
14
|
+
NzQ5YTE2NGI5N2I4NWIzMjc1MGVlOGE3MmY1MzJhY2JjNDNhMjUyMWJhMzZh
|
15
|
+
ZTIwMWE0MzE4M2FmMGNhZmNmZDdmZTE2ZmRhZDc3OThjYzA1ZTA=
|
data/lib/cfndsl/jsonable.rb
CHANGED
@@ -76,11 +76,23 @@ module CfnDsl
|
|
76
76
|
Fn.new('Select', [index, array])
|
77
77
|
end
|
78
78
|
|
79
|
+
# Equivalent to the CloudFormation template built in function Fn::Sub
|
80
|
+
def FnSub(string, substitutions = nil)
|
81
|
+
raise ArgumentError, 'The first argument passed to Fn::Sub must be a string' unless string.is_a? String
|
82
|
+
if substitutions
|
83
|
+
raise ArgumentError, 'The second argument passed to Fn::Sub must be a Hash' unless substitutions.is_a? Hash
|
84
|
+
Fn.new('Sub', [string, substitutions])
|
85
|
+
else
|
86
|
+
Fn.new('Sub', string)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
79
90
|
# Equivalent to the CloudFormation template built in function Fn::ImportValue
|
80
91
|
def FnImportValue(value)
|
81
92
|
Fn.new('ImportValue', value)
|
82
93
|
end
|
83
94
|
|
95
|
+
# DEPRECATED
|
84
96
|
# Usage
|
85
97
|
# FnFormat('This is a %0. It is 100%% %1', 'test', 'effective')
|
86
98
|
# or
|
@@ -103,9 +115,9 @@ module CfnDsl
|
|
103
115
|
# variable name does not exist in the hash, it is used as a Ref
|
104
116
|
# to an existing resource or parameter.
|
105
117
|
#
|
106
|
-
# TODO Can we simplyfy this somehow?
|
107
118
|
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
108
119
|
def FnFormat(string, *arguments)
|
120
|
+
warn '`FnFormat` is deprecated and will be removed a future release. Use `FnSub` instead'
|
109
121
|
array = []
|
110
122
|
|
111
123
|
if arguments.empty? || (arguments.length == 1 && arguments[0].instance_of?(Hash))
|
data/lib/cfndsl/version.rb
CHANGED
data/sample/autoscale.rb
CHANGED
@@ -201,9 +201,7 @@ a stack from this template.
|
|
201
201
|
}
|
202
202
|
])
|
203
203
|
Property('HealthCheck',
|
204
|
-
|
205
|
-
# Note that it renders to a call to Fn::Join in the json.
|
206
|
-
'Target' => FnFormat('HTTP:%0/', Ref('WebServerPort')),
|
204
|
+
'Target' => FnSub('HTTP:${WebServerPort}/'),
|
207
205
|
'HealthyThreshold' => '3',
|
208
206
|
'UnhealthyThreshold' => '5',
|
209
207
|
'Interval' => '30',
|
data/sample/autoscale2.rb
CHANGED
@@ -189,9 +189,7 @@ a stack from this template.
|
|
189
189
|
}
|
190
190
|
])
|
191
191
|
Property('HealthCheck',
|
192
|
-
|
193
|
-
# Note that it renders to a call to Fn::Join in the json.
|
194
|
-
'Target' => FnFormat('HTTP:%0/', Ref('WebServerPort')),
|
192
|
+
'Target' => FnSub('HTTP:${WebServerPort}/'),
|
195
193
|
'HealthyThreshold' => '3',
|
196
194
|
'UnhealthyThreshold' => '5',
|
197
195
|
'Interval' => '30',
|
data/spec/cfndsl_spec.rb
CHANGED
@@ -175,6 +175,28 @@ describe CfnDsl::CloudFormationTemplate do
|
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
|
+
context 'FnSub', 'String' do
|
179
|
+
it 'formats correctly' do
|
180
|
+
func = subject.FnSub('http://aws.${AWS::Region}.com')
|
181
|
+
expect(func.to_json).to eq('{"Fn::Sub":"http://aws.${AWS::Region}.com"}')
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'raises an error if not given a string' do
|
185
|
+
expect { subject.FnSub(1234) }.to raise_error(ArgumentError)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'FnSub', 'Hash' do
|
190
|
+
it 'formats correctly' do
|
191
|
+
func = subject.FnSub('http://aws.${domain}.com', domain: 'foo')
|
192
|
+
expect(func.to_json).to eq('{"Fn::Sub":["http://aws.${domain}.com",{"domain":"foo"}]}')
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'raises an error if not given a second argument that is not a Hash' do
|
196
|
+
expect { subject.FnSub('abc', 123) }.to raise_error(ArgumentError)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
178
200
|
context 'FnFormat', 'String' do
|
179
201
|
it 'formats correctly' do
|
180
202
|
func = subject.FnFormat('abc%0def%1ghi%%x', 'A', 'B')
|