cloud_compose 0.1.1 → 0.3.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 +4 -4
- data/README.md +50 -1
- data/exe/cloud-compose +22 -9
- data/lib/cloud_compose/builtin/iam_console_user.yml +31 -0
- data/lib/cloud_compose/cli.rb +2 -0
- data/lib/cloud_compose/cli/build.rb +33 -0
- data/lib/cloud_compose/cli/print.rb +21 -0
- data/lib/cloud_compose/config.rb +1 -1
- data/lib/cloud_compose/parser.rb +4 -0
- data/lib/cloud_compose/tags/builtin.rb +32 -0
- data/lib/cloud_compose/tags/random.rb +34 -0
- data/lib/cloud_compose/template.rb +2 -4
- data/lib/cloud_compose/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac283bb55bcf40add93a3946568a01957ee43960a19fd5be45bb9c68a0d73191
|
4
|
+
data.tar.gz: 1c34ac3b7fb9170826d1f8c4a948885def05de9608a35b317d618e1ac9bd04ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a1ae8b4a4e5ef9b76c108b9c9d3325ed8e8a125018060b18f466a79b659a60d4d9cea20b037cc52d04e87b0636e94f586fba6e515a880781e1fcc6bea093a35
|
7
|
+
data.tar.gz: 591cb3e9ba60076644ef7dd61f6b23c7111f3eb7e3685cdecd0feeaff623503362da05515d5940531fc23189b9a7caec119bd1baab0034a4b4774d6572b60a14
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Compose multiple cloud formation templates into one file.
|
4
4
|
|
5
|
-
`cloud-compose ./template.yml ./output`
|
5
|
+
`cloud-compose build ./template.yml ./output`
|
6
6
|
|
7
7
|
```yaml
|
8
8
|
# template.yml
|
@@ -15,6 +15,22 @@ $cloud_compose:
|
|
15
15
|
path: ./sub_readme.yml
|
16
16
|
- name: SubTemplateTwo
|
17
17
|
path: ./sub_readme.yml
|
18
|
+
- name: DevUserOne
|
19
|
+
path: !Builtin iam_console_user.yml
|
20
|
+
parameters:
|
21
|
+
username: dev-user-one
|
22
|
+
---
|
23
|
+
|
24
|
+
Resources:
|
25
|
+
$(GlobalName)MainResource:
|
26
|
+
Type: AWS::Fake::Thing
|
27
|
+
Properties:
|
28
|
+
Name: My Main Resource
|
29
|
+
SecondaryResource:
|
30
|
+
Type: AWS::Fake::Thing
|
31
|
+
Properties:
|
32
|
+
ParentThing: !Ref $(GlobalName)MainResource
|
33
|
+
|
18
34
|
---
|
19
35
|
|
20
36
|
Resources:
|
@@ -66,9 +82,42 @@ Resources:
|
|
66
82
|
Type: AWS::Fake::Thing
|
67
83
|
Properties:
|
68
84
|
ParentThing: !Ref TestTemplateMainResource
|
85
|
+
DevUserOneUserAccount:
|
86
|
+
Type: AWS::IAM::User
|
87
|
+
Properties:
|
88
|
+
UserName: dev-user-one
|
89
|
+
ManagedPolicyArns: !Ref DevUserOneManagedPolicyArnsParameter
|
90
|
+
LoginProfile:
|
91
|
+
Password: !FindInMap
|
92
|
+
- DevUserOneUserAccount
|
93
|
+
- Password
|
94
|
+
- Value
|
95
|
+
PasswordResetRequired: true
|
96
|
+
Parameters:
|
97
|
+
DevUserOneManagedPolicyArnsParameter:
|
98
|
+
Type: CommaDelimitedList
|
99
|
+
Description: List of Managed Profile Arns.
|
100
|
+
Default: arn:aws:iam::aws:policy/ReadOnlyAccess
|
101
|
+
Mappings:
|
102
|
+
DevUserOneUserAccount:
|
103
|
+
Password:
|
104
|
+
Value: 124aa4d58a48b77b8b4397be
|
69
105
|
Outputs:
|
70
106
|
SubTemplateOneResourceOutput:
|
71
107
|
Value: !Ref SubTemplateOneResource
|
72
108
|
SubTemplateTwoResourceOutput:
|
73
109
|
Value: !Ref SubTemplateTwoResource
|
110
|
+
DevUserOneUserAccountName:
|
111
|
+
Value: !Ref DevUserOneUserAccount
|
112
|
+
DevUserOneUserAccountArn:
|
113
|
+
Value: !GetAtt
|
114
|
+
- DevUserOneUserAccount
|
115
|
+
- Arn
|
116
|
+
DevUserOneUserAccountTemporaryPassword:
|
117
|
+
Value: !FindInMap
|
118
|
+
- DevUserOneUserAccount
|
119
|
+
- Password
|
120
|
+
- Value
|
121
|
+
|
122
|
+
|
74
123
|
```
|
data/exe/cloud-compose
CHANGED
@@ -1,17 +1,30 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'cloud_compose'
|
4
|
+
require 'cloud_compose/cli'
|
4
5
|
|
5
|
-
|
6
|
+
COMMANDS = {
|
7
|
+
'build' => CloudCompose::Cli::Build,
|
8
|
+
'version' => ->(_) { STDOUT.puts CloudCompose::VERSION },
|
9
|
+
'help' => ->(_) { STDERR.puts HELP_MESSAGE },
|
10
|
+
'print' => CloudCompose::Cli::Print
|
11
|
+
}.freeze
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
input_file_path = File.expand_path(ARGV.shift)
|
10
|
-
output_file_path = File.expand_path(ARGV.shift || './') + '/' + File.basename(input_file_path)
|
13
|
+
HELP_MESSAGE = <<~EOF.freeze
|
14
|
+
CloudCompose #{CloudCompose::VERSION} Help
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
Commands
|
17
|
+
#{COMMANDS.keys.map { |k| " - #{k}" }.join("\n")}
|
18
|
+
EOF
|
19
|
+
|
20
|
+
command_name = ARGV.shift
|
21
|
+
|
22
|
+
command_name = 'help' if command_name.nil? || command_name.empty?
|
23
|
+
|
24
|
+
begin
|
25
|
+
command = COMMANDS.fetch(command_name)
|
26
|
+
command.call(ARGV)
|
27
|
+
rescue StandardError => error
|
28
|
+
STDERR.puts "Error: #{error}"
|
16
29
|
exit(1)
|
17
30
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
$cloud_compose:
|
3
|
+
partial: true
|
4
|
+
require:
|
5
|
+
- username
|
6
|
+
---
|
7
|
+
Parameters:
|
8
|
+
$(name)ManagedPolicyArnsParameter:
|
9
|
+
Type: CommaDelimitedList
|
10
|
+
Description: List of Managed Profile Arns.
|
11
|
+
Default: arn:aws:iam::aws:policy/ReadOnlyAccess
|
12
|
+
Mappings:
|
13
|
+
$(name)UserAccount:
|
14
|
+
Password:
|
15
|
+
Value: !Random [ hex, 12 ]
|
16
|
+
Resources:
|
17
|
+
$(name)UserAccount:
|
18
|
+
Type: AWS::IAM::User
|
19
|
+
Properties:
|
20
|
+
UserName: $(username)
|
21
|
+
ManagedPolicyArns: !Ref $(name)ManagedPolicyArnsParameter
|
22
|
+
LoginProfile:
|
23
|
+
Password: !FindInMap [ $(name)UserAccount, Password, Value ]
|
24
|
+
PasswordResetRequired: true
|
25
|
+
Outputs:
|
26
|
+
$(name)UserAccountName:
|
27
|
+
Value: !Ref $(name)UserAccount
|
28
|
+
$(name)UserAccountArn:
|
29
|
+
Value: !GetAtt [ $(name)UserAccount, Arn ]
|
30
|
+
$(name)UserAccountTemporaryPassword:
|
31
|
+
Value: !FindInMap [ $(name)UserAccount, Password, Value ]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
module CloudCompose
|
4
|
+
module Cli
|
5
|
+
class Build
|
6
|
+
class << self
|
7
|
+
def call(args)
|
8
|
+
input_file = args.shift
|
9
|
+
|
10
|
+
if input_file.nil?
|
11
|
+
raise ArgumentError, 'Missing input path `cloud-compose build <input-path>`'
|
12
|
+
end
|
13
|
+
|
14
|
+
template_path = File.expand_path(input_file)
|
15
|
+
template = CloudCompose::Template.new(template_path, File.expand_path('.'))
|
16
|
+
content = template.to_s
|
17
|
+
|
18
|
+
file_name = File.basename(template_path)
|
19
|
+
file_name.slice!(File.extname(file_name))
|
20
|
+
file_name += '-build.yml'
|
21
|
+
output_path = File.dirname(template_path)
|
22
|
+
output_path += "/#{file_name}"
|
23
|
+
|
24
|
+
File.open(output_path, 'w') do |f|
|
25
|
+
f.write(content)
|
26
|
+
end
|
27
|
+
|
28
|
+
STDERR.puts "Built: #{output_path}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../template'
|
2
|
+
|
3
|
+
module CloudCompose
|
4
|
+
module Cli
|
5
|
+
class Print
|
6
|
+
class << self
|
7
|
+
def call(args)
|
8
|
+
input_file = args.shift
|
9
|
+
|
10
|
+
if input_file.nil?
|
11
|
+
raise ArgumentError, 'Missing input path `cloud-compose print <input-path>`'
|
12
|
+
end
|
13
|
+
|
14
|
+
template_path = File.expand_path(input_file)
|
15
|
+
template = CloudCompose::Template.new(template_path, File.expand_path('.'))
|
16
|
+
STDOUT.puts(template.to_s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/cloud_compose/config.rb
CHANGED
data/lib/cloud_compose/parser.rb
CHANGED
@@ -2,14 +2,17 @@ require 'psych'
|
|
2
2
|
|
3
3
|
require_relative 'tags/simple_type'
|
4
4
|
|
5
|
+
require_relative 'tags/builtin'
|
5
6
|
require_relative 'tags/get_att'
|
6
7
|
require_relative 'tags/sub'
|
8
|
+
require_relative 'tags/random'
|
7
9
|
|
8
10
|
module CloudCompose
|
9
11
|
class Parser
|
10
12
|
CUSTOM_TAGS = {
|
11
13
|
'!And' => CloudCompose::Tags::And,
|
12
14
|
'!Base64' => CloudCompose::Tags::Base64,
|
15
|
+
'!Builtin' => CloudCompose::Tags::Builtin,
|
13
16
|
'!Cidr' => CloudCompose::Tags::Cidr,
|
14
17
|
'!Condition' => CloudCompose::Tags::Condition,
|
15
18
|
'!Equals' => CloudCompose::Tags::Equals,
|
@@ -21,6 +24,7 @@ module CloudCompose
|
|
21
24
|
'!Join' => CloudCompose::Tags::Join,
|
22
25
|
'!Not' => CloudCompose::Tags::Not,
|
23
26
|
'!Or' => CloudCompose::Tags::Or,
|
27
|
+
'!Random' => CloudCompose::Tags::Random,
|
24
28
|
'!Ref' => CloudCompose::Tags::Ref,
|
25
29
|
'!Select' => CloudCompose::Tags::Select,
|
26
30
|
'!Split' => CloudCompose::Tags::Split,
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module CloudCompose
|
4
|
+
module Tags
|
5
|
+
class Builtin < Base
|
6
|
+
def type_from_coder(_coder)
|
7
|
+
:scalar
|
8
|
+
end
|
9
|
+
|
10
|
+
def value_from_coder(coder)
|
11
|
+
case coder.type
|
12
|
+
when :scalar
|
13
|
+
path = File.expand_path('../builtin', File.dirname(__FILE__))
|
14
|
+
path += File::SEPARATOR
|
15
|
+
path += coder.scalar
|
16
|
+
path
|
17
|
+
else
|
18
|
+
raise InvalidTypeError.new(coder.tag, coder.type)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def encode_with(coder)
|
23
|
+
coder.tag = nil
|
24
|
+
coder.scalar = value
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module CloudCompose
|
6
|
+
module Tags
|
7
|
+
class Random < Base
|
8
|
+
def type_from_coder(_coder)
|
9
|
+
:scalar
|
10
|
+
end
|
11
|
+
|
12
|
+
def value_from_coder(coder)
|
13
|
+
case coder.type
|
14
|
+
when :seq
|
15
|
+
@random_type = coder.seq[0]
|
16
|
+
@random_count = coder.seq[1].to_i
|
17
|
+
[]
|
18
|
+
else
|
19
|
+
raise InvalidTypeError.new(coder.tag, coder.type)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def encode_with(coder)
|
24
|
+
coder.tag = nil
|
25
|
+
case @random_type
|
26
|
+
when 'hex'
|
27
|
+
coder.scalar = SecureRandom.hex(@random_count)
|
28
|
+
else
|
29
|
+
raise ArgumentError, "Invalid Random Type #{@random_type}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -36,7 +36,7 @@ module CloudCompose
|
|
36
36
|
@checksum = Digest::SHA256.hexdigest(content)
|
37
37
|
parts = content.split(/^---/, 3)
|
38
38
|
@config = CloudCompose::Config.new(parts[1], @root)
|
39
|
-
@content = parts[2]
|
39
|
+
@content = parts[2] || ''
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_h
|
@@ -133,9 +133,7 @@ module CloudCompose
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def create_hash(context)
|
136
|
-
CloudCompose::Parser.load_yaml(
|
137
|
-
CloudCompose::Processor.preprocess(content, context)
|
138
|
-
)
|
136
|
+
CloudCompose::Parser.load_yaml(CloudCompose::Processor.preprocess(content, context)) || {}
|
139
137
|
end
|
140
138
|
|
141
139
|
def preload_imports!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maddie Schipper
|
@@ -106,12 +106,18 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- exe/cloud-compose
|
108
108
|
- lib/cloud_compose.rb
|
109
|
+
- lib/cloud_compose/builtin/iam_console_user.yml
|
110
|
+
- lib/cloud_compose/cli.rb
|
111
|
+
- lib/cloud_compose/cli/build.rb
|
112
|
+
- lib/cloud_compose/cli/print.rb
|
109
113
|
- lib/cloud_compose/config.rb
|
110
114
|
- lib/cloud_compose/parser.rb
|
111
115
|
- lib/cloud_compose/processor.rb
|
112
116
|
- lib/cloud_compose/tags/base.rb
|
117
|
+
- lib/cloud_compose/tags/builtin.rb
|
113
118
|
- lib/cloud_compose/tags/get_att.rb
|
114
119
|
- lib/cloud_compose/tags/map_type.rb
|
120
|
+
- lib/cloud_compose/tags/random.rb
|
115
121
|
- lib/cloud_compose/tags/scalar_type.rb
|
116
122
|
- lib/cloud_compose/tags/sequenced_type.rb
|
117
123
|
- lib/cloud_compose/tags/simple_type.rb
|