kumogata 0.4.18 → 0.4.19
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 +4 -4
- data/README.md +104 -1
- data/kumogata.gemspec +2 -0
- data/lib/kumogata/argument_parser.rb +1 -1
- data/lib/kumogata/client.rb +19 -1
- data/lib/kumogata/version.rb +1 -1
- data/lib/kumogata.rb +2 -0
- data/spec/kumogata_convert_spec.rb +139 -0
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a626076a8776de3b3f80ff1627fa21753236f73c
|
4
|
+
data.tar.gz: 2b532df5a2e844ceb3ea69d791fb1d2fcc30fc5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfbc840b9761ff339e536a6e4e43c8a27866c910454ffb8f0783ff2ec446d3a691025dd9db4ae9c16d2f85f1310e6b864a74442cbb7f00bf0356833a9902b163
|
7
|
+
data.tar.gz: 71cc9feed08e69b16523136b607f5c7f2184ac7a8f5855dd0d3d9a53e59bcfd7c3dcebe55f47f30f351124624f5385788a4f86a4f317f6fb9796e46ba077db1d
|
data/README.md
CHANGED
@@ -9,6 +9,8 @@ It supports the following format:
|
|
9
9
|
* Ruby
|
10
10
|
* YAML
|
11
11
|
* JavaScript
|
12
|
+
* CoffeeScript (experimental)
|
13
|
+
* JSON5 (experimental)
|
12
14
|
|
13
15
|
[](http://badge.fury.io/rb/kumogata)
|
14
16
|
[](https://travis-ci.org/winebarrel/kumogata)
|
@@ -372,7 +374,7 @@ Status: 0
|
|
372
374
|
|
373
375
|
## JavaScript template
|
374
376
|
|
375
|
-
You can also use the
|
377
|
+
You can also use the JavaScript template instead of JSON and Ruby.
|
376
378
|
|
377
379
|
```javascript
|
378
380
|
function fetch_ami() {
|
@@ -431,6 +433,55 @@ function fetch_ami() {
|
|
431
433
|
|
432
434
|
$ kumogata convert Drupal_Single_Instance.template --output-format=js
|
433
435
|
|
436
|
+
## CoffeeScript template
|
437
|
+
|
438
|
+
You can also use the CoffeeScript template instead of JSON and Ruby.
|
439
|
+
|
440
|
+
```coffeescript
|
441
|
+
fetch_ami = () -> "ami-XXXXXXXX"
|
442
|
+
|
443
|
+
/* For JS Object is evaluated last, it must use `return` */
|
444
|
+
return {
|
445
|
+
Resources:
|
446
|
+
myEC2Instance:
|
447
|
+
Type: "AWS::EC2::Instance",
|
448
|
+
Properties:
|
449
|
+
ImageId: fetch_ami(),
|
450
|
+
InstanceType: "t1.micro"
|
451
|
+
Outputs:
|
452
|
+
AZ: # comment
|
453
|
+
Value:
|
454
|
+
"Fn::GetAtt": [
|
455
|
+
"myEC2Instance",
|
456
|
+
"AvailabilityZone"
|
457
|
+
]
|
458
|
+
}
|
459
|
+
|
460
|
+
###
|
461
|
+
{
|
462
|
+
"Resources": {
|
463
|
+
"myEC2Instance": {
|
464
|
+
"Type": "AWS::EC2::Instance",
|
465
|
+
"Properties": {
|
466
|
+
"ImageId": "ami-XXXXXXXX",
|
467
|
+
"InstanceType": "t1.micro"
|
468
|
+
}
|
469
|
+
}
|
470
|
+
},
|
471
|
+
"Outputs": {
|
472
|
+
"AZ": {
|
473
|
+
"Value": {
|
474
|
+
"Fn::GetAtt": [
|
475
|
+
"myEC2Instance",
|
476
|
+
"AvailabilityZone"
|
477
|
+
]
|
478
|
+
}
|
479
|
+
}
|
480
|
+
}
|
481
|
+
}
|
482
|
+
###
|
483
|
+
```
|
484
|
+
|
434
485
|
## YAML template
|
435
486
|
|
436
487
|
You can also use the YAML template instead of JSON and Ruby.
|
@@ -477,6 +528,58 @@ Outputs:
|
|
477
528
|
|
478
529
|
$ kumogata convert Drupal_Single_Instance.template --output-format=yaml
|
479
530
|
|
531
|
+
## [JSON5](http://json5.org/) template
|
532
|
+
|
533
|
+
You can also use the [JSON5](http://json5.org/) template instead of JSON and Ruby.
|
534
|
+
|
535
|
+
```javascript
|
536
|
+
{
|
537
|
+
Resources: { /* comment */
|
538
|
+
myEC2Instance: {
|
539
|
+
Type: "AWS::EC2::Instance",
|
540
|
+
Properties: {
|
541
|
+
ImageId: "ami-XXXXXXXX",
|
542
|
+
InstanceType: "t1.micro"
|
543
|
+
}
|
544
|
+
}
|
545
|
+
},
|
546
|
+
Outputs: {
|
547
|
+
AZ: { /* comment */
|
548
|
+
Value: {
|
549
|
+
"Fn::GetAtt": [
|
550
|
+
"myEC2Instance",
|
551
|
+
"AvailabilityZone"
|
552
|
+
]
|
553
|
+
}
|
554
|
+
}
|
555
|
+
}
|
556
|
+
}
|
557
|
+
|
558
|
+
/*
|
559
|
+
{
|
560
|
+
"Resources": {
|
561
|
+
"myEC2Instance": {
|
562
|
+
"Type": "AWS::EC2::Instance",
|
563
|
+
"Properties": {
|
564
|
+
"ImageId": "ami-XXXXXXXX",
|
565
|
+
"InstanceType": "t1.micro"
|
566
|
+
}
|
567
|
+
}
|
568
|
+
},
|
569
|
+
"Outputs": {
|
570
|
+
"AZ": {
|
571
|
+
"Value": {
|
572
|
+
"Fn::GetAtt": [
|
573
|
+
"myEC2Instance",
|
574
|
+
"AvailabilityZone"
|
575
|
+
]
|
576
|
+
}
|
577
|
+
}
|
578
|
+
}
|
579
|
+
}
|
580
|
+
*/
|
581
|
+
```
|
582
|
+
|
480
583
|
## Outputs Filter
|
481
584
|
|
482
585
|
```ruby
|
data/kumogata.gemspec
CHANGED
@@ -20,11 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency 'aws-sdk'
|
22
22
|
spec.add_dependency 'coderay'
|
23
|
+
spec.add_dependency 'coffee-script'
|
23
24
|
spec.add_dependency 'diffy'
|
24
25
|
spec.add_dependency 'dslh', '>= 0.2.7'
|
25
26
|
spec.add_dependency 'hashie'
|
26
27
|
spec.add_dependency 'highline'
|
27
28
|
spec.add_dependency 'json'
|
29
|
+
spec.add_dependency 'json5'
|
28
30
|
spec.add_dependency 'net-ssh'
|
29
31
|
spec.add_dependency 'retryable'
|
30
32
|
spec.add_dependency 'term-ansicolor'
|
@@ -80,7 +80,7 @@ class Kumogata::ArgumentParser
|
|
80
80
|
update_usage(opt)
|
81
81
|
|
82
82
|
begin
|
83
|
-
supported_formats = [:ruby, :json, :yaml, :js]
|
83
|
+
supported_formats = [:ruby, :json, :yaml, :js, :coffee, :json5]
|
84
84
|
opt.on('-k', '--access-key ACCESS_KEY') {|v| options[:access_key_id] = v }
|
85
85
|
opt.on('-s', '--secret-key SECRET_KEY') {|v| options[:secret_access_key] = v }
|
86
86
|
opt.on('-r', '--region REGION') {|v| options[:region] = v }
|
data/lib/kumogata/client.rb
CHANGED
@@ -41,18 +41,21 @@ class Kumogata::Client
|
|
41
41
|
when :json then :ruby
|
42
42
|
when :yaml then :json
|
43
43
|
when :js then :json
|
44
|
+
when :json5 then :json
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
case output_format
|
48
49
|
when :ruby
|
49
50
|
devaluate_template(template).chomp.colorize_as(:ruby)
|
50
|
-
when :json
|
51
|
+
when :json, :json5
|
51
52
|
JSON.pretty_generate(template).colorize_as(:json)
|
52
53
|
when :yaml
|
53
54
|
YAML.dump(template).colorize_as(:yaml)
|
54
55
|
when :js
|
55
56
|
'(' + JSON.pretty_generate(template).colorize_as(:json) + ')'
|
57
|
+
when :coffee
|
58
|
+
raise 'Output to CoffeeScript is not implemented'
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
@@ -174,6 +177,17 @@ class Kumogata::Client
|
|
174
177
|
end
|
175
178
|
|
176
179
|
Kumogata::Utils.stringify(obj.to_hash)
|
180
|
+
when :coffee
|
181
|
+
completed = CoffeeScript.compile(f.read)
|
182
|
+
obj = V8::Context.new.eval(completed)
|
183
|
+
|
184
|
+
unless obj.instance_of?(V8::Object)
|
185
|
+
raise "Invalid CoffeeScript template. Please return Object: #{path_or_url}"
|
186
|
+
end
|
187
|
+
|
188
|
+
Kumogata::Utils.stringify(obj.to_hash)
|
189
|
+
when :json5
|
190
|
+
JSON5.parse(f.read)
|
177
191
|
else
|
178
192
|
raise "Unknown format: #{format}"
|
179
193
|
end
|
@@ -196,6 +210,10 @@ class Kumogata::Client
|
|
196
210
|
:yaml
|
197
211
|
when '.js'
|
198
212
|
:js
|
213
|
+
when '.coffee'
|
214
|
+
:coffee
|
215
|
+
when '.json5'
|
216
|
+
:json5
|
199
217
|
else
|
200
218
|
:json
|
201
219
|
end
|
data/lib/kumogata/version.rb
CHANGED
data/lib/kumogata.rb
CHANGED
@@ -4,11 +4,13 @@ require 'kumogata/version'
|
|
4
4
|
require 'aws-sdk'
|
5
5
|
require 'base64'
|
6
6
|
require 'coderay'
|
7
|
+
require 'coffee-script'
|
7
8
|
require 'diffy'
|
8
9
|
require 'dslh'
|
9
10
|
require 'hashie'
|
10
11
|
require 'highline/import'
|
11
12
|
require 'json'
|
13
|
+
require 'json5'
|
12
14
|
require 'logger'
|
13
15
|
require 'net/ssh'
|
14
16
|
require 'open-uri'
|
@@ -225,6 +225,145 @@ end
|
|
225
225
|
EOS
|
226
226
|
end
|
227
227
|
|
228
|
+
it 'convert Ruby template to JSON5 template' do
|
229
|
+
template = <<-EOS
|
230
|
+
Resources do
|
231
|
+
myEC2Instance do
|
232
|
+
Type "AWS::EC2::Instance"
|
233
|
+
Properties do
|
234
|
+
ImageId "ami-XXXXXXXX"
|
235
|
+
InstanceType "t1.micro"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
Outputs do
|
241
|
+
AZ do
|
242
|
+
Value do
|
243
|
+
Fn__GetAtt "myEC2Instance", "AvailabilityZone"
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
EOS
|
248
|
+
|
249
|
+
js_template = run_client(:convert, :template => template, :options => {:output_format => :json5})
|
250
|
+
|
251
|
+
expect(js_template).to eq <<-EOS.strip
|
252
|
+
{
|
253
|
+
"Resources": {
|
254
|
+
"myEC2Instance": {
|
255
|
+
"Type": "AWS::EC2::Instance",
|
256
|
+
"Properties": {
|
257
|
+
"ImageId": "ami-XXXXXXXX",
|
258
|
+
"InstanceType": "t1.micro"
|
259
|
+
}
|
260
|
+
}
|
261
|
+
},
|
262
|
+
"Outputs": {
|
263
|
+
"AZ": {
|
264
|
+
"Value": {
|
265
|
+
"Fn::GetAtt": [
|
266
|
+
"myEC2Instance",
|
267
|
+
"AvailabilityZone"
|
268
|
+
]
|
269
|
+
}
|
270
|
+
}
|
271
|
+
}
|
272
|
+
}
|
273
|
+
EOS
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'convert JSON5 template to Ruby template' do
|
277
|
+
template = <<-EOS
|
278
|
+
{
|
279
|
+
Resources: { /* comment */
|
280
|
+
myEC2Instance: {
|
281
|
+
Type: "AWS::EC2::Instance",
|
282
|
+
Properties: {
|
283
|
+
ImageId: "ami-XXXXXXXX",
|
284
|
+
InstanceType: "t1.micro"
|
285
|
+
}
|
286
|
+
}
|
287
|
+
},
|
288
|
+
Outputs: {
|
289
|
+
AZ: { /* comment */
|
290
|
+
Value: {
|
291
|
+
"Fn::GetAtt": [
|
292
|
+
"myEC2Instance",
|
293
|
+
"AvailabilityZone"
|
294
|
+
]
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
}
|
299
|
+
EOS
|
300
|
+
|
301
|
+
ruby_template = run_client(:convert, :template => template, :template_ext => '.json5', :options => {:output_format => :ruby})
|
302
|
+
|
303
|
+
expect(ruby_template).to eq((<<-EOS).chomp)
|
304
|
+
Resources do
|
305
|
+
myEC2Instance do
|
306
|
+
Type "AWS::EC2::Instance"
|
307
|
+
Properties do
|
308
|
+
ImageId "ami-XXXXXXXX"
|
309
|
+
InstanceType "t1.micro"
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
Outputs do
|
314
|
+
AZ do
|
315
|
+
Value do
|
316
|
+
Fn__GetAtt "myEC2Instance", "AvailabilityZone"
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
EOS
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'convert JavaScript template to Ruby template' do
|
324
|
+
template = <<-EOS
|
325
|
+
fetch_ami = () -> "ami-XXXXXXXX"
|
326
|
+
|
327
|
+
# comment
|
328
|
+
return {
|
329
|
+
Resources:
|
330
|
+
myEC2Instance:
|
331
|
+
Type: "AWS::EC2::Instance",
|
332
|
+
Properties:
|
333
|
+
ImageId: fetch_ami(),
|
334
|
+
InstanceType: "t1.micro"
|
335
|
+
Outputs:
|
336
|
+
AZ: # comment
|
337
|
+
Value:
|
338
|
+
"Fn::GetAtt": [
|
339
|
+
"myEC2Instance",
|
340
|
+
"AvailabilityZone"
|
341
|
+
]
|
342
|
+
}
|
343
|
+
EOS
|
344
|
+
|
345
|
+
ruby_template = run_client(:convert, :template => template, :template_ext => '.coffee', :options => {:output_format => :ruby})
|
346
|
+
|
347
|
+
expect(ruby_template).to eq((<<-EOS).chomp)
|
348
|
+
Resources do
|
349
|
+
myEC2Instance do
|
350
|
+
Type "AWS::EC2::Instance"
|
351
|
+
Properties do
|
352
|
+
ImageId "ami-XXXXXXXX"
|
353
|
+
InstanceType "t1.micro"
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
Outputs do
|
358
|
+
AZ do
|
359
|
+
Value do
|
360
|
+
Fn__GetAtt "myEC2Instance", "AvailabilityZone"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
EOS
|
365
|
+
end
|
366
|
+
|
228
367
|
it 'convert YAML template to JSON template' do
|
229
368
|
template = <<-EOS
|
230
369
|
---
|
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.4.
|
4
|
+
version: 0.4.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coffee-script
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: diffy
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - '>='
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: json5
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: net-ssh
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|