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 +4 -4
- data/bin/mkstack +13 -3
- data/lib/mkstack/section.rb +9 -2
- data/lib/mkstack/template.rb +62 -45
- data/mkstack.gemspec +11 -10
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76379b662cf2153c5c04bccd63e19388a6b9bbf34f0ae124ad4c052d0b58e6ce
|
4
|
+
data.tar.gz: ed67ba1d7d95e334ce57b57565b4eee3e0b54b65d18e7dbd5ac9dfbe14dbd416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/mkstack/section.rb
CHANGED
@@ -17,9 +17,16 @@ module MkStack
|
|
17
17
|
|
18
18
|
# Merge or override a section snippet
|
19
19
|
def merge(contents)
|
20
|
-
|
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
|
|
data/lib/mkstack/template.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative 'section'
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
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 =
|
36
|
+
def initialize(format = 'json', argv = nil)
|
38
37
|
@format = format
|
39
38
|
|
40
39
|
@sections = {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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 =
|
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)
|
64
|
+
def [](section)
|
65
|
+
@sections[section]
|
66
|
+
end
|
65
67
|
|
66
68
|
# Return the length of the entire template
|
67
|
-
def length
|
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
|
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 =>
|
87
|
+
rescue Exception => _e
|
82
88
|
# Try YAML
|
83
89
|
add_tags
|
84
90
|
cfn = YAML.safe_load(contents, permitted_classes: [IntrinsicShort])
|
85
|
-
@format =
|
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
|
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[
|
107
|
+
cfn['Include'].each do |file|
|
94
108
|
Dir.chdir(File.dirname(file)) { self.merge(File.basename(file), erb) }
|
95
|
-
end if cfn[
|
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
|
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
|
125
|
+
when 'json'
|
112
126
|
to_hash.to_json
|
113
|
-
when
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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 =
|
3
|
-
s.version =
|
4
|
-
s.summary =
|
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 = [
|
10
|
-
s.email = [
|
11
|
-
s.homepage =
|
12
|
-
s.licenses = [
|
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[
|
15
|
-
s.executables = [
|
14
|
+
s.files = Dir[ 'mkstack.gemspec', 'bin/*', 'lib/**/*.rb' ]
|
15
|
+
s.executables = [ 'mkstack' ]
|
16
16
|
|
17
|
-
s.
|
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.
|
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:
|
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:
|
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.
|
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: []
|