kumogata 0.4.4 → 0.4.5

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: df82f77f6c7023cbdaa9cf336a3857bd76bdbecb
4
- data.tar.gz: 0f6e167f920c80123bcf89338dbb023439eb46c8
3
+ metadata.gz: 7fdd78705361ec8fc36f2c44c1082e16f5c28789
4
+ data.tar.gz: a87009e2d2ee94e6b23415e1e6d6b6c7ebd7aad5
5
5
  SHA512:
6
- metadata.gz: a53b163c4963b3a216e4c7e2d563f63d75f76073f4f18b0386e75120e417f0717bcc5cfbaefe007d402e16c0c92de04cbe8669c1cff80d450fe5682f68442f1e
7
- data.tar.gz: ec3887e27bcecedb0ce01bf7e79a7e0077a0d6e61ee6269c88e51e9de72d9a3fbcb87f79f374c95f0c50547569ffcea2336d0ea2405043908c09e619434b8236
6
+ metadata.gz: e4af102fcc4b069f907dc145da52e899de20574f36500058c16ae80036d85d7147339dba61b0941033c0e5a4e3e55a2271c095d86771748367dbc169447abec1
7
+ data.tar.gz: ede746e11db3a41f3b1aae33dfa209e8fcbb1583f1a994d7ba8853703f11fa918d3efff1b9b83eab86977439f97bfe7cda595d891ebf571ac478e9bd367e6265
data/README.md CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  Kumogata is a tool for [AWS CloudFormation](https://aws.amazon.com/cloudformation/).
7
7
 
8
- [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403130235)](http://badge.fury.io/rb/kumogata)
9
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403130235)](https://drone.io/github.com/winebarrel/kumogata/latest)
8
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403151714)](http://badge.fury.io/rb/kumogata)
9
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403151714)](https://drone.io/github.com/winebarrel/kumogata/latest)
10
10
 
11
11
  It can define a template in Ruby DSL, such as:
12
12
 
data/bin/kumogata CHANGED
@@ -2,6 +2,7 @@
2
2
  $: << File.expand_path("#{File.dirname __FILE__}/../lib")
3
3
  require 'rubygems'
4
4
  require 'kumogata'
5
+ require 'kumogata/argument_parser'
5
6
 
6
7
  options = nil
7
8
 
@@ -14,7 +15,7 @@ parsed = Kumogata::ArgumentParser.parse! {|parser, cmd, args, opts|
14
15
  }
15
16
 
16
17
  begin
17
- command, arguments, options = parsed
18
+ command, arguments, options, output_result = parsed
18
19
 
19
20
  aws_opts = {}
20
21
 
@@ -24,8 +25,8 @@ begin
24
25
 
25
26
  AWS.config(aws_opts) unless aws_opts.empty?
26
27
 
27
- String.colorize = ($stdout.tty? and options.color?)
28
- Diffy::Diff.default_format = ($stdout.tty? and options.color?) ? :color : :text
28
+ String.colorize = options.color?
29
+ Diffy::Diff.default_format = options.color? ? :color : :text
29
30
 
30
31
  if options.debug?
31
32
  Kumogata.logger.set_debug(true)
@@ -37,12 +38,21 @@ begin
37
38
  end
38
39
 
39
40
  out = Kumogata::Client.new(options).send(command, *arguments)
40
- puts out if out
41
+
42
+ if output_result and out
43
+ puts out
44
+ end
41
45
  rescue Exception => e
42
46
  $stderr.puts("[ERROR] #{e.message}".red) unless e.kind_of?(Interrupt)
43
47
 
44
48
  if options and options.debug?
45
49
  raise e
50
+ else
51
+ backtrace = Kumogata::Utils.filter_backtrace(e.backtrace)
52
+ backtrace = backtrace.slice(0, 3)
53
+ unless backtrace.empty?
54
+ $stderr.puts " from #{backtrace.first}".red
55
+ end
46
56
  end
47
57
 
48
58
  exit 1
data/kumogata.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'aws-sdk'
22
22
  spec.add_dependency 'coderay'
23
23
  spec.add_dependency 'diffy'
24
- spec.add_dependency 'dslh', '>= 0.2.5'
24
+ spec.add_dependency 'dslh', '>= 0.2.6'
25
25
  spec.add_dependency 'hashie'
26
26
  spec.add_dependency 'highline'
27
27
  spec.add_dependency 'json'
@@ -3,58 +3,61 @@ $kumogata = Hashie::Mash.new
3
3
 
4
4
  class Kumogata::ArgumentParser
5
5
  DEFAULT_OPTIONS = {
6
- :replace_underscore => true,
7
6
  :delete_stack => true,
8
7
  :result_log => File.join(Dir.pwd, 'result.json'),
9
8
  :command_result_log => File.join(Dir.pwd, 'command_result.json'),
10
- :color => true,
9
+ :color => $stdout.tty?,
11
10
  :debug => false,
12
11
  }
13
12
 
14
13
  COMMANDS = {
15
14
  :create => {
16
15
  :description => 'Create resources as specified in the template',
17
- :arguments => [:path_or_url, :stack_name?]
16
+ :arguments => [:path_or_url, :stack_name?],
17
+ :output => false,
18
18
  },
19
19
  :validate => {
20
20
  :description => 'Validate a specified template',
21
- :arguments => [:path_or_url]
21
+ :arguments => [:path_or_url],
22
+ :output => false,
22
23
  },
23
24
  :convert => {
24
25
  :description => 'Convert a template format',
25
- :arguments => [:path_or_url]
26
+ :arguments => [:path_or_url],
26
27
  },
27
28
  :update => {
28
29
  :description => 'Update a stack as specified in the template',
29
- :arguments => [:path_or_url, :stack_name]
30
+ :arguments => [:path_or_url, :stack_name],
31
+ :output => false,
30
32
  },
31
33
  :delete => {
32
34
  :description => 'Delete a specified stack',
33
- :arguments => [:stack_name]
35
+ :arguments => [:stack_name],
36
+ :output => false,
34
37
  },
35
38
  :list => {
36
39
  :description => 'List summary information for stacks',
37
- :arguments => [:stack_name?]
40
+ :arguments => [:stack_name?],
38
41
  },
39
42
  :export => {
40
43
  :description => 'Export a template from a specified stack',
41
- :arguments => [:stack_name]
44
+ :arguments => [:stack_name],
42
45
  },
43
46
  :'show-events' => {
44
47
  :description => 'Show events for a specified stack',
45
- :arguments => [:stack_name]
48
+ :arguments => [:stack_name],
46
49
  },
47
50
  :'show-outputs' => {
48
51
  :description => 'Show outputs for a specified stack',
49
- :arguments => [:stack_name]
52
+ :arguments => [:stack_name],
50
53
  },
51
54
  :'show-resources' => {
52
55
  :description => 'Show resources for a specified stack',
53
- :arguments => [:stack_name]
56
+ :arguments => [:stack_name],
54
57
  },
55
58
  :diff => {
56
59
  :description => 'Compare templates logically',
57
- :arguments => [:path_or_url1, :path_or_url2]
60
+ :arguments => [:path_or_url1, :path_or_url2],
58
61
  },
59
62
  }
60
63
 
@@ -81,7 +84,7 @@ class Kumogata::ArgumentParser
81
84
  opt.on('-s', '--secret-key SECRET_KEY') {|v| options[:secret_access_key] = v }
82
85
  opt.on('-r', '--region REGION') {|v| options[:region] = v }
83
86
  opt.on('' , '--format TMPLATE_FORMAT', [:ruby, :json]) {|v| options[:format] = v }
84
- opt.on('' , '--skip-replace-underscore') { options[:replace_underscore] = false }
87
+ opt.on('' , '--skip-replace-underscore') { options[:skip_replace_underscore] = false }
85
88
  opt.on('' , '--deletion-policy-retain') { options[:deletion_policy_retain] = true }
86
89
  opt.on('-p', '--parameters KEY_VALUES', Array) {|v| options[:parameters] = v }
87
90
  opt.on('-e', '--encrypt-parameters KEYS', Array) {|v| options[:encrypt_parameters] = v }
@@ -95,6 +98,7 @@ class Kumogata::ArgumentParser
95
98
  opt.on('' , '--command-result-log PATH') {|v| options[:command] = v }
96
99
  opt.on('' , '--force') { options[:force] = true }
97
100
  opt.on('-w', '--ignore-all-space') { options[:ignore_all_space] = true }
101
+ opt.on('' , '--color') { options[:color] = true }
98
102
  opt.on('' , '--no-color') { options[:color] = false }
99
103
  opt.on('' , '--debug') { options[:debug] = true }
100
104
  opt.parse!
@@ -128,6 +132,7 @@ class Kumogata::ArgumentParser
128
132
  end
129
133
  end
130
134
 
135
+ output = COMMANDS[command].fetch(:output, true)
131
136
  command = command.to_s.gsub('-', '_').to_sym
132
137
 
133
138
  $kumogata.command = command
@@ -135,7 +140,7 @@ class Kumogata::ArgumentParser
135
140
  $kumogata.options = options
136
141
  options = $kumogata.options # Copy of the reference
137
142
 
138
- [command, arguments, options]
143
+ [command, arguments, options, output]
139
144
  end
140
145
 
141
146
  private
@@ -17,14 +17,14 @@ class Kumogata::Client
17
17
  outputs = create_stack(template, stack_name)
18
18
  @post_processing.run(:create, outputs)
19
19
 
20
- nil
20
+ outputs
21
21
  end
22
22
 
23
23
  def validate(path_or_url)
24
24
  template = open_template(path_or_url)
25
25
  add_encryption_password_for_validation(template)
26
26
  validate_template(template)
27
- nil
27
+ true
28
28
  end
29
29
 
30
30
  def convert(path_or_url)
@@ -48,7 +48,7 @@ class Kumogata::Client
48
48
  outputs = update_stack(template, stack_name)
49
49
  @post_processing.run(:update, outputs)
50
50
 
51
- nil
51
+ outputs
52
52
  end
53
53
 
54
54
  def delete(stack_name)
@@ -58,7 +58,7 @@ class Kumogata::Client
58
58
  delete_stack(stack_name)
59
59
  end
60
60
 
61
- nil
61
+ true
62
62
  end
63
63
 
64
64
  def list(stack_name = nil)
@@ -134,7 +134,7 @@ class Kumogata::Client
134
134
  def evaluate_template(template, path_or_url)
135
135
  key_converter = proc do |key|
136
136
  key = key.to_s
137
- key.gsub!('__', '::') if @options.replace_underscore?
137
+ key.gsub!('__', '::') unless @options.skip_replace_underscore?
138
138
  key
139
139
  end
140
140
 
@@ -551,16 +551,21 @@ Stack Resource Summaries:
551
551
 
552
552
  Outputs:
553
553
  #{JSON.pretty_generate(outputs).colorize_as(:json)}
554
+ EOS
554
555
 
555
- (Save to `#{@options.result_log}`)
556
- EOS
556
+ if @options.result_log?
557
+ puts <<-EOS
557
558
 
558
- open(@options.result_log, 'wb') do |f|
559
- f.puts JSON.pretty_generate({
560
- 'StackName' => stack_name,
561
- 'StackResourceSummaries' => summaries,
562
- 'Outputs' => outputs,
563
- })
559
+ (Save to `#{@options.result_log}`)
560
+ EOS
561
+
562
+ open(@options.result_log, 'wb') do |f|
563
+ f.puts JSON.pretty_generate({
564
+ 'StackName' => stack_name,
565
+ 'StackResourceSummaries' => summaries,
566
+ 'Outputs' => outputs,
567
+ })
568
+ end
564
569
  end
565
570
  end
566
571
 
@@ -62,7 +62,9 @@ class Kumogata::PostProcessing
62
62
  }
63
63
  end
64
64
 
65
- save_command_results(results) unless results.empty?
65
+ if @options.command_result_log? and not results.empty?
66
+ save_command_results(results)
67
+ end
66
68
  end
67
69
 
68
70
  private
@@ -17,6 +17,25 @@ class Kumogata::Utils
17
17
  a_zA_Z0_9 = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a)
18
18
  a_zA_Z0_9.sample(n).join
19
19
  end
20
+
21
+ def filter_backtrace(backtrace)
22
+ filter_path = ['(eval)']
23
+
24
+ if defined?(Gem)
25
+ filter_path.concat(Gem.path)
26
+ end
27
+
28
+ RbConfig::CONFIG.select {|k, v|
29
+ k.to_s =~ /libdir/
30
+ }.each {|k, v| filter_path << v }
31
+
32
+ filter_path = filter_path.map {|i| /\A#{Regexp.escape(i)}/ }
33
+
34
+ backtrace.select do |path|
35
+ path = path.split(':', 2).first
36
+ not filter_path.any? {|i| i =~ path }
37
+ end
38
+ end
20
39
  end # of class methods
21
40
  end
22
41
 
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
data/lib/kumogata.rb CHANGED
@@ -14,6 +14,7 @@ require 'net/ssh'
14
14
  require 'open-uri'
15
15
  require 'open3'
16
16
  require 'optparse'
17
+ require 'rbconfig'
17
18
  require 'retryable'
18
19
  require 'set'
19
20
  require 'singleton'
@@ -22,7 +23,6 @@ require 'term/ansicolor'
22
23
  require 'thread'
23
24
  require 'uuidtools'
24
25
 
25
- require 'kumogata/argument_parser'
26
26
  require 'kumogata/client'
27
27
  require 'kumogata/crypt'
28
28
  require 'kumogata/ext/coderay_ext'
@@ -77,11 +77,11 @@ Outputs do
77
77
  end
78
78
  EOS
79
79
 
80
- Timecop.freeze(Time.parse('2014/03/13 0:00')) do
80
+ Timecop.freeze(Time.utc(2014)) do
81
81
  run_client(:update, :arguments => ['MyStack'], :template => template, :options => {:deletion_policy_retain => true}) do |client, cf|
82
82
  template = eval_template(template, :update_deletion_policy => true)
83
83
  template["Resources"]["myEC2Instance"]["Metadata"] = {
84
- "DeletionPolicyUpdateKeyForKumogata" => "DeletionPolicyUpdateValueForKumogata1394636400"
84
+ "DeletionPolicyUpdateKeyForKumogata" => "DeletionPolicyUpdateValueForKumogata1388534400"
85
85
  }
86
86
  json = template.to_json
87
87
  client.should_receive(:print_event_log).once
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'kumogata'
2
+ require 'kumogata/argument_parser'
2
3
  require 'tempfile'
3
4
  require 'time'
4
5
  require 'timecop'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumogata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.5
61
+ version: 0.2.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.5
68
+ version: 0.2.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hashie
71
71
  requirement: !ruby/object:Gem::Requirement