aws-must 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4df0abe6aafa2e3145f9995eee51a1b4f4a6bf9c
4
- data.tar.gz: daa5ad0f99ff4a785fd664cba698cda7e79d540c
3
+ metadata.gz: ef1ec5cf98ec249bc3e9be5ece8c0c7d4688f987
4
+ data.tar.gz: 5433b3272b9c497981c4ada810e52701bc4f5ef4
5
5
  SHA512:
6
- metadata.gz: 48346e91b649bd279a2966bb6dde84a6ee11bd251e181e8b96bb7cd628519aba8f58dfe8a3f9b370268a02c2302f16261ec1ce9d94da30976f1bed367f0817b2
7
- data.tar.gz: 5710ab165795472d962d85f28b3bdbf148f1a17cf9146f6fef18a5da67c9b26e3191e830fd6a1ce5e3d9c2fbeeec2cd615a68773674ab898eb30d6472c8d81ca
6
+ metadata.gz: c1decbdc3b13c2cf84603a916b7e2ed42768b54a7e81ef902ee7639cc2419829bf0901d4cf7c7842ec1110146fe649ac10e6f2e243fd1925934cd9b92b91509c
7
+ data.tar.gz: bc5bd0f0664d9ec1b32dc9e6394f1dee496978c584f7484fc9ffb8250baf5b5986325b64e73d682d334d3dab07b7681951ad3b8f7316ab5f3bb769d13753cf56
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.13$
1
+ # aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.14$
2
2
 
3
3
  `aws-must` is a tool, which allows separating infrastructure
4
4
  configuration and Amazon related syntax in CloudFormation JSON
@@ -1,308 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
-
4
- require 'thor'
5
- require_relative '../lib/aws-must'
6
-
7
- class App < Thor
8
-
9
- include Utils::MyLogger # mix logger
10
- PROGNAME = "main" # logger progname
11
-
12
- # default values
13
-
14
- DEAFAULT_TEMPLATE="root" # name of template in :template_path -directory
15
-
16
- # DEFAUL_FOLD_ON="<!--*SED-MAGIC* <div class=window> -->" # default output for +++fold-on+++ tag
17
- # DEFAUL_FOLD_OFF="<!--*SED-MAGIC* </div> -->" # default output for +++fold-off+++ tag
18
-
19
- # default output for +++fold-on+++ tag
20
- DEFAUL_FOLD_ON="<div class='fold'>Check to show template: <input type='checkbox' class='toggle'/><div>"
21
- DEFAUL_FOLD_OFF="</div></div>" # default output for +++fold-off+++ tag
22
-
23
- # ------------------------------------------------------------------
24
- # make two thor tasks share options?
25
- # http://stackoverflow.com/questions/14346285/how-to-make-two-thor-tasks-share-options
26
-
27
- class << self
28
- def add_shared_option(name, options = {})
29
- @shared_options = {} if @shared_options.nil?
30
- @shared_options[name] = options
31
- end
32
-
33
- def shared_options(*option_names)
34
- option_names.each do |option_name|
35
- opt = @shared_options[option_name]
36
- raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
37
- option option_name, opt
38
- end
39
- end
40
- end
41
-
42
- def initialize(*args)
43
- super
44
- @logger = getLogger( PROGNAME, options )
45
- end
46
-
47
- # ------------------------------------------------------------------
48
-
49
- class_option :log, :aliases => "-l", :type =>:string, :default => nil,
50
- :enum => [ "DEBUG", "INFO", "WARN", "ERROR" ],
51
- :desc => "Set debug level "
52
-
53
-
54
- # ------------------------------------------------------------------
55
- add_shared_option :template_gem, :aliases => "-g", :type => :string,
56
- :desc => "Mustache template Gem name (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') (DEPRECATED)"
57
-
58
- add_shared_option :template_path, :aliases => "-t", :type =>
59
- :string, :desc => "Directory holding mustache templates (DEPRECATED)"
60
-
61
- add_shared_option :mustaches, :aliases => "-m", :type =>
62
- :array, :default => [ "mustache/"],
63
- :desc => "Array of directory paths (ending with slash '/' char e.g. 'mustache/') of Gem names (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') holding mustache templates"
64
-
65
- # ------------------------------------------------------------------
66
- # action 'doc'
67
-
68
- desc "doc", "Extract template documentation"
69
-
70
- shared_options :template_path
71
- shared_options :mustaches
72
- shared_options :template_gem
73
-
74
- option :fold_on, :aliases => "-n", :type => :string,
75
- :default => DEFAUL_FOLD_ON,
76
- :desc => "Output for +++fold-on+++ tag"
77
-
78
- option :fold_off, :aliases => "-f", :type => :string,
79
- :default => DEFAUL_FOLD_OFF,
80
- :desc => "Output for +++fold-off+++ tag"
81
-
82
- long_desc <<-LONGDESC
83
-
84
- Extract documation from <template_name> in ':template_path' -directory.
85
-
86
- <template_name> defaults to '#{DEAFAULT_TEMPLATE}'
87
-
88
-
89
- Documentation is extracted from lines surrounded by #{AwsMust::Docu::DEFAULT_OPEN_TAG} and #{AwsMust::Docu::DEFAULT_CLOSE_TAG} tags,
90
- or by #{AwsMust::Docu::DEFAULT_FOLD_ON_TAG} and #{AwsMust::Docu::DEFAULT_FOLD_OFF_TAG} tags.
91
-
92
- Following rules apply:
93
-
94
- - #{AwsMust::Docu::DEFAULT_OPEN_TAG}, #{AwsMust::Docu::DEFAULT_CLOSE_TAG} -tags: nothing is outputted for these lines
95
-
96
- - #{AwsMust::Docu::DEFAULT_FOLD_ON_TAG} -tag: output text for --fold_on option (defaults '#{DEFAUL_FOLD_ON}')
97
-
98
- - #{AwsMust::Docu::DEFAULT_FOLD_OFF_TAG} -tag: output text for --fold_off option (defaults '#{DEFAUL_FOLD_OFF}')
99
-
100
-
101
- Defult fold_on and fold_off parameters implement CCS-toggle when using following css-code
102
-
103
- /* CSS-support fold-on/fold-off toggle */\n
104
- div.fold { width: 90%; padding: .42rem; border-radius: 5px; margin: 1rem; }\n
105
- div.fold div { height: 0px; margin: .2rem; overflow: hidden; }\n
106
- div.toggle ~ div { height: 0px; margin: .2rem; overflow: hidden; }\n
107
- input.toggle:checked ~ div { height: auto;color: white; background: #c6a24b;font-family: monospace;white-space: pre; }\n
108
-
109
-
110
- LONGDESC
111
-
112
- def doc( template_name=DEAFAULT_TEMPLATE )
113
-
114
- @logger.info( "#{__method__} starting" )
115
-
116
-
117
- my_options = option_adjust_common( options )
118
-
119
- app = ::AwsMust::AwsMust.new( my_options )
120
- app.doc( template_name )
121
-
122
- end
123
-
124
- # ------------------------------------------------------------------
125
- # action 'json'
126
-
127
- desc "json <yaml_file> [with_adjust]", "Dump configuration in JSON format (with or without adjustment)"
128
-
129
- long_desc <<-LONGDESC
130
-
131
- Reads <yaml_file> and dumps it to stdout in JSON format
132
- 'with_adjust' (yes/no)
133
-
134
- By default 'adjusts' data, i.e. adds property "_comma" with the
135
- value "," to each sub document, expect the last sub-document is
136
- adjusted with empty string "".
137
-
138
- The "_comma" -property helps in generating valid json arrays in
139
- mustache templates. For example, YAML construct
140
-
141
- tags:
142
- - Key: key1
143
- Value: value1
144
-
145
- - Key: key2
146
- Value: value2
147
-
148
- and Mustache template snippet
149
-
150
- { "Tags" : [
151
- {{#tags}}
152
- { "Key" : "{{Key}}", "Value" : "{{Value}}"{{_comma}} }
153
- {{/tags}}
154
- ]}
155
-
156
- results to valid JSON document
157
-
158
- { "Tags" : [
159
- { "Key" : "key1", "Value" : "value1",
160
- { "Key" : "key2", "Value" : "value2"
161
- ]}
162
-
163
- LONGDESC
164
-
165
-
166
- def json( yaml_file, with_adjust="true" )
167
-
168
- app = ::AwsMust::AwsMust.new( options )
169
- app.json( yaml_file, with_adjust =~ /^true$/ || with_adjust =~ /^yes$/ ? true : false )
170
-
171
- end
172
-
173
-
174
- # ------------------------------------------------------------------
175
- # action 'gen'
176
-
177
- desc "gen <yaml_file> [<template_name>]", "Generate CloudFormation JSON template"
178
-
179
- shared_options :template_path
180
- shared_options :mustaches
181
- shared_options :template_gem
182
-
183
- long_desc <<-LONGDESC
184
-
185
- Generate Amazon CloudFormation JSON file for <yaml_file> using
186
- <template_name> in ':template_path' -directory.
187
-
188
- <template_name> defaults to '#{DEAFAULT_TEMPLATE}'
189
-
190
- LONGDESC
191
-
192
-
193
- def gen( yaml_file, template_name=DEAFAULT_TEMPLATE )
194
-
195
- my_options = option_adjust_common( options )
196
-
197
- app = ::AwsMust::AwsMust.new( my_options )
198
- app.generate( template_name, yaml_file, my_options )
199
-
200
- end
201
-
202
- # ------------------------------------------------------------------
203
- # common routines
204
- no_commands do
205
-
206
- def option_adjust_common( options )
207
-
208
- raise "No optios given" unless options
209
-
210
- # options readonly - dup allows modification
211
- options = options.dup
212
-
213
- @logger.debug( "#{__method__}, options '#{options}'" )
214
-
215
- options = option_template_gem_to_template_path( options ) if options[:template_gem]
216
- options = option_template_path( options ) if options[:template_path]
217
-
218
- warn <<-EOS unless options[:mustaches] && options[:mustaches].any?
219
-
220
- Deprecation!!
221
-
222
- Use option -m to define location of templates
223
-
224
- Options -g and -t deprecated
225
- EOS
226
-
227
- options = option_mustaches_to_template_paths( options ) if options[:mustaches]
228
-
229
- return options
230
- end
231
-
232
- # set `options[:template_path]` to an array of local directory
233
- # paths parsed from list of options[:mustaches]
234
- def option_mustaches_to_template_paths( options )
235
-
236
- # init, NB: plural
237
- options[:template_paths] = []
238
-
239
- options[:mustaches].each do |mustache_def|
240
- if mustache_def[-1] == '/' then
241
- # directory with last char removed
242
- options[:template_paths] << mustache_def[0..-1]
243
- else
244
- # gemname
245
- options[:template_paths] << gem_name_to_template_path( mustache_def )
246
- end
247
-
248
- end
249
- return options
250
- end
251
-
252
- # overrides -m option
253
- def option_template_path( options )
254
- # overrides -m option
255
- options[:mustaches] = []
256
- return options
257
- end
258
-
259
- # set 'options[:template_path]' to mustache directory withing
260
- # `options[:template_gem]` Gem
261
- def option_template_gem_to_template_path( options )
262
-
263
- # overrides -m option
264
- options[:mustaches] = []
265
-
266
- options[:template_path] = gem_name_to_template_path( options[:template_gem] )
267
-
268
- return options
269
-
270
- end
271
-
272
- # map 'gem_name_and_spec' to path of mustache templates
273
- def gem_name_to_template_path( gem_name_and_spec )
274
-
275
- # The version requirements are optional.
276
- # You can also specify multiple version requirements, just append more at the end
277
- gem_spec = gem_name_and_spec.split(',')
278
- gem_name, *gem_ver_reqs = gem_spec[0], gem_spec[1]
279
- @logger.debug( "#{__method__}, gem_name=#{gem_name}, *gem_ver_reqs=#{gem_ver_reqs}" )
280
- gdep = Gem::Dependency.new(gem_name, *gem_ver_reqs)
281
- # find latest that satisifies
282
- found_gspec = gdep.matching_specs.sort_by(&:version).last
283
- @logger.debug( "#{__method__}, found_gspec=#{found_gspec}" )
284
- # instead of using Gem::Dependency, you can also do:
285
- # Gem::Specification.find_all_by_name(gem_name, *gem_ver_reqs)
286
-
287
- if found_gspec
288
- @logger.debug( "#{__method__}, Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" )
289
- @logger.debug( "#{__method__}, old-options=#{options}" )
290
- template_path = "#{found_gspec.gem_dir}/mustache"
291
- @logger.debug( "#{__method__}, template_path=#{template_path}" )
292
- else
293
- #puts "Requirement '#{gdep}' not satisfied; installing..."
294
- # ver_args = gdep.requirements_list.map{|s| ['-v', s] }.flatten
295
- # # multi-arg is safer, to avoid injection attacks
296
- # system('gem', 'install', gem_name, *ver_args)
297
- raise "Could not find gem '#{gdep}' - try 'gem install #{gdep}'"
298
- end
299
-
300
- return template_path
301
-
302
- end
303
-
304
- end # no commands
305
-
306
- end
3
+ require_relative "../lib/cli/aws-must-cli"
307
4
 
308
5
  App.start
@@ -5,6 +5,7 @@ module AwsMust
5
5
  require_relative 'aws-must/aws-must'
6
6
  require_relative 'aws-must/template'
7
7
  require_relative 'aws-must/docu'
8
+ require_relative 'aws-must/fileprovider'
8
9
 
9
10
  end
10
11
 
@@ -56,13 +56,15 @@ module AwsMust
56
56
  end
57
57
 
58
58
  # ------------------------------------------------------------------
59
- # generate JSON by rendering 'template_name' using configurations
59
+ # output result of rendering 'template_name' using configurations
60
60
  # from 'yaml_file'
61
61
 
62
62
  def generate( template_name, yaml_file, options )
63
63
  puts generate_str( template_name, yaml_file, options )
64
64
  end
65
65
 
66
+ # return the result of rendering 'template_name' using
67
+ # configurations from 'yaml_file' as a string
66
68
  def generate_str( template_name, yaml_file, options )
67
69
 
68
70
  @logger.debug( "#{__method__}, template_name '#{template_name}'" )
@@ -61,7 +61,7 @@ module AwsMust
61
61
 
62
62
  def document( template_name )
63
63
 
64
- @logger.debug( "#{__method__}, template_name '#{template_name}'" )
64
+ @logger.info( "#{__method__}, template_name '#{template_name}'" )
65
65
 
66
66
  #
67
67
  template_string = @template.get_template( template_name )
@@ -81,6 +81,7 @@ module AwsMust
81
81
  if open_found then
82
82
 
83
83
  state_opened = true
84
+ @logger.info( "#{__method__}, open tag in '#{template_name}'" )
84
85
 
85
86
  # something follows the start -tag
86
87
  redo if line && ! line.empty?
@@ -95,9 +96,11 @@ module AwsMust
95
96
  # puts "close_found=#{close_found}, #{close_found.class}, line=#{line}"
96
97
  if close_found then
97
98
  output( line_pre ) if line_pre && !line_pre.empty?
99
+ @logger.info( "#{__method__}, close tag in '#{template_name}'" )
98
100
  state_opened = false
99
101
  redo if line && ! line.empty?
100
102
  elsif template_name = directive_include( line ) then
103
+ @logger.info( "#{__method__}, include in '#{template_name}'" )
101
104
  document( template_name )
102
105
  else
103
106
  output( line )
@@ -112,7 +115,6 @@ module AwsMust
112
115
  # output - document output
113
116
 
114
117
  def output( line )
115
-
116
118
  puts( line )
117
119
  end
118
120
 
@@ -0,0 +1,13 @@
1
+ module AwsMust
2
+
3
+ # allow Docu class to access files
4
+ class FileProvider
5
+ def initialize( optionss=nil )
6
+ end
7
+ # return lines in a file as a long string
8
+ def get_template( file_name )
9
+ return File.readlines( file_name ).join
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,338 @@
1
+
2
+ require 'thor'
3
+ require_relative '../aws-must'
4
+
5
+
6
+ class App < Thor
7
+
8
+ include Utils::MyLogger # mix logger
9
+ PROGNAME = "main" # logger progname
10
+
11
+ # default values
12
+
13
+ DEAFAULT_TEMPLATE="root" # name of template in :template_path -directory
14
+
15
+ # DEFAUL_FOLD_ON="<!--*SED-MAGIC* <div class=window> -->" # default output for +++fold-on+++ tag
16
+ # DEFAUL_FOLD_OFF="<!--*SED-MAGIC* </div> -->" # default output for +++fold-off+++ tag
17
+
18
+ # default output for +++fold-on+++ tag
19
+ DEFAUL_FOLD_ON="<div class='fold'>Check to show template: <input type='checkbox' class='toggle'/><div>"
20
+ DEFAUL_FOLD_OFF="</div></div>" # default output for +++fold-off+++ tag
21
+
22
+ # ------------------------------------------------------------------
23
+ # make two thor tasks share options?
24
+ # http://stackoverflow.com/questions/14346285/how-to-make-two-thor-tasks-share-options
25
+
26
+ class << self
27
+ def add_shared_option(name, options = {})
28
+ @shared_options = {} if @shared_options.nil?
29
+ @shared_options[name] = options
30
+ end
31
+
32
+ def shared_options(*option_names)
33
+ option_names.each do |option_name|
34
+ opt = @shared_options[option_name]
35
+ raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
36
+ option option_name, opt
37
+ end
38
+ end
39
+ end
40
+
41
+ def initialize(*args)
42
+ super
43
+ @logger = getLogger( PROGNAME, options )
44
+ end
45
+
46
+ # ------------------------------------------------------------------
47
+
48
+ class_option :log, :aliases => "-l", :type =>:string, :default => nil,
49
+ :enum => [ "DEBUG", "INFO", "WARN", "ERROR" ],
50
+ :desc => "Set debug level "
51
+
52
+
53
+ # ------------------------------------------------------------------
54
+ add_shared_option :template_gem, :aliases => "-g", :type => :string,
55
+ :desc => "Mustache template Gem name (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') (DEPRECATED)"
56
+
57
+ add_shared_option :template_path, :aliases => "-t", :type =>
58
+ :string, :desc => "Directory holding mustache templates (DEPRECATED)"
59
+
60
+ add_shared_option :mustaches, :aliases => "-m", :type =>
61
+ :array, :default => [ "mustache/"],
62
+ :desc => "Array of directory paths (ending with slash '/' char e.g. 'mustache/') of Gem names (optionally with version constraint e.g. 'aws-must-templates,~>0.0.1') holding mustache templates"
63
+
64
+
65
+ add_shared_option :fold_on, :aliases => "-n", :type => :string,
66
+ :default => DEFAUL_FOLD_ON,
67
+ :desc => "Output for +++fold-on+++ tag"
68
+
69
+ add_shared_option :fold_off, :aliases => "-f", :type => :string,
70
+ :default => DEFAUL_FOLD_OFF,
71
+ :desc => "Output for +++fold-off+++ tag"
72
+
73
+
74
+
75
+ # ------------------------------------------------------------------
76
+ # action 'doc'
77
+
78
+ desc "doc", "Extract documentation in template"
79
+
80
+ shared_options :template_path
81
+ shared_options :mustaches
82
+ shared_options :template_gem
83
+
84
+ shared_options :fold_on
85
+ shared_options :fold_off
86
+
87
+
88
+ long_desc <<-LONGDESC
89
+
90
+ Extract documation from <template_name> in ':template_path' -directory.
91
+
92
+ <template_name> defaults to '#{DEAFAULT_TEMPLATE}'
93
+
94
+
95
+ Documentation is extracted from lines surrounded by #{AwsMust::Docu::DEFAULT_OPEN_TAG} and #{AwsMust::Docu::DEFAULT_CLOSE_TAG} tags,
96
+ or by #{AwsMust::Docu::DEFAULT_FOLD_ON_TAG} and #{AwsMust::Docu::DEFAULT_FOLD_OFF_TAG} tags.
97
+
98
+ Following rules apply:
99
+
100
+ - #{AwsMust::Docu::DEFAULT_OPEN_TAG}, #{AwsMust::Docu::DEFAULT_CLOSE_TAG} -tags: nothing is outputted for these lines
101
+
102
+ - #{AwsMust::Docu::DEFAULT_FOLD_ON_TAG} -tag: output text for --fold_on option (defaults '#{DEFAUL_FOLD_ON}')
103
+
104
+ - #{AwsMust::Docu::DEFAULT_FOLD_OFF_TAG} -tag: output text for --fold_off option (defaults '#{DEFAUL_FOLD_OFF}')
105
+
106
+
107
+ Defult fold_on and fold_off parameters implement CCS-toggle when using following css-code
108
+
109
+ /* CSS-support fold-on/fold-off toggle */\n
110
+ div.fold { width: 90%; padding: .42rem; border-radius: 5px; margin: 1rem; }\n
111
+ div.fold div { height: 0px; margin: .2rem; overflow: hidden; }\n
112
+ div.toggle ~ div { height: 0px; margin: .2rem; overflow: hidden; }\n
113
+ input.toggle:checked ~ div { height: auto;color: white; background: #c6a24b;font-family: monospace;white-space: pre; }\n
114
+
115
+
116
+ LONGDESC
117
+
118
+ def doc( template_name=DEAFAULT_TEMPLATE )
119
+
120
+ @logger.info( "#{__method__} starting" )
121
+
122
+
123
+ my_options = option_adjust_common( options )
124
+
125
+ app = ::AwsMust::AwsMust.new( my_options )
126
+ app.doc( template_name )
127
+
128
+ end
129
+
130
+ # ------------------------------------------------------------------
131
+ # action 'ddoc'
132
+
133
+ desc "ddoc <pattern>", "Extract documentation in <pattern> files"
134
+
135
+ shared_options :fold_on
136
+ shared_options :fold_off
137
+
138
+
139
+ def ddoc( pattern )
140
+
141
+ @logger.info( "#{__method__} starting, options '#{options}'" )
142
+
143
+
144
+ files = Dir.glob( pattern ).sort
145
+ files.each do |file|
146
+ @logger.debug( "#{__method__}, file '#{file}'" )
147
+ fileProvider = AwsMust::FileProvider.new( options )
148
+ docu = AwsMust::Docu.new( fileProvider, options )
149
+ docu.document( file )
150
+ end
151
+
152
+ end
153
+
154
+
155
+ # ------------------------------------------------------------------
156
+ # action 'json'
157
+
158
+ desc "json <yaml_file> [with_adjust]", "Dump configuration in JSON format (with or without adjustment)"
159
+
160
+ long_desc <<-LONGDESC
161
+
162
+ Reads <yaml_file> and dumps it to stdout in JSON format
163
+ 'with_adjust' (yes/no)
164
+
165
+ By default 'adjusts' data, i.e. adds property "_comma" with the
166
+ value "," to each sub document, expect the last sub-document is
167
+ adjusted with empty string "".
168
+
169
+ The "_comma" -property helps in generating valid json arrays in
170
+ mustache templates. For example, YAML construct
171
+
172
+ tags:
173
+ - Key: key1
174
+ Value: value1
175
+
176
+ - Key: key2
177
+ Value: value2
178
+
179
+ and Mustache template snippet
180
+
181
+ { "Tags" : [
182
+ {{#tags}}
183
+ { "Key" : "{{Key}}", "Value" : "{{Value}}"{{_comma}} }
184
+ {{/tags}}
185
+ ]}
186
+
187
+ results to valid JSON document
188
+
189
+ { "Tags" : [
190
+ { "Key" : "key1", "Value" : "value1",
191
+ { "Key" : "key2", "Value" : "value2"
192
+ ]}
193
+
194
+ LONGDESC
195
+
196
+
197
+ def json( yaml_file, with_adjust="true" )
198
+
199
+ app = ::AwsMust::AwsMust.new( options )
200
+ app.json( yaml_file, with_adjust =~ /^true$/ || with_adjust =~ /^yes$/ ? true : false )
201
+
202
+ end
203
+
204
+
205
+ # ------------------------------------------------------------------
206
+ # action 'gen'
207
+
208
+ desc "gen <yaml_file> [<template_name>]", "Generate CloudFormation JSON template"
209
+
210
+ shared_options :template_path
211
+ shared_options :mustaches
212
+ shared_options :template_gem
213
+
214
+ long_desc <<-LONGDESC
215
+
216
+ Generate Amazon CloudFormation JSON file for <yaml_file> using
217
+ <template_name> in ':template_path' -directory.
218
+
219
+ <template_name> defaults to '#{DEAFAULT_TEMPLATE}'
220
+
221
+ LONGDESC
222
+
223
+
224
+ def gen( yaml_file, template_name=DEAFAULT_TEMPLATE )
225
+
226
+ my_options = option_adjust_common( options )
227
+
228
+ app = ::AwsMust::AwsMust.new( my_options )
229
+ app.generate( template_name, yaml_file, my_options )
230
+
231
+ end
232
+
233
+ # ------------------------------------------------------------------
234
+ # common routines
235
+ no_commands do
236
+
237
+ def option_adjust_common( options )
238
+
239
+ raise "No optios given" unless options
240
+
241
+ # options readonly - dup allows modification
242
+ options = options.dup
243
+
244
+ @logger.debug( "#{__method__}, options '#{options}'" )
245
+
246
+ options = option_template_gem_to_template_path( options ) if options[:template_gem]
247
+ options = option_template_path( options ) if options[:template_path]
248
+
249
+ warn <<-EOS unless options[:mustaches] && options[:mustaches].any?
250
+
251
+ Deprecation!!
252
+
253
+ Use option -m to define location of templates
254
+
255
+ Options -g and -t deprecated
256
+ EOS
257
+
258
+ options = option_mustaches_to_template_paths( options ) if options[:mustaches]
259
+
260
+ return options
261
+ end
262
+
263
+ # set `options[:template_path]` to an array of local directory
264
+ # paths parsed from list of options[:mustaches]
265
+ def option_mustaches_to_template_paths( options )
266
+
267
+ # init, NB: plural
268
+ options[:template_paths] = []
269
+
270
+ options[:mustaches].each do |mustache_def|
271
+ if mustache_def[-1] == '/' then
272
+ # directory with last char removed
273
+ options[:template_paths] << mustache_def[0..-1]
274
+ else
275
+ # gemname
276
+ options[:template_paths] << gem_name_to_template_path( mustache_def )
277
+ end
278
+
279
+ end
280
+ return options
281
+ end
282
+
283
+ # overrides -m option
284
+ def option_template_path( options )
285
+ # overrides -m option
286
+ options[:mustaches] = []
287
+ return options
288
+ end
289
+
290
+ # set 'options[:template_path]' to mustache directory withing
291
+ # `options[:template_gem]` Gem
292
+ def option_template_gem_to_template_path( options )
293
+
294
+ # overrides -m option
295
+ options[:mustaches] = []
296
+
297
+ options[:template_path] = gem_name_to_template_path( options[:template_gem] )
298
+
299
+ return options
300
+
301
+ end
302
+
303
+ # map 'gem_name_and_spec' to path of mustache templates
304
+ def gem_name_to_template_path( gem_name_and_spec )
305
+
306
+ # The version requirements are optional.
307
+ # You can also specify multiple version requirements, just append more at the end
308
+ gem_spec = gem_name_and_spec.split(',')
309
+ gem_name, *gem_ver_reqs = gem_spec[0], gem_spec[1]
310
+ @logger.debug( "#{__method__}, gem_name=#{gem_name}, *gem_ver_reqs=#{gem_ver_reqs}" )
311
+ gdep = Gem::Dependency.new(gem_name, *gem_ver_reqs)
312
+ # find latest that satisifies
313
+ found_gspec = gdep.matching_specs.sort_by(&:version).last
314
+ @logger.debug( "#{__method__}, found_gspec=#{found_gspec}" )
315
+ # instead of using Gem::Dependency, you can also do:
316
+ # Gem::Specification.find_all_by_name(gem_name, *gem_ver_reqs)
317
+
318
+ if found_gspec
319
+ @logger.debug( "#{__method__}, Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" )
320
+ @logger.debug( "#{__method__}, old-options=#{options}" )
321
+ template_path = "#{found_gspec.gem_dir}/mustache"
322
+ @logger.debug( "#{__method__}, template_path=#{template_path}" )
323
+ else
324
+ #puts "Requirement '#{gdep}' not satisfied; installing..."
325
+ # ver_args = gdep.requirements_list.map{|s| ['-v', s] }.flatten
326
+ # # multi-arg is safer, to avoid injection attacks
327
+ # system('gem', 'install', gem_name, *ver_args)
328
+ raise "Could not find gem '#{gdep}' - try 'gem install #{gdep}'"
329
+ end
330
+
331
+ return template_path
332
+
333
+ end
334
+
335
+ end # no commands
336
+
337
+ end
338
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-must
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - jarjuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-23 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -101,7 +101,9 @@ files:
101
101
  - lib/aws-must.rb
102
102
  - lib/aws-must/aws-must.rb
103
103
  - lib/aws-must/docu.rb
104
+ - lib/aws-must/fileprovider.rb
104
105
  - lib/aws-must/template.rb
106
+ - lib/cli/aws-must-cli.rb
105
107
  - lib/tasks/demo.rake
106
108
  - lib/utils/hasher.rb
107
109
  - lib/utils/logger.rb
@@ -131,3 +133,4 @@ signing_key:
131
133
  specification_version: 4
132
134
  summary: Minimum Viable Solution to Manage CloudFormation Templates'
133
135
  test_files: []
136
+ has_rdoc: