kumogata2 0.1.9 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f8d233adf58c553d0835355ab7c9befc443df1d
4
- data.tar.gz: 007dcc0ccdaa8fd9870ab0f9ee74a4fab04f577f
3
+ metadata.gz: 179adaf126269ec84361603f4195e22424289ac8
4
+ data.tar.gz: 677c9a57a3a0bb7766831faa888ee3e3c68f3dae
5
5
  SHA512:
6
- metadata.gz: 536c5cc9d3b2a6ab91e4ba3bde0919b249ab7f00f4e8cd4762ba2666c62de6b104bf62d4e541950a28e370dd201ee0a599c46244bfee3aad08280c47d9171204
7
- data.tar.gz: 3676a3513ddc0b497e9812b4f362f3934b7baa4ab504e4ae200553de73c461ccbd79d07e68da79cd4dec45f6f07a49f5112501c9dc1af9ea879bd9d6571807d3
6
+ metadata.gz: a643d946b7c12c60aa438d65fad921960b73fe60a2390ea1abc7078a86c973c5001350f37ebed2837851c3e8c37a0c0422397fef79f5968e08185e3035450e01
7
+ data.tar.gz: a0414ff4884871e759c44d1d2fef10f22ffcf501958a54a48764b354c35cb92ae138cb2604bfe9552da0f1ee065f0bc3671a9d7f4aeb5c24ea1d0aa3f83058db
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  *.json
11
+ *.yaml
11
12
  test.rb
data/README.md CHANGED
@@ -4,6 +4,8 @@ Kumogata2 is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformati
4
4
 
5
5
  This is a `format converter` + `useful tool`.
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/kumogata2.png?201406152020)](http://badge.fury.io/rb/kumogata2)
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -1,8 +1,7 @@
1
1
  module Kumogata2::CLI
2
2
  class OptionParser
3
3
  DEFAULT_OPTIONS = {
4
- result_log: File.join(Dir.pwd, 'result.json'),
5
- command_result_log: File.join(Dir.pwd, 'command_result.json'),
4
+ result_log: File.join(Dir.pwd, 'result.yaml'),
6
5
  color: $stdout.tty?,
7
6
  }
8
7
 
@@ -261,7 +260,7 @@ module Kumogata2::CLI
261
260
  max = expected.length
262
261
 
263
262
  if arguments.length < min or max < arguments.length
264
- raise "Usage: kumogata #{command} #{arguments_to_message(expected)} [options]"
263
+ raise "Usage: kumogata2 #{command} #{arguments_to_message(expected)} [options]"
265
264
  end
266
265
  end
267
266
 
@@ -150,7 +150,7 @@ class Kumogata2::Client
150
150
 
151
151
  def get_client
152
152
  return @client unless @client.nil?
153
- @client = Aws::CloudFormation::Client.new
153
+ @client = Aws::CloudFormation::Client.new(@options.aws)
154
154
  end
155
155
 
156
156
  def get_resource
@@ -175,7 +175,7 @@ class Kumogata2::Client
175
175
 
176
176
  params = {
177
177
  stack_name: stack_name,
178
- template_body: template.to_json,
178
+ template_body: convert_output_value(template),
179
179
  parameters: parameters_array,
180
180
  }
181
181
 
@@ -220,7 +220,7 @@ class Kumogata2::Client
220
220
 
221
221
  params = {
222
222
  stack_name: stack_name,
223
- template_body: template.to_json,
223
+ template_body: convert_output_value(template),
224
224
  parameters: parameters_array,
225
225
  }
226
226
 
@@ -285,7 +285,7 @@ class Kumogata2::Client
285
285
  end
286
286
 
287
287
  def validate_template(template)
288
- get_client.validate_template(template_body: template.to_json)
288
+ get_client.validate_template(template_body: convert_output_value(template))
289
289
  log(:info, 'Template validated successfully', color: :green)
290
290
  end
291
291
 
@@ -319,7 +319,7 @@ class Kumogata2::Client
319
319
  params = {
320
320
  stack_name: stack_name,
321
321
  change_set_name: change_set_name,
322
- template_body: template.to_json,
322
+ template_body: convert_output_value(template),
323
323
  parameters: parameters_array,
324
324
  }
325
325
 
@@ -382,8 +382,12 @@ class Kumogata2::Client
382
382
  resp.to_h
383
383
  end
384
384
 
385
+ def get_output_format
386
+ @options.output_format || 'template'
387
+ end
388
+
385
389
  def convert0(template)
386
- ext = @options.output_format || 'template'
390
+ ext = get_output_format
387
391
  plugin = find_or_create_plugin('xxx.' + ext)
388
392
 
389
393
  if plugin
@@ -605,13 +609,14 @@ Outputs:
605
609
  EOS
606
610
 
607
611
  if @options.result_log?
612
+ logname = get_output_filename(@options.result_log, stack_name)
608
613
  puts <<-EOS
609
614
 
610
- (Save to `#{@options.result_log}`)
615
+ (Save to `#{logname}`)
611
616
  EOS
612
617
 
613
- open(@options.result_log, 'wb') do |f|
614
- f.puts JSON.pretty_generate({
618
+ open(logname, 'wb') do |f|
619
+ f.puts convert_output_value({
615
620
  'StackName' => stack_name,
616
621
  'StackResourceSummaries' => summaries,
617
622
  'Outputs' => outputs,
@@ -620,6 +625,32 @@ EOS
620
625
  end
621
626
  end
622
627
 
628
+ def convert_output_value(value)
629
+ ext = get_output_format
630
+ Kumogata2::Plugin.plugin_by_name.each do |type, plugin|
631
+ next unless plugin[:ext].include? ext
632
+ case type
633
+ when 'json'
634
+ return JSON.pretty_generate(value)
635
+ when 'yaml'
636
+ return YAML.dump(value)
637
+ end
638
+ end
639
+ value
640
+ end
641
+
642
+ def get_output_filename(value, stack_name = '')
643
+ ext = get_output_format
644
+ Kumogata2::Plugin.plugin_by_name.each do |type, plugin|
645
+ if plugin[:ext].include? ext
646
+ plugin_ext = plugin[:ext].first
647
+ filename = stack_name.empty? ? File.basename(value, '.yaml') : stack_name
648
+ return "#{filename}.#{plugin_ext}"
649
+ end
650
+ end
651
+ value
652
+ end
653
+
623
654
  def post_process(path_or_url, outputs)
624
655
  plugin = find_or_create_plugin(path_or_url)
625
656
 
@@ -1,5 +1,5 @@
1
1
  class Kumogata2::Plugin::JSON
2
- Kumogata2::Plugin.register(:json, ['json', 'js', 'template'], self)
2
+ Kumogata2::Plugin.register(:json, ['json', 'js'], self)
3
3
 
4
4
  def initialize(options)
5
5
  @options = options
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
  class Kumogata2::Plugin::YAML
3
- Kumogata2::Plugin.register(:yaml, ['yaml', 'yml'], self)
3
+ Kumogata2::Plugin.register(:yaml, ['yaml', 'yml', 'template'], self)
4
4
 
5
5
  def initialize(options)
6
6
  @options = options
@@ -1,3 +1,3 @@
1
1
  module Kumogata2
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-19 00:00:00.000000000 Z
11
+ date: 2017-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.5.2
203
+ rubygems_version: 2.6.11
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Kumogata2 is a tool for AWS CloudFormation.