aws-must 0.0.7 → 0.0.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: b5cbfe13a7f701b92bdb2bb092716c9ad6a58403
4
- data.tar.gz: ce6ebf729e31b5d0a66294ced5060365fda6ebab
3
+ metadata.gz: 2c24b20220f2f8c9469ed37c1521f47945b33abf
4
+ data.tar.gz: 555fea1c14b4f38f29db7d46b7f6346ee61006f1
5
5
  SHA512:
6
- metadata.gz: 1d62abc49a43f6347439054009544963440daf46159f37b1a8413a9b91de1271909b291dd4599f7d5f811a39cb6de24ac45794fbc2b142cdc306ef8b265687eb
7
- data.tar.gz: 5952680e1bd12a74c3f6e427351cb0f5c0ec8a61c9b329e44b7f5f8899fd5f6fbae9d65476074ddb002b116f8c26f165fd521ea85cd1f49088d211339eeb2756
6
+ metadata.gz: 15bf6f675da9078c230ade99c7e5975aedf8912948c8b22335fa14b58b68353172475457dd8a91f65960198534e3628d9c468e5f64634a7935bc32325425ed3a
7
+ data.tar.gz: 755034b30c68c6f4245cddfd1b8eb89fb203d747ce671037d5daa78ea8591544f2d96a7fcf94b4d691216281aea2df78bc5ef1e40dc0d5a978a0024f90dd670b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.7$
1
+ # aws-must - Minimum Viable Solution to Manage CloudFormation Templates - $Release:0.0.10$
2
2
 
3
3
  `aws-must` is a tool, which allows separating infrastructure
4
4
  configuration and Amazon related syntax in CloudFormation JSON
@@ -98,16 +98,38 @@ template `./mustache/root.mustache` issue the command
98
98
 
99
99
  aws-must.rb gen yaml_file
100
100
 
101
- To extract documentation from template `./mustache/root.mustache`,
101
+ The path of Mustache templates can be changed using `-t` option, or by
102
+ giving the name of a gem with a `-g` option. For example, to use the
103
+ latest version of
104
+ [aws-must-templates](https://github.com/jarjuk/aws-must-templates),
105
+ use the command
106
+
107
+ aws-must.rb gen yaml_file -g aws-must-templates
108
+
109
+ The version constraint for the gem can be specified followed by a
110
+ comma -character. For example, to use version specification `~>0.0.1`,
102
111
  issue the command
103
112
 
113
+ aws-must.rb gen yaml_file -g 'aws-must-templates,~>0.0.1'
114
+
115
+ To extract documentation for the templates
116
+
104
117
  aws-must.rb doc
105
-
118
+
119
+ The documentation command supports the same `-t` and `-g` options, as
120
+ the `gen` -command.
106
121
 
107
122
  Documentation is extracted from lines surrounded by **+++start+++**
108
123
  and **+++close+++** tags, or by **+++fold-on+++** and
109
- **+++fold-off+++** tags. To see more information on how documentation
110
- is generated, issue the the command
124
+ **+++fold-off+++** tags. Examples documents for
125
+ [demo:html-7](https://rawgit.com/jarjuk/aws-must/master/generated-docs/7.html),
126
+ [demo:html-6](https://rawgit.com/jarjuk/aws-must/master/generated-docs/6.html),
127
+ [demo:html-5](https://rawgit.com/jarjuk/aws-must/master/generated-docs/5.html),
128
+ [demo:html-4](https://rawgit.com/jarjuk/aws-must/master/generated-docs/4.html),
129
+ and
130
+ [demo:html-3](https://rawgit.com/jarjuk/aws-must/master/generated-docs/3.html).
131
+ To see more information on how documentation is generated, issue the
132
+ the command
111
133
 
112
134
  aws-must.rb help doc
113
135
 
@@ -242,6 +264,6 @@ See [RELEASES](RELEASES.md)
242
264
  MIT
243
265
 
244
266
 
245
-
267
+
246
268
 
247
269
 
data/bin/aws-must.rb CHANGED
@@ -20,20 +20,53 @@ class App < Thor
20
20
  DEFAUL_FOLD_ON="<div class='fold'>Check to show template: <input type='checkbox' class='toggle'/><div>"
21
21
  DEFAUL_FOLD_OFF="</div></div>" # default output for +++fold-off+++ tag
22
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
+
23
47
  # ------------------------------------------------------------------
24
48
 
25
49
  class_option :log, :aliases => "-l", :type =>:string, :default => nil,
26
50
  :enum => [ "DEBUG", "INFO", "WARN", "ERROR" ],
27
51
  :desc => "Set debug level "
28
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')"
57
+
58
+ add_shared_option :template_path, :aliases => "-t", :type =>
59
+ :string, :default => "mustache",
60
+ :desc => "Directory holding mustache templates"
61
+
62
+
29
63
  # ------------------------------------------------------------------
30
64
  # action 'doc'
31
65
 
32
66
  desc "doc", "Extract template documentation"
33
67
 
34
- option :template_path, :aliases => "-t", :type => :string,
35
- :default => "mustache",
36
- :desc => "Directory holding mustache templates"
68
+ shared_options :template_path
69
+ shared_options :template_gem
37
70
 
38
71
  option :fold_on, :aliases => "-n", :type => :string,
39
72
  :default => DEFAUL_FOLD_ON,
@@ -75,7 +108,12 @@ LONGDESC
75
108
 
76
109
  def doc( template_name=DEAFAULT_TEMPLATE )
77
110
 
78
- app = ::AwsMust::AwsMust.new( options )
111
+ @logger.info( "#{__FILE__}.#{__method__} starting" )
112
+
113
+
114
+ my_options = option_adjust_common( options )
115
+
116
+ app = ::AwsMust::AwsMust.new( my_options )
79
117
  app.doc( template_name )
80
118
 
81
119
  end
@@ -135,14 +173,13 @@ LONGDESC
135
173
 
136
174
  desc "gen <yaml_file> [<template_name>]", "Generate CloudFormation JSON template"
137
175
 
138
- option :template_path, :aliases => "-t", :type => :string,
139
- :default => "mustache",
140
- :desc => "Directory holding mustache templates"
176
+ shared_options :template_path
177
+ shared_options :template_gem
141
178
 
142
179
  long_desc <<-LONGDESC
143
180
 
144
181
  Generate Amazon CloudFormation JSON file for <yaml_file> using
145
- <template_name> in ':template_path' -direcotory.
182
+ <template_name> in ':template_path' -directory.
146
183
 
147
184
  <template_name> defaults to '#{DEAFAULT_TEMPLATE}'
148
185
 
@@ -151,11 +188,60 @@ LONGDESC
151
188
 
152
189
  def gen( yaml_file, template_name=DEAFAULT_TEMPLATE )
153
190
 
154
- app = ::AwsMust::AwsMust.new( options )
155
- app.generate( template_name, yaml_file, options )
191
+ my_options = option_adjust_common( options )
192
+
193
+ app = ::AwsMust::AwsMust.new( my_options )
194
+ app.generate( template_name, yaml_file, my_options )
156
195
 
157
196
  end
158
197
 
198
+ # ------------------------------------------------------------------
199
+ # common routines
200
+ no_commands do
201
+
202
+ def option_adjust_common( options )
203
+
204
+ raise "No optios give" unless options
205
+ ret = options
206
+ ret = option_template_gem_to_template_path( options ) if options[:template_gem]
207
+
208
+ return ret
209
+ end
210
+
211
+
212
+ def option_template_gem_to_template_path( options )
213
+
214
+ # The version requirements are optional.
215
+ # You can also specify multiple version requirements, just append more at the end
216
+ gem_spec = options[:template_gem].split(',')
217
+ gem_name, *gem_ver_reqs = gem_spec[0], gem_spec[1]
218
+ gdep = Gem::Dependency.new(gem_name, *gem_ver_reqs)
219
+ # find latest that satisifies
220
+ found_gspec = gdep.matching_specs.sort_by(&:version).last
221
+ # instead of using Gem::Dependency, you can also do:
222
+ # Gem::Specification.find_all_by_name(gem_name, *gem_ver_reqs)
223
+
224
+ if found_gspec
225
+ # unfreeze options
226
+ @logger.debug( "#{__FILE__}.#{__method__}, Requirement '#{gdep}' already satisfied by #{found_gspec.name}-#{found_gspec.version}" )
227
+ @logger.debug( "#{__FILE__}.#{__method__}, old-options=#{options}" )
228
+ options = options.dup
229
+ options[:template_path] = "#{found_gspec.gem_dir}/mustache"
230
+ @logger.debug( "#{__FILE__}.#{__method__}, new-options=#{options}" )
231
+ else
232
+ #puts "Requirement '#{gdep}' not satisfied; installing..."
233
+ # ver_args = gdep.requirements_list.map{|s| ['-v', s] }.flatten
234
+ # # multi-arg is safer, to avoid injection attacks
235
+ # system('gem', 'install', gem_name, *ver_args)
236
+ raise "Could not find gem '#{gdep}' - try 'gem install #{gdep}'"
237
+ end
238
+
239
+ return options
240
+
241
+ end
242
+
243
+ end # no commands
244
+
159
245
  end
160
246
 
161
247
  App.start
data/demo/0/root.mustache CHANGED
@@ -1,3 +1,8 @@
1
+ {{!
2
+ +++start+++
3
+ Demo 0
4
+ +++close+++
5
+ }}
1
6
  {
2
7
  "AWSTemplateFormatVersion" : "2010-09-09",
3
8
  "Description" : "A simple Amazon EC2 instance. Initial copy",
@@ -1,6 +1,7 @@
1
1
  {{!
2
2
 
3
- ++start++
3
+ +++start+++
4
+
4
5
 
5
6
  <style>
6
7
  h1 {
@@ -66,7 +67,7 @@ each template, it
66
67
  * **Description**: `description`
67
68
 
68
69
 
69
- ++close++
70
+ +++close+++
70
71
 
71
72
  }}
72
73
 
data/demo/5/root.mustache CHANGED
@@ -176,7 +176,6 @@ INCLUDED templates
176
176
  > resources
177
177
  > resource
178
178
  > resourceInstance
179
- > resourceSecurityGroup
180
179
  > output
181
180
 
182
181
  +++close+++
data/lib/tasks/demo.rake CHANGED
@@ -19,7 +19,7 @@ namespace "demo" do |ns|
19
19
 
20
20
  all_regions= ["ap-northeast-1", "ap-southeast-1", "ap-southeast-2", "cn-north-1", "eu-central-1", "eu-west-1", "sa-east-1", "us-east-1", "us-gov-west-1", "us-west-1", "us-west-2"]
21
21
 
22
- [
22
+ demos = [
23
23
 
24
24
  { :id => "1", :desc=>"Initial copy", :region=>['eu-central-1'], :ssh => false },
25
25
  { :id => "2", :desc=>"Added 'description' property, Use resources.mustache -partial", :region=>['eu-central-1'], :ssh => false },
@@ -29,8 +29,9 @@ namespace "demo" do |ns|
29
29
  { :id => "6", :desc=>"Create security group, and EC2 instances", :region=>all_regions, :ssh => true },
30
30
  { :id => "7", :desc=>"Add support for installing Chef", :region=>all_regions, :ssh => true },
31
31
 
32
+ ]
32
33
 
33
- ].each do |c|
34
+ demos.each do |c|
34
35
 
35
36
  desc "Output CF template using configs in '#{demo_dir}/#{c[:id]}' to demonstrate '#{c[:desc]}'"
36
37
  task "template-#{c[:id]}" do
@@ -60,12 +61,22 @@ namespace "demo" do |ns|
60
61
  sh "aws cloudformation create-stack --stack-name #{stack} --template-body \"$(#{cmd} gen -t #{demo_dir}/#{c[:id]} #{demo_dir}/#{c[:id]}/conf.yaml)\""
61
62
  end
62
63
 
63
- desc "Open html documentation in 'browser' (default 'firefox')"
64
+ desc "Output html documentation for demo case #{c[:id]} to STDOUT"
65
+ task "doc-#{c[:id]}" do |t,args|
66
+ # sh "#{cmd} doc -t #{demo_dir}/#{c[:id]} | markdown"
67
+ sh html_doc_to_stdout( cmd, demo_dir, c )
68
+ end
69
+
70
+
71
+ desc "Open html documentation for demo case #{c[:id]} in 'browser' (default 'firefox')"
64
72
  task "html-#{c[:id]}", :browser do |t,args|
65
73
 
66
74
  args.with_defaults( browser: "firefox" )
67
75
 
68
- sh "#{cmd} doc -t #{demo_dir}/#{c[:id]} | markdown | #{args.browser} \"data:text/html;base64,$(base64 -w 0 <&0)\""
76
+ # sh "#{cmd} doc -t #{demo_dir}/#{c[:id]} | markdown | #{args.browser} \"data:text/html;base64,$(base64 -w 0 <&0)\""
77
+ sh "#{html_doc_to_stdout( cmd, demo_dir, c )} | #{args.browser} \"data:text/html;base64,$(base64 -w 0 <&0)\""
78
+
79
+
69
80
  end
70
81
 
71
82
 
@@ -99,6 +110,14 @@ namespace "demo" do |ns|
99
110
  }
100
111
 
101
112
  end
113
+
114
+ # ------------------------------------------------------------------
115
+ # common methods
116
+
117
+ # sh-commnand pipelito to create mardown documentation for demo case c[:id]
118
+ def html_doc_to_stdout( cmd, demo_dir, c )
119
+ return "#{cmd} doc -t #{demo_dir}/#{c[:id]} | markdown"
120
+ end
102
121
 
103
122
 
104
123
  end
@@ -0,0 +1,18 @@
1
+ {{! This is default template root.mustache
2
+
3
+ +++start+++
4
+
5
+ Text between start/close tags is outputted verbatim to standard output.
6
+
7
+ +++close+++
8
+
9
+ }}
10
+
11
+ {{! +++fold-on+++ }}
12
+
13
+ Text between fold-on/fold-off tags is surrounded by string set by
14
+ options 'fold_on' and 'fold_off'.
15
+
16
+ Create your own template in file `mustache/root.mustache`
17
+
18
+ {{! +++fold-off+++ }}
metadata CHANGED
@@ -1,29 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-must
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.10
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-10 00:00:00.000000000 Z
11
+ date: 2015-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.18.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.18.1
27
41
  description: |
28
42
  aws-must is a tool, which allows separating infrastructure
29
43
  configuration and Amazon related syntax using YAML and Mustache templates
@@ -91,6 +105,7 @@ files:
91
105
  - lib/tasks/demo.rake
92
106
  - lib/utils/hasher.rb
93
107
  - lib/utils/logger.rb
108
+ - mustache/root.mustache
94
109
  homepage:
95
110
  licenses:
96
111
  - MIT
@@ -101,9 +116,9 @@ require_paths:
101
116
  - lib
102
117
  required_ruby_version: !ruby/object:Gem::Requirement
103
118
  requirements:
104
- - - ">="
119
+ - - "~>"
105
120
  - !ruby/object:Gem::Version
106
- version: '0'
121
+ version: '2'
107
122
  required_rubygems_version: !ruby/object:Gem::Requirement
108
123
  requirements:
109
124
  - - ">="