mkstack 1.1.3 → 1.2.0

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
  SHA256:
3
- metadata.gz: e5d37d2a94286016bc2fe971108aa2c9c9209cdc4492d648ce2f74627d4a3771
4
- data.tar.gz: 571c7b9744eda12ba9e03f431dd6869949ef6f3c52d9b0fa06bc752631e782db
3
+ metadata.gz: 322eccfead31ad6c826aec54f1e7318895bf083846583c049131e0f07c7cbe23
4
+ data.tar.gz: 0a91db392b235136cf72837d971cd933f15af793a984cb3ff07401431f4e7248
5
5
  SHA512:
6
- metadata.gz: f69c72b6898c770d866cb6fc2be8b073eff0009cd91b6aea6eb36950c989412862a084f0f703b7bfa9e596a448a8ffe319af13a0112f1cb2006c2c6f43567d03
7
- data.tar.gz: 1e8918f652e058070760b73db832b902a3680701e96eb6470b3f6cfc7c8cb0bc7eb70ca23642fe331fa59c02c51a3fca39017aaf59dba3b8d64c266afd919d65
6
+ metadata.gz: dc047d7381bfcc86076eda6ae58de7b4b04a7e61cb29248530d2e13d7c353c3eac5925b2c381383c561d3eb530c190de46fa35ae4bfb38dce7e966667ca3591d
7
+ data.tar.gz: c3393240e63e337ce4ef643ca9df68949678ddfb64a118d3647d68eb6c60cdcc90ce40898440e3f5f7790a98bc5e2db4d0b20f807bf648c4ecade270ee1a8017
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,8 +1,10 @@
1
- #!/usr/local/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require "logger"
4
4
  require "optparse"
5
- require "mkstack"
5
+ require_relative "../lib/mkstack"
6
+
7
+ version = "1.2.0"
6
8
 
7
9
 
8
10
  ##################################################
@@ -29,6 +31,7 @@ opts = OptionParser.new do |p|
29
31
 
30
32
  # Help
31
33
  p.on("-h", "--help", "Display this message") { puts opts ; exit }
34
+ p.on("--version", "Show version") { puts version ; exit }
32
35
  p.separator(" ")
33
36
 
34
37
  # Verbosity
@@ -75,7 +78,6 @@ template = MkStack::Template.new(options[:format], options[:erb_argv])
75
78
  files.each do |file|
76
79
  begin
77
80
  Dir.chdir(File.dirname(file)) {
78
- $logger.info { "Loading #{file}" }
79
81
  template.merge(File.basename(file), options[:erb])
80
82
  }
81
83
  rescue KeyError => e
@@ -5,6 +5,30 @@ require "json"
5
5
  require "yaml"
6
6
 
7
7
  module MkStack
8
+ ##################################################
9
+ # A class to represent undefined local tags.
10
+ #
11
+ # CloudFormation uses <b>!</b> to denote the YAML short form of
12
+ # intrinsic functions, which is the same prefix YAML uses for local
13
+ # tags. The default handler strips undefined local tags, leaving
14
+ # just the value.
15
+ #
16
+ # Loading a YAML file will force the output to be in YAML format.
17
+
18
+ class IntrinsicShort
19
+ def init_with(coder)
20
+ @coder = coder
21
+ end
22
+
23
+ def encode_with(coder)
24
+ coder.tag = @coder.tag
25
+
26
+ coder.map = @coder.map if @coder.type == :map
27
+ coder.scalar = @coder.scalar if @coder.type == :scalar
28
+ coder.seq = @coder.seq if @coder.type == :seq
29
+ end
30
+ end
31
+
8
32
  ##################################################
9
33
  # A CloudFormation template
10
34
  class Template
@@ -34,10 +58,6 @@ module MkStack
34
58
  # every time we load a file. This allows ERB code in one file to
35
59
  # be referenced in another.
36
60
  @binding = binding
37
-
38
- # See add_domain_types
39
- @yaml_domain = "mlfs.org,2020"
40
- @global_tag = "tag:#{@yaml_domain}:"
41
61
  end
42
62
 
43
63
  # Shorthand accessor for template sections
@@ -60,8 +80,9 @@ module MkStack
60
80
  cfn = JSON.load(contents)
61
81
  rescue Exception => e
62
82
  # Try YAML
63
- add_domain_types
64
- cfn = YAML.load(contents)
83
+ add_tags
84
+ cfn = YAML.safe_load(contents, [IntrinsicShort])
85
+ @format = "yaml"
65
86
  end
66
87
 
67
88
  # Merge sections that are present in the file
@@ -90,9 +111,7 @@ module MkStack
90
111
  when "json"
91
112
  to_hash.to_json
92
113
  when "yaml"
93
- # Strip enclosing quotes around tags and revert tags to their short form
94
- # And keep Psych from splitting "long" lines
95
- to_hash.to_yaml({ line_width: -1 }).gsub(/"(#{@global_tag}[^"]+?)"/, '\1').gsub("#{@global_tag}", "!")
114
+ to_hash.to_yaml({ line_width: -1 }) # Keep Psych from splitting "long" lines
96
115
  else
97
116
  to_hash
98
117
  end
@@ -127,20 +146,9 @@ module MkStack
127
146
 
128
147
 
129
148
  #########################
130
- # Define YAML domains to handle CloudFormation intrinsic
131
- # functions.
132
- #
133
- # CloudFormation uses <b>!</b> to denote the YAML short form of
134
- # intrinsic functions, which is the same prefix YAML uses for
135
- # local tags. The default handler strips undefined local tags,
136
- # leaving just the value.
137
- #
138
- # This puts the tags back, but in global tag format. The global
139
- # tag prefix is converted back to <b>!</b> on output.
140
- #
141
- # Using the short form will force the output to be in YAML format.
142
- def add_domain_types
143
- functions = [
149
+ # List of intrinsic functions that look like undefined local tags
150
+ def add_tags
151
+ [
144
152
  "Base64",
145
153
  "Cidr",
146
154
  "FindInMap",
@@ -159,14 +167,7 @@ module MkStack
159
167
  "Or",
160
168
  "Sub",
161
169
  ].each do |function|
162
- YAML::add_domain_type(@yaml_domain, function) do |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}"
169
- end
170
+ YAML::add_tag("!#{function}", IntrinsicShort)
170
171
  end
171
172
  end
172
173
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "mkstack"
3
- s.version = "1.1.3"
3
+ s.version = "1.2.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.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rosen
@@ -33,7 +33,7 @@ cert_chain:
33
33
  kLyoFawGT9fF6+lXyIT9XiaUzOCjQUJo94on5U601Y2GXB4Sa1oxLSBlEtkSwuD3
34
34
  gMHlHdBRvoJurkVzYNWkN+Cz
35
35
  -----END CERTIFICATE-----
36
- date: 2020-08-19 00:00:00.000000000 Z
36
+ date: 2020-09-01 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: aws-sdk-cloudformation
metadata.gz.sig CHANGED
Binary file