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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2UzMWFmNmYxM2E2MTQ4M2U1NmM2MDk3NGFkNzUwMzI5ZjJmZmI4ZQ==
4
+ ODkxMWE3OWJjMmM4NjNhYzYxMzE3MmYyMTU3ZDQ4NDMwY2YzNTE1Yg==
5
5
  data.tar.gz: !binary |-
6
- YmYyNzZlM2RkNzRmNzE2YmYwOGI2OWVlMTM4MGZhYzE2Yjk4ODFlYw==
6
+ OGVlYzBmODllYzZjYjZlYzFiZGNmYjZhYzI3Mzk5Y2E3OGVhMDdjZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzY3ZjVjZDU4NGQ3ZTNlMTdmNmM1N2RkYmMzZjIwZmYxZGRkZjM3NTIwNGEx
10
- OGFkMTJmZTViZWQ5MTEzNGU3MjAxYzQyYjNmZDVlN2JkNmVhMGM2YTBjOTEy
11
- MTI0M2U1MDRhZDVjMjc3ZDVkN2FmMGFmZTA1ZjhiMWJjNGNkMDE=
9
+ Mjc4MjJlZjBmZDk4NjliODdhMDcyYTAxM2NmNjRhMjU5NjNhZmZlNTczM2Q0
10
+ MDlhZDY5NDdhZjVkNGQzMTdlNWRjZmI2NDM5NmYzMjY5N2IzNmJjMWMzZjlm
11
+ NzQ5YzgyYTU1YzkwM2M2YWNiNGNmMzc4NTM1NmMwN2ExNjcyYjE=
12
12
  data.tar.gz: !binary |-
13
- YTVhZTA1NTIxODg2ZmM5NjJlNzZhZWViNTg2NjAwZWJmMDFlNzlhOTYzMzM1
14
- NGU0NzdlNDBlMDMwZDllODRmMDlmOTZiZTU0MmZiZTdkZjhkY2ZkMjk0MjFm
15
- ZjBhNzFjY2RjYTQwN2FmOTYyNmU0ZDFjMmUxMThhMzFjZjdlOWU=
13
+ OTc3MDY5ZTBkMWJjYmUzZjA3M2MzMzEzNzkyYzMxMmQ1ZWE2MWZlNmI0M2Zk
14
+ NzQ5YTE2NGI5N2I4NWIzMjc1MGVlOGE3MmY1MzJhY2JjNDNhMjUyMWJhMzZh
15
+ ZTIwMWE0MzE4M2FmMGNhZmNmZDdmZTE2ZmRhZDc3OThjYzA1ZTA=
@@ -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))
@@ -1,3 +1,3 @@
1
1
  module CfnDsl
2
- VERSION = '0.11.4'.freeze
2
+ VERSION = '0.11.5'.freeze
3
3
  end
data/sample/autoscale.rb CHANGED
@@ -201,9 +201,7 @@ a stack from this template.
201
201
  }
202
202
  ])
203
203
  Property('HealthCheck',
204
- # FnFormat replaces %0, %1, etc with passed in parameters
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
- # FnFormat replaces %0, %1, etc with passed in parameters
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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfndsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.11.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack