cfndsl 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.md +36 -35
- data/bin/cfndsl +14 -0
- data/lib/cfndsl.rb +29 -18
- data/lib/cfndsl/external_parameters.rb +47 -0
- data/lib/cfndsl/orchestration_template.rb +9 -0
- data/lib/cfndsl/version.rb +1 -1
- data/sample/t1.rb +5 -5
- data/sample/t1.yaml +2 -2
- data/spec/cli_spec.rb +37 -11
- data/spec/external_parameters_spec.rb +79 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjRiMGI3NjU1M2NjYzQyOGZlZmUzOTQ2MDIyNTc5MGIyYzRkNjIwZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDYzZDU1YTc1MmNmYTE0NGI3NDQwNDU0MThkYmQxNzJkNjY0ZTViMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODRmOWU4NGVjNzE3MjQ2ZDBkNDk1MWUyYmFlNWRmZjQ5MzE5MDJiNzA4ODA2
|
10
|
+
MTI0ZTdkNjBjNjIyNDhmOGUxNjQ4ODYzNzAwOTk5YzAyMTAyYmM4ZDQ4YmNi
|
11
|
+
ZWIyODRlOTBiMjQwMmJkZWQzNDI4YzIwNmQ2NWRkNGRhZWZmYmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NWVjMzQ5YWE0ZDhhOGU5NzE5YTAwYTlhY2E3NDg0OTM4NDMwODVlZThlNDE0
|
14
|
+
ZTE1MmE0MWRhMzFiOGM3YmYyMmNiNzcwOGNiZDZhZjc0Njk4MTkzYzUzY2Y2
|
15
|
+
NGYxYTY2ZDBkNjdhNTg0YmRmYTg0ZGJiYTY2MGRmZGNkOTk3ZDM=
|
data/README.md
CHANGED
@@ -55,27 +55,27 @@ chris@raspberrypi:~/git/cfndsl$ cfndsl test.rb | json_pp
|
|
55
55
|
{
|
56
56
|
"Parameters" : {
|
57
57
|
"One" : {
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
"Type" : "String",
|
59
|
+
"Default" : "Test",
|
60
|
+
"MaxLength" : 15
|
61
61
|
}
|
62
62
|
},
|
63
63
|
"Resources" : {
|
64
64
|
"MyInstance" : {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
"Type" : "AWS::EC2::Instance",
|
66
|
+
"Properties" : {
|
67
|
+
"ImageId" : "ami-12345678"
|
68
|
+
}
|
69
69
|
}
|
70
70
|
},
|
71
71
|
"AWSTemplateFormatVersion" : "2010-09-09",
|
72
72
|
"Outputs" : {
|
73
73
|
"One" : {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
"Value" : {
|
75
|
+
"Fn::Base64" : {
|
76
|
+
"Ref" : "One"
|
77
|
+
}
|
78
|
+
}
|
79
79
|
}
|
80
80
|
},
|
81
81
|
"Description" : "Test"
|
@@ -106,6 +106,7 @@ Usage: cfndsl [options] FILE
|
|
106
106
|
-p, --pretty Pretty-format output JSON
|
107
107
|
-D, --define "VARIABLE=VALUE" Directly set local VARIABLE as VALUE
|
108
108
|
-v, --verbose Turn on verbose ouptut
|
109
|
+
-b, --disable-binding Disable binding configuration
|
109
110
|
-h, --help Display this screen
|
110
111
|
```
|
111
112
|
|
@@ -124,26 +125,26 @@ This is best illustrated with a example. Consider the following cfndsl
|
|
124
125
|
template
|
125
126
|
|
126
127
|
```ruby
|
127
|
-
# cfndsl template t1.rb
|
128
|
-
CloudFormation
|
128
|
+
# cfndsl template sample/t1.rb
|
129
|
+
CloudFormation do
|
129
130
|
|
130
|
-
|
131
|
-
|
131
|
+
description = external_parameters.fetch(:description, 'default description')
|
132
|
+
machines = external_parameters.fetch(:machines, 1).to_i
|
132
133
|
|
133
|
-
Description
|
134
|
+
Description description
|
134
135
|
|
135
|
-
(1..
|
136
|
+
(1..machines).each do |i|
|
136
137
|
name = "machine#{i}"
|
137
|
-
EC2_Instance(name)
|
138
|
-
ImageId
|
139
|
-
Type
|
140
|
-
|
138
|
+
EC2_Instance(name) do
|
139
|
+
ImageId 'ami-12345678'
|
140
|
+
Type 't1.micro'
|
141
|
+
end
|
141
142
|
end
|
142
143
|
|
143
|
-
|
144
|
+
end
|
144
145
|
```
|
145
146
|
|
146
|
-
Note the two variables
|
147
|
+
Note the two variables `description` and `machines`. The template
|
147
148
|
sets these to some reasonable default values, and if you run cfndsl
|
148
149
|
on it without changing them in any way you get the following cloudformation
|
149
150
|
template:
|
@@ -154,7 +155,7 @@ template:
|
|
154
155
|
"machine1": {
|
155
156
|
"Type": "AWS::EC2::Instance",
|
156
157
|
"Properties": {
|
157
|
-
|
158
|
+
"ImageId": "ami-12345678"
|
158
159
|
}
|
159
160
|
}
|
160
161
|
},
|
@@ -166,7 +167,7 @@ template:
|
|
166
167
|
However if you run the command
|
167
168
|
|
168
169
|
```bash
|
169
|
-
$ cfndsl t1.rb -D '
|
170
|
+
$ cfndsl sample/t1.rb -D 'description=3 machine cluster' -D 'machines=3'
|
170
171
|
```
|
171
172
|
|
172
173
|
you get the following generated template.
|
@@ -177,19 +178,19 @@ you get the following generated template.
|
|
177
178
|
"machine3": {
|
178
179
|
"Type": "AWS::EC2::Instance",
|
179
180
|
"Properties": {
|
180
|
-
|
181
|
+
"ImageId": "ami-12345678"
|
181
182
|
}
|
182
183
|
},
|
183
184
|
"machine2": {
|
184
185
|
"Type": "AWS::EC2::Instance",
|
185
186
|
"Properties": {
|
186
|
-
|
187
|
+
"ImageId": "ami-12345678"
|
187
188
|
}
|
188
189
|
},
|
189
190
|
"machine1": {
|
190
191
|
"Type": "AWS::EC2::Instance",
|
191
192
|
"Properties": {
|
192
|
-
|
193
|
+
"ImageId": "ami-12345678"
|
193
194
|
}
|
194
195
|
}
|
195
196
|
},
|
@@ -199,26 +200,26 @@ you get the following generated template.
|
|
199
200
|
```
|
200
201
|
|
201
202
|
The -y and -j options allow you to group several variable definitions
|
202
|
-
into a single file (formated as either yaml or
|
203
|
+
into a single file (formated as either yaml or json respectively). If
|
203
204
|
you had a file called 't1.yaml' that contained the following,
|
204
205
|
|
205
206
|
```yaml
|
206
|
-
# t1.yaml
|
207
|
-
|
208
|
-
|
207
|
+
# sample/t1.yaml
|
208
|
+
description: 5 machine cluster
|
209
|
+
machines: 5
|
209
210
|
```
|
210
211
|
|
211
212
|
the command
|
212
213
|
|
213
214
|
```bash
|
214
|
-
$ cfndsl t1.rb -y t1.yaml
|
215
|
+
$ cfndsl sample/t1.rb -y sample/t1.yaml
|
215
216
|
```
|
216
217
|
|
217
218
|
would generate a template with 5 instances declared.
|
218
219
|
|
219
220
|
Finally, the -r option gives you the opportunity to execute some
|
220
221
|
arbitrary ruby code in the evaluation context before the cloudformation
|
221
|
-
template is evaluated.
|
222
|
+
template is evaluated (this is not available if `--disable-binding` is used).
|
222
223
|
|
223
224
|
### Rake task
|
224
225
|
Simply add the following to your `Rakefile`:
|
data/bin/cfndsl
CHANGED
@@ -41,6 +41,10 @@ optparse = OptionParser.new do |opts|
|
|
41
41
|
options[:verbose] = true
|
42
42
|
end
|
43
43
|
|
44
|
+
opts.on('-b', '--disable-binding', 'Disable binding configuration') do
|
45
|
+
options[:disable_binding] = true
|
46
|
+
end
|
47
|
+
|
44
48
|
# This displays the help screen, all programs are
|
45
49
|
# assumed to have this option.
|
46
50
|
opts.on('-h', '--help', 'Display this screen') do
|
@@ -57,6 +61,16 @@ end
|
|
57
61
|
|
58
62
|
filename = File.expand_path(ARGV[0])
|
59
63
|
verbose = options[:verbose] && STDERR
|
64
|
+
if options[:disable_binding]
|
65
|
+
CfnDsl.disable_binding
|
66
|
+
else
|
67
|
+
STDERR.puts <<-MSG
|
68
|
+
The creation of constants as config is deprecated!
|
69
|
+
Please switch to the #external_parameters method within your templates to access variables
|
70
|
+
See https://github.com/stevenjack/cfndsl/issues/170
|
71
|
+
Use the --disable-binding flag to suppress this message
|
72
|
+
MSG
|
73
|
+
end
|
60
74
|
|
61
75
|
model = CfnDsl.eval_file_with_extras(filename, options[:extras], verbose)
|
62
76
|
|
data/lib/cfndsl.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'forwardable'
|
1
2
|
require 'json'
|
2
3
|
|
3
4
|
require 'cfndsl/module'
|
@@ -15,9 +16,17 @@ require 'cfndsl/parameters'
|
|
15
16
|
require 'cfndsl/outputs'
|
16
17
|
require 'cfndsl/aws/cloud_formation_template'
|
17
18
|
require 'cfndsl/os/heat_template'
|
19
|
+
require 'cfndsl/external_parameters'
|
18
20
|
|
19
21
|
# CfnDsl
|
20
22
|
module CfnDsl
|
23
|
+
def self.disable_binding
|
24
|
+
@disable_binding = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.disable_binding?
|
28
|
+
@disable_binding
|
29
|
+
end
|
21
30
|
# This function handles the eval of the template file and returns the
|
22
31
|
# results. It does this with a ruby "eval", but it builds up a customized
|
23
32
|
# binding environment before it calls eval. The environment can be
|
@@ -42,41 +51,43 @@ module CfnDsl
|
|
42
51
|
# side effects) will persist into the context where the template
|
43
52
|
# is evaluated
|
44
53
|
#
|
45
|
-
# :raw - the
|
54
|
+
# :raw - the second element is treated as a ruby statement and is
|
46
55
|
# evaluated in the binding context, similar to the contents of
|
47
56
|
# a ruby file.
|
48
57
|
#
|
49
58
|
# Note that the order is important, as later extra sections can overwrite
|
50
59
|
# or even undo things that were done by earlier sections.
|
60
|
+
|
61
|
+
# rubocop:disable all
|
51
62
|
def self.eval_file_with_extras(filename, extras = [], logstream = nil)
|
52
63
|
b = binding
|
53
|
-
|
54
|
-
|
64
|
+
params = CfnDsl::ExternalParameters.new
|
65
|
+
extras.each do |type, file|
|
55
66
|
case type
|
56
67
|
when :yaml, :json
|
57
68
|
klass_name = type.to_s.upcase
|
58
|
-
klass = Object.const_get(klass_name)
|
59
69
|
logstream.puts("Loading #{klass_name} file #{file}") if logstream
|
60
|
-
|
61
|
-
|
62
|
-
logstream.puts("Setting local variable #{k} to #{v}") if logstream
|
63
|
-
b.eval("#{k} = #{v.inspect}")
|
64
|
-
end
|
65
|
-
|
70
|
+
params.load_file file
|
71
|
+
params.add_to_binding(b, logstream) unless disable_binding?
|
66
72
|
when :ruby
|
67
|
-
|
68
|
-
|
69
|
-
|
73
|
+
if disable_binding?
|
74
|
+
logstream.puts("Interpreting Ruby files was disabled. #{file} will not be read") if logstream
|
75
|
+
else
|
76
|
+
logstream.puts("Running ruby file #{file}") if logstream
|
77
|
+
b.eval(File.read(file), file)
|
78
|
+
end
|
70
79
|
when :raw
|
71
|
-
|
72
|
-
|
80
|
+
params.set_param(*file.split('='))
|
81
|
+
unless disable_binding?
|
82
|
+
logstream.puts("Running raw ruby code #{file}") if logstream
|
83
|
+
b.eval(file, 'raw code')
|
84
|
+
end
|
73
85
|
end
|
74
86
|
end
|
75
87
|
|
88
|
+
CfnDsl::CloudFormationTemplate.external_parameters params
|
76
89
|
logstream.puts("Loading template file #{filename}") if logstream
|
77
|
-
|
78
|
-
|
79
|
-
model
|
90
|
+
b.eval(File.read(filename), filename)
|
80
91
|
end
|
81
92
|
end
|
82
93
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CfnDsl
|
2
|
+
# Handles all external parameters
|
3
|
+
class ExternalParameters
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :parameters, :fetch, :keys, :values, :each_pair
|
7
|
+
|
8
|
+
attr_reader :parameters
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@parameters = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_param(k, v)
|
15
|
+
parameters[k.to_sym] = v
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_param(k)
|
19
|
+
parameters[k.to_sym]
|
20
|
+
end
|
21
|
+
alias [] get_param
|
22
|
+
|
23
|
+
def to_h
|
24
|
+
parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_to_binding(bind, logstream)
|
28
|
+
parameters.each_pair do |key, val|
|
29
|
+
logstream.puts("Setting local variable #{key} to #{val}") if logstream
|
30
|
+
bind.eval "#{key} = #{val.inspect}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_file(fname)
|
35
|
+
format = File.extname fname
|
36
|
+
case format
|
37
|
+
when /ya?ml/
|
38
|
+
params = YAML.load_file fname
|
39
|
+
when /json/
|
40
|
+
params = JSON.load File.read(fname)
|
41
|
+
else
|
42
|
+
raise "Unrecognized extension #{format}"
|
43
|
+
end
|
44
|
+
params.each { |key, val| set_param(key, val) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -10,6 +10,15 @@ module CfnDsl
|
|
10
10
|
dsl_attr_setter :AWSTemplateFormatVersion, :Description
|
11
11
|
dsl_content_object :Condition, :Parameter, :Output, :Resource, :Mapping
|
12
12
|
|
13
|
+
def self.external_parameters(params = nil)
|
14
|
+
@external_parameters = params if params
|
15
|
+
@external_parameters
|
16
|
+
end
|
17
|
+
|
18
|
+
def external_parameters
|
19
|
+
self.class.external_parameters
|
20
|
+
end
|
21
|
+
|
13
22
|
def initialize
|
14
23
|
@AWSTemplateFormatVersion = '2010-09-09'
|
15
24
|
end
|
data/lib/cfndsl/version.rb
CHANGED
data/sample/t1.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
CloudFormation do
|
2
|
-
|
3
|
-
|
2
|
+
description = external_parameters.fetch(:description, 'default description')
|
3
|
+
machines = external_parameters.fetch(:machines, 1).to_i
|
4
4
|
|
5
|
-
Description
|
5
|
+
Description description
|
6
6
|
|
7
|
-
(1..
|
7
|
+
(1..machines).each do |i|
|
8
8
|
name = "machine#{i}"
|
9
|
-
|
9
|
+
EC2_Instance(name) do
|
10
10
|
ImageId 'ami-12345678'
|
11
11
|
Type 't1.micro'
|
12
12
|
end
|
data/sample/t1.yaml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
description: 5 machine cluster
|
2
|
+
machines: 5
|
data/spec/cli_spec.rb
CHANGED
@@ -11,6 +11,7 @@ describe 'cfndsl', type: :aruba do
|
|
11
11
|
-p, --pretty Pretty-format output JSON
|
12
12
|
-D, --define "VARIABLE=VALUE" Directly set local VARIABLE as VALUE
|
13
13
|
-v, --verbose Turn on verbose ouptut
|
14
|
+
-b, --disable-binding Disable binding configuration
|
14
15
|
-h, --help Display this screen
|
15
16
|
USAGE
|
16
17
|
end
|
@@ -18,8 +19,7 @@ describe 'cfndsl', type: :aruba do
|
|
18
19
|
let(:template_content) do
|
19
20
|
<<-TEMPLATE.gsub(/^ {6}/, '')
|
20
21
|
CloudFormation do
|
21
|
-
DESC
|
22
|
-
Description DESC
|
22
|
+
Description(external_parameters[:DESC] || 'default')
|
23
23
|
end
|
24
24
|
TEMPLATE
|
25
25
|
end
|
@@ -42,16 +42,26 @@ describe 'cfndsl', type: :aruba do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'cfndsl FILE' do
|
45
|
+
it 'gives a deprecation warning about bindings' do
|
46
|
+
run_simple 'cfndsl template.rb'
|
47
|
+
expect(last_command_started).to have_output_on_stderr(<<-WARN.gsub(/^ {8}/, '').chomp)
|
48
|
+
The creation of constants as config is deprecated!
|
49
|
+
Please switch to the #external_parameters method within your templates to access variables
|
50
|
+
See https://github.com/stevenjack/cfndsl/issues/170
|
51
|
+
Use the --disable-binding flag to suppress this message
|
52
|
+
WARN
|
53
|
+
end
|
54
|
+
|
45
55
|
it 'generates a JSON CloudFormation template' do
|
46
56
|
run_simple 'cfndsl template.rb'
|
47
|
-
expect(last_command_started).to
|
57
|
+
expect(last_command_started).to have_output_on_stdout('{"AWSTemplateFormatVersion":"2010-09-09","Description":"default"}')
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
61
|
context 'cfndsl FILE --pretty' do
|
52
62
|
it 'generates a pretty JSON CloudFormation template' do
|
53
63
|
run_simple 'cfndsl template.rb --pretty'
|
54
|
-
expect(last_command_started).to
|
64
|
+
expect(last_command_started).to have_output_on_stdout(<<-OUTPUT.gsub(/^ {8}/, '').chomp)
|
55
65
|
{
|
56
66
|
"AWSTemplateFormatVersion": "2010-09-09",
|
57
67
|
"Description": "default"
|
@@ -72,7 +82,7 @@ describe 'cfndsl', type: :aruba do
|
|
72
82
|
|
73
83
|
it 'interpolates the YAML file in the CloudFormation template' do
|
74
84
|
run_simple 'cfndsl template.rb --yaml params.yaml'
|
75
|
-
expect(last_command_started).to
|
85
|
+
expect(last_command_started).to have_output_on_stdout('{"AWSTemplateFormatVersion":"2010-09-09","Description":"yaml"}')
|
76
86
|
end
|
77
87
|
end
|
78
88
|
|
@@ -81,23 +91,39 @@ describe 'cfndsl', type: :aruba do
|
|
81
91
|
|
82
92
|
it 'interpolates the JSON file in the CloudFormation template' do
|
83
93
|
run_simple 'cfndsl template.rb --json params.json'
|
84
|
-
expect(last_command_started).to
|
94
|
+
expect(last_command_started).to have_output_on_stdout('{"AWSTemplateFormatVersion":"2010-09-09","Description":"json"}')
|
85
95
|
end
|
86
96
|
end
|
87
97
|
|
88
98
|
context 'cfndsl FILE --ruby FILE' do
|
89
|
-
|
99
|
+
let(:template_content) do
|
100
|
+
<<-TEMPLATE.gsub(/^ {8}/, '')
|
101
|
+
CloudFormation do
|
102
|
+
DESC = 'default' unless defined? DESC
|
103
|
+
Description DESC
|
104
|
+
end
|
105
|
+
TEMPLATE
|
106
|
+
end
|
90
107
|
|
91
|
-
|
108
|
+
before(:each) { write_file('params.rb', 'DESC = "ruby"') }
|
109
|
+
|
110
|
+
it 'interpolates the Ruby file in the CloudFormation template' do
|
92
111
|
run_simple 'cfndsl template.rb --ruby params.rb'
|
93
|
-
expect(last_command_started).to
|
112
|
+
expect(last_command_started).to have_output_on_stdout('{"AWSTemplateFormatVersion":"2010-09-09","Description":"ruby"}')
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'gives a deprecation warning and does not interpolate if bindings are disabled' do
|
116
|
+
run_simple 'cfndsl template.rb --ruby params.rb --disable-binding --verbose'
|
117
|
+
deprecation_warning = /Interpreting Ruby files was disabled\. .*params.rb will not be read/
|
118
|
+
expect(last_command_started).to have_output_on_stderr(deprecation_warning)
|
119
|
+
expect(last_command_started).to have_output_on_stdout('{"AWSTemplateFormatVersion":"2010-09-09","Description":"default"}')
|
94
120
|
end
|
95
121
|
end
|
96
122
|
|
97
123
|
context 'cfndsl FILE --define VARIABLE=VALUE' do
|
98
124
|
it 'interpolates the command line variables in the CloudFormation template' do
|
99
|
-
|
100
|
-
expect(last_command_started).to
|
125
|
+
run "cfndsl template.rb --define \"DESC='cli'\""
|
126
|
+
expect(last_command_started).to have_output_on_stdout("{\"AWSTemplateFormatVersion\":\"2010-09-09\",\"Description\":\"'cli'\"}")
|
101
127
|
end
|
102
128
|
end
|
103
129
|
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CfnDsl::ExternalParameters do
|
4
|
+
subject do
|
5
|
+
exp = described_class.new
|
6
|
+
exp.set_param(:username, 'Wiz Khalifa')
|
7
|
+
exp.set_param(:password, 'BlackAndYellow')
|
8
|
+
exp
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#set_param' do
|
12
|
+
it 'treats keys as symbols only' do
|
13
|
+
subject.set_param('reminder', 'You Know What It Is')
|
14
|
+
expect(subject[:reminder]).to eq('You Know What It Is')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#get_param' do
|
19
|
+
it 'treats keys as symbols only' do
|
20
|
+
subject.set_param(:reminder, 'You Know What It Is')
|
21
|
+
expect(subject.get_param('reminder')).to eq('You Know What It Is')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context '#to_h' do
|
26
|
+
it 'returns the current parameters as a Hash' do
|
27
|
+
expect(subject.to_h).to eq(username: 'Wiz Khalifa', password: 'BlackAndYellow')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#add_to_binding' do
|
32
|
+
it 'defines the parameters as variables in the current binding' do
|
33
|
+
current = binding
|
34
|
+
subject.add_to_binding(current, nil)
|
35
|
+
expect(current).to be_local_variable_defined(:username)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'prints to a logstream if given' do
|
39
|
+
logstream = StringIO.new
|
40
|
+
subject.add_to_binding(binding, logstream)
|
41
|
+
logstream.rewind
|
42
|
+
expect(logstream.read).to match('Setting local variable username to Wiz Khalifa')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context '#load_file JSON', type: :aruba do
|
47
|
+
before { write_file('params.json', '{"reminder":"You Know What It Is"}') }
|
48
|
+
|
49
|
+
it 'merges a JSON file as parameters' do
|
50
|
+
subject.load_file File.join(expand_path('./params.json'))
|
51
|
+
expect(subject[:reminder]).to eq('You Know What It Is')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#load_file YAML', type: :aruba do
|
56
|
+
before { write_file('params.yaml', '{"reminder":"You Know What It Is"}') }
|
57
|
+
|
58
|
+
it 'merges a YAML file as parameters' do
|
59
|
+
subject.load_file File.join(expand_path('./params.yaml'))
|
60
|
+
expect(subject[:reminder]).to eq('You Know What It Is')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '#[]' do
|
65
|
+
it 'accesses the parameters like a Hash' do
|
66
|
+
expect(subject).to respond_to(:[])
|
67
|
+
expect(subject[:username]).to eq('Wiz Khalifa')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
[:fetch, :keys, :values, :each_pair].each do |meth|
|
72
|
+
context "##{meth}" do
|
73
|
+
it "delegates the method #{meth} to the underlying parameters" do
|
74
|
+
expect(subject.parameters).to receive(meth)
|
75
|
+
subject.send meth
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-04-
|
12
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/cfndsl/conditions.rb
|
51
51
|
- lib/cfndsl/creation_policy.rb
|
52
52
|
- lib/cfndsl/errors.rb
|
53
|
+
- lib/cfndsl/external_parameters.rb
|
53
54
|
- lib/cfndsl/generate_types.rb
|
54
55
|
- lib/cfndsl/jsonable.rb
|
55
56
|
- lib/cfndsl/mappings.rb
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- sample/vpc_with_vpn_example.rb
|
87
88
|
- spec/cfndsl_spec.rb
|
88
89
|
- spec/cli_spec.rb
|
90
|
+
- spec/external_parameters_spec.rb
|
89
91
|
- spec/fixtures/heattest.rb
|
90
92
|
- spec/fixtures/test.rb
|
91
93
|
- spec/spec_helper.rb
|
@@ -117,6 +119,7 @@ summary: AWS Cloudformation DSL
|
|
117
119
|
test_files:
|
118
120
|
- spec/cfndsl_spec.rb
|
119
121
|
- spec/cli_spec.rb
|
122
|
+
- spec/external_parameters_spec.rb
|
120
123
|
- spec/fixtures/heattest.rb
|
121
124
|
- spec/fixtures/test.rb
|
122
125
|
- spec/spec_helper.rb
|