mkstack 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: aa22c1f1c57234678eefa866bc219909dc00334d91d6d4daf70be9762233d51c
4
- data.tar.gz: c5a1f8095d6b34d467fafd443fbc9605b206a42ef70e65f47ec9290ed8783ca3
3
+ metadata.gz: aaf1a841fa0de51efa15c58884b99939a940d2c1bf2e87873d8b3e63d2a1ff6b
4
+ data.tar.gz: 7241af85e09c860e3bd5c105a7ec0e8dea22a9614d4b8a3d21aac72288abb26c
5
5
  SHA512:
6
- metadata.gz: b0a0588f47fbc38f7efddb0175afbfacb7d40604a41094a9bc705a26fc6edc154c00bc9f2146e1a19d3326d1d7bfdbb2a6f2de9918a5f8a67ca11e06e202d286
7
- data.tar.gz: b23350d9abe01bb969d9dbf617d7025f5572481e526b37a7632a6ec8fb46c7a64aebb92266166105bfd55ffd73f5187b642620d04bdf4ede746ceeb99bf696ee
6
+ metadata.gz: 5bd88c3603c614382a10fbcb1009704b661afe89f3553162c4a2a0b4e04494f82c9cb025eada3451c65d93a981ad2161d14d0ea50f89ab40bc0d6451b8a4a4fd
7
+ data.tar.gz: e90035e6ab6a9f37f6b9b8837efbc349e391f24c3d03e2a9c4179314e7c294e7243705f580a8425240ed9b4ec98280a2a5d05954a6969772f19d30b1d87bd710
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -15,12 +15,11 @@ $logger.formatter = proc { |s, d, p, m|
15
15
  "[%s] %5s [%5s] - %s\n" % [ d.strftime("%Y-%m-%d %H:%M:%S"), s, caller(4, 1).first.split(":")[1], m ]
16
16
  }
17
17
 
18
-
19
18
  # Default options
20
19
  options = {}
21
20
  options[:erb] = true
22
21
  options[:format] = "json"
23
-
22
+ options[:erb_argv] = []
24
23
 
25
24
  # Command line options
26
25
  opts = OptionParser.new do |p|
@@ -36,7 +35,7 @@ opts = OptionParser.new do |p|
36
35
  p.on("-d", "--debug", "Show debug messages") { $logger.level = Logger::DEBUG }
37
36
  p.on("-v", "--verbose", "Be verbose") { $logger.level = Logger::INFO }
38
37
  p.on("-q", "--quiet", "Only show errors") { $logger.level = Logger::ERROR }
39
- p.on("-s", "--silient", "Don't show any log messages") { $logger.level = Logger::FATAL }
38
+ p.on("-s", "--silent", "Don't show any log messages") { $logger.level = Logger::FATAL }
40
39
  p.separator(" ")
41
40
 
42
41
  # Output
@@ -49,18 +48,36 @@ opts = OptionParser.new do |p|
49
48
  # Operations
50
49
  p.on("--erb", "--[no-]erb", "Perform ERB processing (default is true)") { |x| options[:erb] = x }
51
50
  p.on("--validate", "Call ValidateTemplate after merging") { options[:validate] = true }
51
+ p.separator(" ")
52
+
53
+ # ERB options
54
+ p.on("---", "Marks end of mkstack options") { p.terminate("---") }
55
+ p.on("%s Remaining arguments are available to ERB as an Array argv" % [ desc_padding ])
52
56
  end
53
57
 
54
- files = opts.parse!.uniq
55
- opts.parse "--help" if files.count == 0
58
+ # Separate files from ERB arguments
59
+ args = opts.parse!
56
60
 
57
- template = MkStack::Template.new(options[:format])
61
+ if args.index("---")
62
+ files = args[0..(args.index("---") - 1)]
63
+ options[:erb_argv] = args[(args.index("---") + 1)..]
64
+ else
65
+ files = args
66
+ end
58
67
 
68
+ # At least one file is required
69
+ files.uniq!
70
+ opts.parse "--help" if ((files.count == 0) or (files[0].eql?("---")))
59
71
 
60
72
  # Merge files
73
+ template = MkStack::Template.new(options[:format], options[:erb_argv])
74
+
61
75
  files.each do |file|
62
76
  begin
63
- Dir.chdir(File.dirname(file)) { template.merge(File.basename(file), options[:erb]) }
77
+ Dir.chdir(File.dirname(file)) {
78
+ $logger.info { "Loading #{file}" }
79
+ template.merge(File.basename(file), options[:erb])
80
+ }
64
81
  rescue KeyError => e
65
82
  $logger.warn { "#{file}: already parsed" }
66
83
  rescue Exception => e
@@ -68,7 +85,6 @@ files.each do |file|
68
85
  end
69
86
  end
70
87
 
71
-
72
88
  # Check limits
73
89
  $logger.debug { "Checking limits" }
74
90
 
@@ -79,19 +95,17 @@ end
79
95
  $logger.warn { "At least one Resources member must be defined" } if template["Resources"].length == 0
80
96
  $logger.warn { "Template too large (#{template.length} > #{template.limit})" } if template.exceeds_limit?
81
97
 
82
-
83
98
  # Validate template
84
99
  if options[:validate] then
85
100
  begin
86
101
  $logger.info { "Validating #{template.format} template" }
87
102
 
88
- $logger.debug { template.validate }
103
+ template.validate
89
104
  rescue Exception => e
90
105
  $logger.error { e.message }
91
106
  end
92
107
  end
93
108
 
94
-
95
109
  # Save template
96
110
  if options[:save] then
97
111
  begin
@@ -71,6 +71,19 @@ tags defined in one file to be referenced in subsequent files.
71
71
 
72
72
  Note that foo.yaml is processed <i>before</i> bar.json.
73
73
 
74
+ == Passing arguments to ERB
75
+
76
+ Any command line arguments following "---" are added to an Array
77
+ called <b>argv</b>, which can be referenced in your ERB code.
78
+
79
+ === foo.yaml
80
+
81
+ <% puts "#{argv.class} with #{argv.length} items: #{argv}" %>
82
+
83
+ $ mkstack foo.yaml --- a 2 test
84
+
85
+ Array with 3 items: ["a", "2", "test"]
86
+
74
87
  == See Also
75
88
 
76
89
  MkStack::Template
@@ -10,20 +10,20 @@ module MkStack
10
10
  class Template
11
11
  attr_reader :sections, :limit, :format
12
12
 
13
- def initialize(format = "json")
13
+ def initialize(format = "json", argv = nil)
14
14
  @format = format
15
15
 
16
16
  @sections = {
17
17
  "AWSTemplateFormatVersion" => Section.new("AWSTemplateFormatVersion", String, nil),
18
18
  "Description" => Section.new("Description", String, 1024),
19
19
 
20
- "Conditions" => Section.new("Conditions", Hash, nil),
21
- "Mappings" => Section.new("Mappings", Hash, 100),
22
- "Metadata" => Section.new("Metadata", Hash, nil),
23
- "Outputs" => Section.new("Outputs", Hash, 60),
24
- "Parameters" => Section.new("Parameters", Hash, 60),
25
- "Resources" => Section.new("Resources", Hash, nil),
26
- "Transforms" => Section.new("Transforms", Hash, nil),
20
+ "Conditions" => Section.new("Conditions", Hash, nil),
21
+ "Mappings" => Section.new("Mappings", Hash, 100),
22
+ "Metadata" => Section.new("Metadata", Hash, nil),
23
+ "Outputs" => Section.new("Outputs", Hash, 60),
24
+ "Parameters" => Section.new("Parameters", Hash, 60),
25
+ "Resources" => Section.new("Resources", Hash, nil),
26
+ "Transform" => Section.new("Transform", Hash, nil),
27
27
  }
28
28
  @limit = 51200
29
29
 
@@ -36,7 +36,7 @@ module MkStack
36
36
  @binding = binding
37
37
 
38
38
  # See add_domain_types
39
- @yaml_domain = "mlfs.org,2019"
39
+ @yaml_domain = "mlfs.org,2020"
40
40
  @global_tag = "tag:#{@yaml_domain}:"
41
41
  end
42
42
 
@@ -157,20 +157,15 @@ module MkStack
157
157
  "If",
158
158
  "Not",
159
159
  "Or",
160
- ].each do |function|
161
- YAML::add_domain_type(@yaml_domain, function) do |type, val|
162
- @format = "yaml"
163
- "#{type} #{val}"
164
- end
165
- end
166
-
167
- # The syntax for !Sub requires double-quotes around Strings
168
- functions = [
169
160
  "Sub",
170
161
  ].each do |function|
171
162
  YAML::add_domain_type(@yaml_domain, function) do |type, val|
172
- @format = "yaml"
173
- val.is_a?(String)? "#{type} \"#{val}\"" : "#{type} #{val}"
163
+ unless @format.eql?("yaml")
164
+ $logger.debug "Setting output to YAML for short form intrinsic function !#{function}"
165
+ @format = "yaml"
166
+ end
167
+
168
+ (function.eql?("Sub") and val.is_a?(String))? "#{type} \"#{val}\"" : "#{type} #{val}"
174
169
  end
175
170
  end
176
171
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "mkstack"
3
- s.version = "1.0.0"
3
+ s.version = "1.1.0"
4
4
  s.summary = "Merge multiple CloudFormation template files into a single template"
5
5
  s.description = <<-EOF
6
6
  Merge multiple CloudFormation template files into a single template. Each file may be in either JSON or YAML format. By default all files are run through an ERB (Embedded RuBy) processor.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rosen
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEOjCCAqKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBphanIv
14
- REM9Y29ycC9EQz1tbGZzL0RDPW9yZzAeFw0xOTA1MDEwMjIwNTBaFw0yMDA0MzAw
15
- MjIwNTBaMCUxIzAhBgNVBAMMGmFqci9EQz1jb3JwL0RDPW1sZnMvREM9b3JnMIIB
13
+ MIID/jCCAmagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBphanIv
14
+ REM9Y29ycC9EQz1tbGZzL0RDPW9yZzAeFw0yMDA2MjMyMjA0MDdaFw0yMTA2MjMy
15
+ MjA0MDdaMCUxIzAhBgNVBAMMGmFqci9EQz1jb3JwL0RDPW1sZnMvREM9b3JnMIIB
16
16
  ojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAqQ2xCUJ4wY8WujSzYd3OGTbj
17
17
  JDMeU44pXOTLc49Rs8ydukGfd0YBvYMzifmiVRj6depGx2+Ln28Y2mT6IB+zHq8X
18
18
  s1lrMdFCReztJjQ7OYS16YcZ6pmLkYClnHN3VNqayk1lQEJGCr8aawMeroSB01om
@@ -21,20 +21,19 @@ cert_chain:
21
21
  JbnFW7mFQGtBpfh8zY8OCQ76Aw8cb5bEIPTI+Hd4FoJLPKnexTI28endSLigOUCF
22
22
  76kLOiVOVOjdqZ8vEdSgWVugEAzIC30xW5b8yD6N7GdT7n3ktgoZu7jZMUW3D6PQ
23
23
  wS6BaABVsXbeVtFrzK2tQ65EwLfRluRLTfbnQ7qvMIYCwC3Ib9DTMLavCiOot1vc
24
- RBWXIrDex0tt3EN0dDIxP9O+7ciDg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eHDpzcVpGkHBGYCPkLBPyjMkRwlZpgth9DVO7FP3mV9SMHyP
29
+ x1/55FYk0A62NgXSzmLghePC+trYllv54YURP4/R8RYnZPZNf5MFMjF94BoWGFzQ
30
+ 9BKJ+1DbdAVwCMSWEcGOkw5euwofwf6PpvLlmhB9pM+acsjLJkaS/OU7v5/X0F6+
31
+ MkYSejwDmyV9/u/cPgStxlOOu4x7Ur2qOzfb8OEKMmautB7ZEdCivdG/Qa634dDq
32
+ dnrb3iC4VliJf0o5SVrYjRxBYn9WQV1eJaygRunfhVo9AqRPg+rcbkQ/XIWUQDeY
33
+ kLyoFawGT9fF6+lXyIT9XiaUzOCjQUJo94on5U601Y2GXB4Sa1oxLSBlEtkSwuD3
34
+ gMHlHdBRvoJurkVzYNWkN+Cz
36
35
  -----END CERTIFICATE-----
37
- date: 2019-05-02 00:00:00.000000000 Z
36
+ date: 2020-06-23 00:00:00.000000000 Z
38
37
  dependencies:
39
38
  - !ruby/object:Gem::Dependency
40
39
  name: aws-sdk-cloudformation
@@ -86,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
85
  - !ruby/object:Gem::Version
87
86
  version: '0'
88
87
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.7.6
88
+ rubygems_version: 3.0.3
91
89
  signing_key:
92
90
  specification_version: 4
93
91
  summary: Merge multiple CloudFormation template files into a single template
metadata.gz.sig CHANGED
Binary file