mkstack 1.3.0 → 1.3.1

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: b7112810ff4a3c0fd827c6887c0de68adeeea9ceeb504bb4720c824f5f64915c
4
- data.tar.gz: e11529e44338a57df079a1df8fcbdc4fa12e7ca5f65be93a2fc24418c5d0081e
3
+ metadata.gz: 76379b662cf2153c5c04bccd63e19388a6b9bbf34f0ae124ad4c052d0b58e6ce
4
+ data.tar.gz: ed67ba1d7d95e334ce57b57565b4eee3e0b54b65d18e7dbd5ac9dfbe14dbd416
5
5
  SHA512:
6
- metadata.gz: cf246f85a8b801cad73e40e27ef9f44d681727c064bb51d912bd0d8ed062f2d1674869b5d989f0b515f3cd514f033f17e04fd8b58ec4c4228e90af28ad23c951
7
- data.tar.gz: 61b586cc10747994496d91fa0bd3c13f161c5a8d61c40eb7846f8a4f56696cdf1d489673f969b45ced144339db141f929cd0167ffc4c7a9907fccfe7cff09a92
6
+ metadata.gz: a595736d490a9d07e7b66188ed3a6e2932d7964665cb281759433558b3dade38e9d3c434c4c82253ecf661bb2fc2db0284a13ab9416154c28f7db7a447e56d4f
7
+ data.tar.gz: da21b87d8ef7d38102198951469ab7e7a1d98f20888677a12994efa785a5ec734f2f147861ad96a77a84cdaf8f599bb739945a06784ddb79111ec9fb5e3a7bc1
data/bin/mkstack CHANGED
@@ -4,7 +4,7 @@ require "logger"
4
4
  require "optparse"
5
5
  require_relative "../lib/mkstack"
6
6
 
7
- version = "1.2.0"
7
+ version = "1.3.1"
8
8
 
9
9
 
10
10
  ##################################################
@@ -14,7 +14,11 @@ version = "1.2.0"
14
14
  $logger = Logger.new(STDERR)
15
15
  $logger.level = Logger::WARN
16
16
  $logger.formatter = proc { |s, d, p, m|
17
- "[%s] %5s [%5s] - %s\n" % [ d.strftime("%Y-%m-%d %H:%M:%S"), s, caller(4, 1).first.split(":")[1], m ]
17
+ x = caller(4, 1)[0]
18
+ line = x.split(':')[1]
19
+ file = x.split(':')[0].split('/')[-1]
20
+ func = x.split("'")[-1]
21
+ "[%s] %5s [%-12s] [%4d] %s: %s\n" % [ d.strftime("%Y-%m-%d %H:%M:%S"), s, file, line, func, m ]
18
22
  }
19
23
 
20
24
  # Default options
@@ -110,8 +114,14 @@ end
110
114
 
111
115
  # Save template
112
116
  if options[:save] then
117
+ $logger.debug { "saving #{options[:save]}" }
118
+
113
119
  begin
114
- $stdout = File.new(options[:save], File::CREAT | File::WRONLY) unless options[:save] == "-"
120
+ unless options[:save] == '-'
121
+ f = File.new(options[:save], File::CREAT | File::WRONLY)
122
+ f.truncate(0)
123
+ $stdout = f
124
+ end
115
125
 
116
126
  $logger.info { "Saving #{template.format} to #{$stdout.path}" } unless $stdout == STDOUT
117
127
 
@@ -17,9 +17,16 @@ module MkStack
17
17
 
18
18
  # Merge or override a section snippet
19
19
  def merge(contents)
20
- raise TypeError.new("#{contents.class} != #{@contents.class}") if contents.class != @contents.class
21
-
20
+ # Hashes get merged
22
21
  return @contents.merge!(contents) if @contents.respond_to?(:merge!)
22
+
23
+ # Arrays get concatenated or pushed
24
+ if @contents.respond_to?(:push)
25
+ return @contents.concat(contents) if contents.respond_to?(:push)
26
+ return @contents.push(contents)
27
+ end
28
+
29
+ # Strings get copied
23
30
  @contents = contents
24
31
  end
25
32
 
@@ -1,8 +1,8 @@
1
- require_relative "section"
1
+ require_relative 'section'
2
2
 
3
- require "erb"
4
- require "json"
5
- require "yaml"
3
+ require 'erb'
4
+ require 'json'
5
+ require 'yaml'
6
6
 
7
7
  module MkStack
8
8
  ##################################################
@@ -14,7 +14,6 @@ module MkStack
14
14
  # just the value.
15
15
  #
16
16
  # Loading a YAML file will force the output to be in YAML format.
17
-
18
17
  class IntrinsicShort
19
18
  def init_with(coder)
20
19
  @coder = coder
@@ -34,22 +33,23 @@ module MkStack
34
33
  class Template
35
34
  attr_reader :sections, :limit, :format
36
35
 
37
- def initialize(format = "json", argv = nil)
36
+ def initialize(format = 'json', argv = nil)
38
37
  @format = format
39
38
 
40
39
  @sections = {
41
- "AWSTemplateFormatVersion" => Section.new("AWSTemplateFormatVersion", String, nil),
42
- "Description" => Section.new("Description", String, 1024),
43
-
44
- "Conditions" => Section.new("Conditions", Hash, nil),
45
- "Mappings" => Section.new("Mappings", Hash, 200),
46
- "Metadata" => Section.new("Metadata", Hash, nil),
47
- "Outputs" => Section.new("Outputs", Hash, 200),
48
- "Parameters" => Section.new("Parameters", Hash, 200),
49
- "Resources" => Section.new("Resources", Hash, 500),
50
- "Transform" => Section.new("Transform", Hash, nil),
40
+ 'AWSTemplateFormatVersion' => Section.new('AWSTemplateFormatVersion', String, nil),
41
+ 'Description' => Section.new('Description', String, 1024),
42
+
43
+ 'Conditions' => Section.new('Conditions', Hash, nil),
44
+ 'Mappings' => Section.new('Mappings', Hash, 200),
45
+ 'Metadata' => Section.new('Metadata', Hash, nil),
46
+ 'Outputs' => Section.new('Outputs', Hash, 200),
47
+ 'Parameters' => Section.new('Parameters', Hash, 200),
48
+ 'Resources' => Section.new('Resources', Hash, 500),
49
+ 'Transform' => Section.new('Transform', Array, nil),
50
+ 'Rules' => Section.new('Rules', Hash, nil),
51
51
  }
52
- @limit = 51200
52
+ @limit = 51_200
53
53
 
54
54
  # Keep track of parsed files to avoid loops
55
55
  @parsed = {}
@@ -61,13 +61,19 @@ module MkStack
61
61
  end
62
62
 
63
63
  # Shorthand accessor for template sections
64
- def [](section); @sections[section]; end
64
+ def [](section)
65
+ @sections[section]
66
+ end
65
67
 
66
68
  # Return the length of the entire template
67
- def length; to_json.to_s.length; end
69
+ def length
70
+ to_json.to_s.length
71
+ end
68
72
 
69
73
  # Check if the template exceeds the AWS limit
70
- def exceeds_limit?; limit && length > limit; end
74
+ def exceeds_limit?
75
+ limit && length > limit
76
+ end
71
77
 
72
78
 
73
79
  #########################
@@ -78,28 +84,36 @@ module MkStack
78
84
  begin
79
85
  # Try JSON
80
86
  cfn = JSON.load(contents)
81
- rescue Exception => e
87
+ rescue Exception => _e
82
88
  # Try YAML
83
89
  add_tags
84
90
  cfn = YAML.safe_load(contents, permitted_classes: [IntrinsicShort])
85
- @format = "yaml"
91
+ @format = 'yaml'
92
+ end
93
+
94
+ # Check if there were any sections
95
+ unless cfn
96
+ $logger.debug { "no content in #{file}" }
97
+ return
86
98
  end
87
99
 
88
100
  # Merge sections that are present in the file
89
- @sections.each { |name, section| section.merge(cfn[name]) if cfn[name] }
101
+ @sections.each do |name, section|
102
+ section.merge(cfn[name]) if cfn[name]
103
+ end
90
104
 
91
105
  # Look for Includes and merge them
92
106
  # Files are Included relative to the file with the Include directive
93
- cfn["Include"].each do |file|
107
+ cfn['Include'].each do |file|
94
108
  Dir.chdir(File.dirname(file)) { self.merge(File.basename(file), erb) }
95
- end if cfn["Include"]
109
+ end if cfn['Include']
96
110
  end
97
111
 
98
112
 
99
113
  #########################
100
114
  # Call ValidateTemplate[https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_ValidateTemplate.html]
101
115
  def validate
102
- require "aws-sdk-cloudformation"
116
+ require 'aws-sdk-cloudformation'
103
117
  Aws::CloudFormation::Client.new.validate_template({ template_body: pp })
104
118
  end
105
119
 
@@ -108,9 +122,9 @@ module MkStack
108
122
  # Format contents
109
123
  def pp
110
124
  case @format
111
- when "json"
125
+ when 'json'
112
126
  to_hash.to_json
113
- when "yaml"
127
+ when 'yaml'
114
128
  to_hash.to_yaml({ line_width: -1 }) # Keep Psych from splitting "long" lines
115
129
  else
116
130
  to_hash
@@ -149,23 +163,26 @@ module MkStack
149
163
  # List of intrinsic functions that look like undefined local tags
150
164
  def add_tags
151
165
  [
152
- "Base64",
153
- "Cidr",
154
- "FindInMap",
155
- "GetAtt",
156
- "GetAZs",
157
- "ImportValue",
158
- "Join",
159
- "Ref",
160
- "Select",
161
- "Split",
162
- "Transform",
163
- "And",
164
- "Equals",
165
- "If",
166
- "Not",
167
- "Or",
168
- "Sub",
166
+ 'Base64',
167
+ 'Cidr',
168
+ 'FindInMap',
169
+ 'ForEach',
170
+ 'GetAtt',
171
+ 'GetAZs',
172
+ 'ImportValue',
173
+ 'Join',
174
+ 'Length',
175
+ 'Ref',
176
+ 'Select',
177
+ 'Split',
178
+ 'ToJsonString',
179
+ 'Transform',
180
+ 'And',
181
+ 'Equals',
182
+ 'If',
183
+ 'Not',
184
+ 'Or',
185
+ 'Sub',
169
186
  ].each do |function|
170
187
  YAML::add_tag("!#{function}", IntrinsicShort)
171
188
  end
data/mkstack.gemspec CHANGED
@@ -1,18 +1,19 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = "mkstack"
3
- s.version = "1.3.0"
4
- s.summary = "Merge multiple CloudFormation template files into a single template"
2
+ s.name = 'mkstack'
3
+ s.version = '1.3.1'
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.
7
7
  EOF
8
8
 
9
- s.authors = [ "Andy Rosen" ]
10
- s.email = [ "ajr@corp.mlfs.org" ]
11
- s.homepage = "https://github.com/ajrosen/AWS/tree/master/mkstack"
12
- s.licenses = [ "GPL-3.0+" ]
9
+ s.authors = [ 'Andy Rosen' ]
10
+ s.email = [ 'ajr@corp.mlfs.org' ]
11
+ s.homepage = 'https://github.com/ajrosen/AWS/tree/master/mkstack'
12
+ s.licenses = [ 'GPL-3.0-or-later' ]
13
13
 
14
- s.files = Dir[ "mkstack.gemspec", "bin/*", "lib/**/*.rb" ]
15
- s.executables = [ "mkstack" ]
14
+ s.files = Dir[ 'mkstack.gemspec', 'bin/*', 'lib/**/*.rb' ]
15
+ s.executables = [ 'mkstack' ]
16
16
 
17
- s.add_runtime_dependency "aws-sdk-cloudformation", "~> 1"
17
+ s.required_ruby_version = '>= 2.6.0'
18
+ s.add_runtime_dependency 'aws-sdk-cloudformation', '~> 1'
18
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Rosen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2025-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudformation
@@ -28,7 +28,7 @@ description: 'Merge multiple CloudFormation template files into a single templat
28
28
  file may be in either JSON or YAML format. By default all files are run through
29
29
  an ERB (Embedded RuBy) processor.
30
30
 
31
- '
31
+ '
32
32
  email:
33
33
  - ajr@corp.mlfs.org
34
34
  executables:
@@ -43,9 +43,9 @@ files:
43
43
  - mkstack.gemspec
44
44
  homepage: https://github.com/ajrosen/AWS/tree/master/mkstack
45
45
  licenses:
46
- - GPL-3.0+
46
+ - GPL-3.0-or-later
47
47
  metadata: {}
48
- post_install_message:
48
+ post_install_message:
49
49
  rdoc_options: []
50
50
  require_paths:
51
51
  - lib
@@ -53,15 +53,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '0'
56
+ version: 2.6.0
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.5.11
64
- signing_key:
63
+ rubygems_version: 3.4.15
64
+ signing_key:
65
65
  specification_version: 4
66
66
  summary: Merge multiple CloudFormation template files into a single template
67
67
  test_files: []