kumogata 0.1.6 → 0.1.7

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
- ODhkMTUzNDVjOWU3YjNjMjNmZjFjMDQ5MDQ1ZGJmOWI5Y2MzMmQ4Ng==
4
+ MTA0NDRkYThiNzBhNzgwODU4YWUxOTM5ZDNjYjUwMjU2Yzc3OTY0MA==
5
5
  data.tar.gz: !binary |-
6
- NDRhOWNlNzJiYzRhMTQyZDIwNmNkM2NjMTZiNTY0YmM3MTNlOWJmYg==
6
+ NzJmZjYzZTI2NDg0OGFkN2M2NTZiZWNkOTA0ZmZmYWVkODkwMDU5Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjM3OWIzZTBjOWY3MjZlNzhmYWVjYTU4MmE1ODYxNGQ1NGVhM2ZkODhkNDQz
10
- YjUyZmU1N2I1NWQ0NmVkZjE4MTJjYmRmYmYyMGM2ODA2MTNiYzgxOGMzMTQ0
11
- NzFhZjhjZGU3NmI0M2MxMjViNmMzZjdiZmVlNzY0MzczNjBmMWI=
9
+ ZjY5YTYzMDliYTkwNTJhNzdkMmY4MDgwY2E0NTJiMDEwOTUxMzliNDNiZjBh
10
+ ZmMxOTA2OWM2ZjI1MWVjOWYxOGRlNTAwMmIwNWZjNjNhNmZiMGU1Nzg0N2Ux
11
+ ODZiOTBjOWVlY2VlNjQyYjZiZjgyZTBjZDhjZDYwZWZhY2E4M2Q=
12
12
  data.tar.gz: !binary |-
13
- MzgyMjRmMTIwZjJmZGI1ZjJhMmQ5NjBhYzM5NzNjNTQ0MmJkMjE4NzliYmE0
14
- YTRkZGVhMWJhMzUyNDc2NjdkNDdjNzA1NTVjZWJhYjVmMGU4ODhhNWFlZGM5
15
- OGUyODE1ODdiNTJiYmUxM2Y3ZmZjYTYyNWE5YTc4M2Q2Yjc3YjU=
13
+ ZmU3MmY5YjU0YWE4YmY1ZDczNWU1Nzg1NGJiN2Y4ODkyMmE4ZDg0YzBhYzgx
14
+ OGZkNjM2NzBjOTViZWUzZmI3ZTQwOTYwYTA3ZWZkYmI2YTNjODZlMmU5MmE1
15
+ MjViMmQ4YTMxNzU4ZWZmOTM1ZTJhYmNjNzE1N2Q4NWJjMTlhNTk=
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403031537)](http://badge.fury.io/rb/kumogata)
6
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403031537)](https://drone.io/github.com/winebarrel/kumogata/latest)
5
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403031647)](http://badge.fury.io/rb/kumogata)
6
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403031647)](https://drone.io/github.com/winebarrel/kumogata/latest)
7
7
 
8
8
  It can define a template in Ruby DSL, such as:
9
9
 
@@ -184,8 +184,9 @@ class Kumogata::Client
184
184
 
185
185
  data = data.map do |item|
186
186
  if item.kind_of?(String)
187
- item = item.split("\n").map {|i| i.gsub(/\A\s+/, "") }.join("\n")
188
- item = " " + item if prev_not_str
187
+ item = item.split("\n").map {|i|
188
+ prev_not_str ? i : i.gsub(/\A\s+/, "")
189
+ }.join("\n")
189
190
  prev_not_str = false
190
191
  item
191
192
  else
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -93,4 +93,193 @@ Outputs do
93
93
  end
94
94
  EOS
95
95
  end
96
+
97
+ it 'convert Ruby template to JSON template with _join()' do
98
+ template = <<-TEMPLATE
99
+ Parameters do
100
+ Password do
101
+ NoEcho true
102
+ Type "String"
103
+ end
104
+ end
105
+
106
+ Resources do
107
+ myEC2Instance do
108
+ Type "AWS::EC2::Instance"
109
+ Properties do
110
+ ImageId "ami-XXXXXXXX"
111
+ InstanceType "t1.micro"
112
+
113
+ UserData do
114
+ Fn__Base64 _join(<<-EOS)
115
+ #!/bin/bash
116
+ /opt/aws/bin/cfn-init -s <%= Ref "AWS::StackName" %> -r myEC2Instance --region <%= Ref "AWS::Region" %>
117
+ EOS
118
+ end
119
+ end
120
+
121
+ Metadata do
122
+ AWS__CloudFormation__Init do
123
+ config do
124
+
125
+ packages do
126
+ yum({"httpd"=>[]})
127
+ end
128
+
129
+ services do
130
+ sysvinit do
131
+ httpd do
132
+ enabled "true"
133
+ ensureRunning "true"
134
+ end
135
+ end
136
+ end
137
+
138
+ commands do
139
+ any_name do
140
+ command _join(<<-EOS)
141
+ echo <%= Ref "Password" %> > /tmp/my-password
142
+ EOS
143
+ end
144
+ end
145
+
146
+ end # config
147
+ end # AWS__CloudFormation__Init
148
+ end # Metadata
149
+ end
150
+ end
151
+ TEMPLATE
152
+
153
+ json_template = run_client(:convert, :template => template)
154
+
155
+ expect(json_template).to eq((<<-'EOS').chomp)
156
+ {
157
+ "Parameters": {
158
+ "Password": {
159
+ "NoEcho": "true",
160
+ "Type": "String"
161
+ }
162
+ },
163
+ "Resources": {
164
+ "myEC2Instance": {
165
+ "Type": "AWS::EC2::Instance",
166
+ "Properties": {
167
+ "ImageId": "ami-XXXXXXXX",
168
+ "InstanceType": "t1.micro",
169
+ "UserData": {
170
+ "Fn::Base64": {
171
+ "Fn::Join": [
172
+ "",
173
+ [
174
+ "#!/bin/bash\n/opt/aws/bin/cfn-init -s ",
175
+ {
176
+ "Ref": "AWS::StackName"
177
+ },
178
+ " -r myEC2Instance --region ",
179
+ {
180
+ "Ref": "AWS::Region"
181
+ },
182
+ "\n"
183
+ ]
184
+ ]
185
+ }
186
+ }
187
+ },
188
+ "Metadata": {
189
+ "AWS::CloudFormation::Init": {
190
+ "config": {
191
+ "packages": {
192
+ "yum": {
193
+ "httpd": [
194
+
195
+ ]
196
+ }
197
+ },
198
+ "services": {
199
+ "sysvinit": {
200
+ "httpd": {
201
+ "enabled": "true",
202
+ "ensureRunning": "true"
203
+ }
204
+ }
205
+ },
206
+ "commands": {
207
+ "any_name": {
208
+ "command": {
209
+ "Fn::Join": [
210
+ "",
211
+ [
212
+ "echo ",
213
+ {
214
+ "Ref": "Password"
215
+ },
216
+ " > /tmp/my-password",
217
+ "\n"
218
+ ]
219
+ ]
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ EOS
230
+ end
231
+
232
+ it 'convert Ruby template to JSON template with _user_data()' do
233
+ template = <<-TEMPLATE
234
+ Parameters do
235
+ Password do
236
+ NoEcho true
237
+ Type "String"
238
+ end
239
+ end
240
+
241
+ Resources do
242
+ myEC2Instance do
243
+ Type "AWS::EC2::Instance"
244
+ Properties do
245
+ ImageId "ami-XXXXXXXX"
246
+ InstanceType "t1.micro"
247
+
248
+ UserData _user_data(<<-EOS)
249
+ #!/bin/bash
250
+ yum install -y httpd
251
+ services start httpd
252
+ EOS
253
+ end
254
+ end
255
+ end
256
+ TEMPLATE
257
+
258
+ json_template = run_client(:convert, :template => template)
259
+
260
+ # UserData: IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgLXkgaHR0cGQKc2VydmljZXMgc3RhcnQgaHR0cGQK
261
+ # => #!/bin/bash
262
+ # yum install -y httpd
263
+ # services start httpd
264
+ expect(json_template).to eq((<<-EOS).chomp)
265
+ {
266
+ "Parameters": {
267
+ "Password": {
268
+ "NoEcho": "true",
269
+ "Type": "String"
270
+ }
271
+ },
272
+ "Resources": {
273
+ "myEC2Instance": {
274
+ "Type": "AWS::EC2::Instance",
275
+ "Properties": {
276
+ "ImageId": "ami-XXXXXXXX",
277
+ "InstanceType": "t1.micro",
278
+ "UserData": "IyEvYmluL2Jhc2gKeXVtIGluc3RhbGwgLXkgaHR0cGQKc2VydmljZXMgc3RhcnQgaHR0cGQK"
279
+ }
280
+ }
281
+ }
282
+ }
283
+ EOS
284
+ end
96
285
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara