kumogata 0.3.11 → 0.3.12

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2UxODIxNjc5ZDcyMmU2ZTgwNmE3NDdhYWEyYzEwNDhmYmUxOTI3NA==
4
+ Y2E5OGQ4ZGRjNGI4MWJlNTBlNjQ0NzYzZDY3NTIwYmM0MzVmOTk0Mw==
5
5
  data.tar.gz: !binary |-
6
- ODgzY2QxYTQ0ZGU2ZDI5MGJlYzNhMDI3NDQwMjUzZmZmZjAyNTcwYg==
6
+ ODAxMjk3ZjIzZTdkZDM1YzAwZjdlOTY3MGEwNzk2Yjk1ODEyNzA5ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzdkMmIwOTgxZjllOTRhYmVmZTQyMDFkMTk1MjUyNzgyNGEzZTRiMmUzNDYw
10
- ZWMzYjFlMTRlNmE3YzRmMTYyY2VkOWEwYzc3MjE0MmI3ZGI3YjRhNGM5ZTQw
11
- NGFiZGRjZTAxMjNiZGMxMDIzM2YzZGZlZmI2YjRmZjBjNWFkNTA=
9
+ ZWY5YmQ2MmYyMjI5ODQyODk3OGE0YzYwMzg4ZGU5OTMzZWNkZjAyZTEyMjgx
10
+ NjgwNmM3YzJiOGU3NGM3YmJlNGI1NjIwOGQ4YzEzMjM5NDA1YTUwNDcyMjEz
11
+ ZjA4NTVjY2MxODk4NTMxMzQ3NGE1ZTg1YWQyNGNjMTUyOTEzOGQ=
12
12
  data.tar.gz: !binary |-
13
- MDQxNzMzNmZiMDZiZWM4MjA0YzNhMDkwMDIxMGZkODFjOTAxZWEyOTZmY2Ew
14
- NWE1N2RjY2E0NmU1OWJlMmQ1ZmZlMDE2OWIwNTcyOWQ5MmI2Zjc2MmQzMThi
15
- ODdhYmZjNTczMDMwYzBlMzk1ZTU5OTA1ZWZjZThmZDUyOWFlMWU=
13
+ ZDA1ZDk0YTQ0OWI2NjQxZTliYTViNWY3NDc1NDQ2ZDhkZTQyNmM3NGM2OGEy
14
+ OWFlZDcwOTUxY2Q2MGFmODEzY2RiYWRlNWU5NDI0MzBjNzgyNTVkZTE0ZGM1
15
+ MDViOThiMGYwOTNmYjZhMzQ1YmI0MmEzZjE5MjRiYjY4MTE5YmE=
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?201403111050)](http://badge.fury.io/rb/kumogata)
9
- [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403111050)](https://drone.io/github.com/winebarrel/kumogata/latest)
8
+ [![Gem Version](https://badge.fury.io/rb/kumogata.png?201403111115)](http://badge.fury.io/rb/kumogata)
9
+ [![Build Status](https://drone.io/github.com/winebarrel/kumogata/status.png?201403111115)](https://drone.io/github.com/winebarrel/kumogata/latest)
10
10
 
11
11
  It can define a template in Ruby DSL, such as:
12
12
 
@@ -14,6 +14,7 @@ require 'net/ssh'
14
14
  require 'open-uri'
15
15
  require 'open3'
16
16
  require 'optparse'
17
+ require 'set'
17
18
  require 'singleton'
18
19
  require 'strscan'
19
20
  require 'term/ansicolor'
@@ -18,21 +18,26 @@ class Kumogata::PostProcessing
18
18
  options = _post[:options] || {}
19
19
  @command_options.merge(options)
20
20
 
21
+ outputs = template['Outputs'] || {}
22
+
21
23
  _post.fetch(:commands).each do |name, attrs|
22
24
  unless attrs.kind_of?(Hash) and attrs['command']
23
25
  raise "Invalid post processing: #{name} => #{attrs.inspect}"
24
26
  end
25
27
 
26
28
  timing = [(attrs['after'] || TRIGGER_TIMING)].flatten.map {|i| i.to_sym }
29
+ command = attrs['command']
30
+
27
31
  validate_timing(name, timing)
32
+ validate_command_template(name, command, outputs)
28
33
 
29
34
  @commands[name] = {
30
35
  :after => timing,
31
- :command => attrs['command'],
36
+ :command => command,
32
37
  }
33
38
 
34
39
  if (ssh = attrs['ssh'])
35
- validate_ssh(name, ssh)
40
+ validate_ssh(name, ssh, outputs)
36
41
  @commands[name][:ssh] = ssh
37
42
  end
38
43
  end
@@ -70,7 +75,7 @@ class Kumogata::PostProcessing
70
75
  end
71
76
  end
72
77
 
73
- def validate_ssh(name, ssh)
78
+ def validate_ssh(name, ssh, outputs)
74
79
  host, user, options = ssh.values_at('host', 'user', 'options')
75
80
 
76
81
  unless host and user
@@ -88,6 +93,8 @@ class Kumogata::PostProcessing
88
93
  ssh['host'] = host.to_s
89
94
  end
90
95
 
96
+ validate_command_template(name, ssh['host'], outputs)
97
+
91
98
  if user.kind_of?(Hash)
92
99
  if user.keys != ['Key']
93
100
  raise "Invalid post processing ssh user: #{name} => #{user.inspect}"
@@ -99,6 +106,8 @@ class Kumogata::PostProcessing
99
106
  ssh['user'] = user.to_s
100
107
  end
101
108
 
109
+ validate_command_template(name, ssh['user'], outputs)
110
+
102
111
  if options and not options.kind_of?(Hash)
103
112
  raise "Invalid post processing ssh options: #{name} => #{options.inspect}"
104
113
  end
@@ -172,6 +181,29 @@ class Kumogata::PostProcessing
172
181
  Open3.capture3(command)
173
182
  end
174
183
 
184
+ def validate_command_template(name, command, outputs)
185
+ command = command.undent if @command_options[:undent]
186
+ trim_mode = @command_options[:trim_mode]
187
+ expected_outputs = Set.new
188
+
189
+ scope = Object.new
190
+ scope.instance_variable_set(:@__expected_outputs__, expected_outputs)
191
+
192
+ scope.instance_eval(<<-EOS)
193
+ def Key(name)
194
+ @__expected_outputs__ << name
195
+ end
196
+
197
+ ERB.new(#{command.inspect}, nil, #{trim_mode.inspect}).result(binding)
198
+ EOS
199
+
200
+ expected_outputs.each do |key|
201
+ unless outputs.keys.include?(key)
202
+ raise "Unknown output: #{name} => #{key.inspect}"
203
+ end
204
+ end
205
+ end
206
+
175
207
  def evaluate_command_template(command, outputs)
176
208
  command = command.undent if @command_options[:undent]
177
209
  trim_mode = @command_options[:trim_mode]
@@ -1,3 +1,3 @@
1
1
  module Kumogata
2
- VERSION = '0.3.11'
2
+ VERSION = '0.3.12'
3
3
  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.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara