mkstack 1.2.1 → 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: 156c6f1b2ce583f7723c9943105e5a56b27959cad2dcd3cab914065806d5371b
4
- data.tar.gz: d994eee79d71b74e2a635059ed1a4ba47cf93d518e3606421a567f6b92bd53ff
3
+ metadata.gz: 76379b662cf2153c5c04bccd63e19388a6b9bbf34f0ae124ad4c052d0b58e6ce
4
+ data.tar.gz: ed67ba1d7d95e334ce57b57565b4eee3e0b54b65d18e7dbd5ac9dfbe14dbd416
5
5
  SHA512:
6
- metadata.gz: ab4040c5feb8d08e926c58c36ffc9c6f7f70f17c433992cfbb4b227cabf03802ad1f0139fde972847037bf466877f5d6a212f44136e4aa7709135345c7c34550
7
- data.tar.gz: f09c970148652460c653672016f60f97feae0df146fa487be7d942ea7f98a8470ed4af47467b864b020bc19d0ef42df65295377cc0ee61bf0aa0563e6cb6f61b
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
- cfn = YAML.safe_load(contents, [IntrinsicShort])
85
- @format = "yaml"
90
+ cfn = YAML.safe_load(contents, permitted_classes: [IntrinsicShort])
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.2.1"
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,39 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
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
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIID/jCCAmagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBphanIv
14
- REM9Y29ycC9EQz1tbGZzL0RDPW9yZzAeFw0yMDA2MjMyMjA0MDdaFw0yMTA2MjMy
15
- MjA0MDdaMCUxIzAhBgNVBAMMGmFqci9EQz1jb3JwL0RDPW1sZnMvREM9b3JnMIIB
16
- ojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAqQ2xCUJ4wY8WujSzYd3OGTbj
17
- JDMeU44pXOTLc49Rs8ydukGfd0YBvYMzifmiVRj6depGx2+Ln28Y2mT6IB+zHq8X
18
- s1lrMdFCReztJjQ7OYS16YcZ6pmLkYClnHN3VNqayk1lQEJGCr8aawMeroSB01om
19
- d5wqDATnKEG3x4bnlxFJb3LHzUG1CgNuVCuNREi8zN/uYdm2MGe1fTJguy4/vzBQ
20
- /FnAMt1mr3LtM6YZRGaitIlOKBV/08v7fjH31KRmSMMHPq6A+WyWKRNKnK3tHpSN
21
- JbnFW7mFQGtBpfh8zY8OCQ76Aw8cb5bEIPTI+Hd4FoJLPKnexTI28endSLigOUCF
22
- 76kLOiVOVOjdqZ8vEdSgWVugEAzIC30xW5b8yD6N7GdT7n3ktgoZu7jZMUW3D6PQ
23
- wS6BaABVsXbeVtFrzK2tQ65EwLfRluRLTfbnQ7qvMIYCwC3Ib9DTMLavCiOot1vc
24
- RBWXIrDex0tt3EN0dDIxP9O+7ciDgM4zPe6BvaF/AgMBAAGjOTA3MAkGA1UdEwQC
25
- MAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBRDowzw+kmcX6FV7T9BkQsUgmzLZjAN
26
- BgkqhkiG9w0BAQsFAAOCAYEAAmnuLwfJOuo9JlIMPCArwX0wIZcuKJ1Ms5S9RpTT
27
- MYqNwa52//SCZ5VG0bZknXNgHGs1qm4kHekxOVjjjdawVHQFZvDJJxblSvj1OTe0
28
- J4OF7hiWldeUE7ezeHDpzcVpGkHBGYCPkLBPyjMkRwlZpgth9DVO7FP3mV9SMHyP
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
35
- -----END CERTIFICATE-----
36
- date: 2020-10-23 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2025-05-09 00:00:00.000000000 Z
37
12
  dependencies:
38
13
  - !ruby/object:Gem::Dependency
39
14
  name: aws-sdk-cloudformation
@@ -53,7 +28,7 @@ description: 'Merge multiple CloudFormation template files into a single templat
53
28
  file may be in either JSON or YAML format. By default all files are run through
54
29
  an ERB (Embedded RuBy) processor.
55
30
 
56
- '
31
+ '
57
32
  email:
58
33
  - ajr@corp.mlfs.org
59
34
  executables:
@@ -68,9 +43,9 @@ files:
68
43
  - mkstack.gemspec
69
44
  homepage: https://github.com/ajrosen/AWS/tree/master/mkstack
70
45
  licenses:
71
- - GPL-3.0+
46
+ - GPL-3.0-or-later
72
47
  metadata: {}
73
- post_install_message:
48
+ post_install_message:
74
49
  rdoc_options: []
75
50
  require_paths:
76
51
  - lib
@@ -78,15 +53,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
53
  requirements:
79
54
  - - ">="
80
55
  - !ruby/object:Gem::Version
81
- version: '0'
56
+ version: 2.6.0
82
57
  required_rubygems_version: !ruby/object:Gem::Requirement
83
58
  requirements:
84
59
  - - ">="
85
60
  - !ruby/object:Gem::Version
86
61
  version: '0'
87
62
  requirements: []
88
- rubygems_version: 3.1.4
89
- signing_key:
63
+ rubygems_version: 3.4.15
64
+ signing_key:
90
65
  specification_version: 4
91
66
  summary: Merge multiple CloudFormation template files into a single template
92
67
  test_files: []
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file