rubycfn 0.3.7 → 0.3.8
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/.rubocop.yml +114 -0
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/bin/rubycfn +84 -81
- data/lib/cli_methods.rb +10 -10
- data/lib/rubycfn/version.rb +1 -1
- data/lib/rubycfn.rb +100 -68
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a67c783ed3a9632618ffe3feab06c75fdfc7539
|
4
|
+
data.tar.gz: 1166d0dee1db9009e259e51eb4e069c84c6e0047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cbb3b83362fd9705f289e4c5fa098cd91d9d34c74d1f7c145e2cda7c131336280ea6f883fe2ff630d366bd28fb6388ce7d0cbc7f2aa36958e9940b55b768717
|
7
|
+
data.tar.gz: b1f803072f2bdf77d5e032c689f93252608fa31130cf8f0dc3431b4202b06e3d570d08d36e359415c035208d86f0384902545f574ebd4fd33e79b5c3cfaba6a4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
DisplayCopNames: true
|
5
|
+
Include:
|
6
|
+
- "Gemfile"
|
7
|
+
- "Rakefile"
|
8
|
+
- "bin/*"
|
9
|
+
- "*.gemspec"
|
10
|
+
- "lib/**/*.rb"
|
11
|
+
Exclude:
|
12
|
+
- "lib/core/monkeypatch.rb"
|
13
|
+
- "test/**/*.rb"
|
14
|
+
- "spec/**/*.rb"
|
15
|
+
- "attic/**/*"
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Max: 500
|
19
|
+
Exclude:
|
20
|
+
- "test/**/*"
|
21
|
+
- "spec/**/*"
|
22
|
+
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Max: 500
|
25
|
+
Exclude:
|
26
|
+
- "test/**/*"
|
27
|
+
- "spec/**/*"
|
28
|
+
|
29
|
+
Metrics/CyclomaticComplexity:
|
30
|
+
Max: 40
|
31
|
+
Exclude:
|
32
|
+
- "test/**/*"
|
33
|
+
- "spec/**/*"
|
34
|
+
|
35
|
+
Metrics/PerceivedComplexity:
|
36
|
+
Max: 40
|
37
|
+
Exclude:
|
38
|
+
- "test/**/*"
|
39
|
+
- "spec/**/*"
|
40
|
+
|
41
|
+
Layout/SpaceInsideHashLiteralBraces:
|
42
|
+
EnforcedStyle: space
|
43
|
+
|
44
|
+
Metrics/LineLength:
|
45
|
+
Max: 500
|
46
|
+
Exclude:
|
47
|
+
- "test/**/*"
|
48
|
+
- "spec/**/*"
|
49
|
+
|
50
|
+
Metrics/ModuleLength:
|
51
|
+
Max: 500
|
52
|
+
|
53
|
+
Metrics/MethodLength:
|
54
|
+
Max: 40
|
55
|
+
|
56
|
+
Metrics/BlockLength:
|
57
|
+
Max: 500
|
58
|
+
|
59
|
+
Performance/Casecmp:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/DoubleNegation:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
Style/StringLiterals:
|
66
|
+
EnforcedStyle: double_quotes
|
67
|
+
|
68
|
+
Style/StringLiteralsInInterpolation:
|
69
|
+
EnforcedStyle: double_quotes
|
70
|
+
|
71
|
+
Style/Next:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Style/FrozenStringLiteralComment:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
Security/MarshalLoad:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Style/PercentLiteralDelimiters:
|
81
|
+
PreferredDelimiters:
|
82
|
+
default: '()'
|
83
|
+
'%i': '()'
|
84
|
+
'%w': '()'
|
85
|
+
|
86
|
+
Style/Alias:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/ClassAndModuleChildren:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/Documentation:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Style/ExpandPathArguments:
|
96
|
+
Enabled: false
|
97
|
+
|
98
|
+
Style/IfUnlessModifier:
|
99
|
+
Enabled: false
|
100
|
+
|
101
|
+
Style/DateTime:
|
102
|
+
Enabled: false
|
103
|
+
|
104
|
+
Style/MissingRespondToMissing:
|
105
|
+
Enabled: false
|
106
|
+
|
107
|
+
Style/NestedTernaryOperator:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
Style/PerlBackrefs:
|
111
|
+
Enabled: false
|
112
|
+
|
113
|
+
Style/RescueStandardError:
|
114
|
+
EnforcedStyle: "implicit"
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
All notable changes to Rubycfn will be documented in this file.
|
3
3
|
This project uses [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
-
## 0.3.
|
5
|
+
## 0.3.9 (Next Release)
|
6
|
+
|
7
|
+
## 0.3.8
|
8
|
+
|
9
|
+
* Added Fn::Transform intrinsic function `.fntransform` -- [@dennisvink][@dennisvink]
|
10
|
+
* Refactored some code -- [@dennisvink][@dennisvink]
|
6
11
|
|
7
12
|
## 0.3.7
|
8
13
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -61,7 +61,7 @@ __________ ____ __________________.___._________ _____________________
|
|
61
61
|
| _/ | /| | _// | |/ \ \/ | __) | | _/
|
62
62
|
| | \ | / | | \\____ |\ \____| \ | | \
|
63
63
|
|____|_ /______/ |______ // ______| \______ /\___ / |______ /
|
64
|
-
\/ \/ \/ \/ \/ \/ [v0.3.
|
64
|
+
\/ \/ \/ \/ \/ \/ [v0.3.8]
|
65
65
|
Project name? example
|
66
66
|
Account ID? 1234567890
|
67
67
|
Select region EU (Frankfurt)
|
data/bin/rubycfn
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "erb"
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "fileutils"
|
5
|
+
require "ostruct"
|
6
6
|
require "tty-prompt"
|
7
7
|
require "rubycfn/version"
|
8
8
|
|
9
9
|
require_relative "../lib/cli_methods"
|
10
10
|
|
11
|
-
|
11
|
+
# rubocop:disable Style/AndOr
|
12
|
+
if ARGV.first || (ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)) # rubocop:disable Style/Not
|
12
13
|
require "rubycfn"
|
13
14
|
require "active_support/concern"
|
14
15
|
module RubycfnStack
|
15
|
-
if
|
16
|
+
if ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?) # rubocop:disable Style/Not
|
17
|
+
# rubocop:enable Style/AndOr
|
16
18
|
contents = []
|
17
19
|
ARGF.each_line do |line|
|
18
20
|
contents.push(line)
|
@@ -25,10 +27,10 @@ if ARGV.first || (ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)
|
|
25
27
|
extend ActiveSupport::Concern
|
26
28
|
include Rubycfn
|
27
29
|
included do
|
28
|
-
eval(contents)
|
30
|
+
eval(contents) # rubocop:disable Security/Eval
|
29
31
|
end
|
30
32
|
end
|
31
|
-
cfn = include RubycfnStack
|
33
|
+
cfn = include RubycfnStack # rubocop:disable Style/MixinUsage
|
32
34
|
puts cfn.render_template
|
33
35
|
exit
|
34
36
|
end
|
@@ -37,97 +39,98 @@ path = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
|
37
39
|
puts rubycfn_banner(Rubycfn::VERSION)
|
38
40
|
prompt = TTY::Prompt.new
|
39
41
|
|
40
|
-
project_name = prompt.ask(
|
41
|
-
q.validate(/^([a-z0-9]*)$/,
|
42
|
+
project_name = prompt.ask("Project name?", default: "example") do |q|
|
43
|
+
q.validate(/^([a-z0-9]*)$/, "Invalid project name")
|
42
44
|
end
|
43
45
|
|
44
|
-
project_path = project_name +
|
46
|
+
project_path = project_name + "-rubycfn"
|
45
47
|
|
46
|
-
account_id = prompt.ask(
|
47
|
-
q.validate(/^([0-9]*)$/,
|
48
|
+
account_id = prompt.ask("AWS Account ID?", default: "1234567890") do |q|
|
49
|
+
q.validate(/^([0-9]*)$/, "Invalid account id")
|
48
50
|
end
|
49
51
|
|
50
52
|
region = prompt.select(
|
51
53
|
"Select AWS region", aws_regions
|
52
54
|
)
|
53
55
|
|
54
|
-
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:
|
58
|
-
}
|
56
|
+
render_args = {
|
57
|
+
project_name: project_name,
|
58
|
+
account_id: account_id,
|
59
|
+
region: region
|
60
|
+
}
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
62
|
+
dotenv = render(".env", render_args, path)
|
63
|
+
aws_sdk = render("aws_sdk.rb", {}, path)
|
64
|
+
compiler = render("compiler.rb", {}, path)
|
65
|
+
core_deploy = render("core_deploy.rb", { name: project_name }, path)
|
66
|
+
core_upload = render("core_upload.rb", {}, path)
|
67
|
+
core_compile = render("core_compile.rb", {}, path)
|
68
|
+
core_diff = render("core_diff.rb", {}, path)
|
69
|
+
dependencies = render("dependencies.rb", {}, path)
|
70
|
+
deploy = render("deploy.rb", {}, path)
|
71
|
+
dotenv_test = render(".env.test", { name: project_name }, path)
|
72
|
+
dotenv_production = render(".env.production", { name: project_name }, path)
|
73
|
+
dotenv_rspec = render(".env.rspec", { name: project_name }, path)
|
74
|
+
ecs_stack = render("ecs_stack.rb", {}, path)
|
75
|
+
ecs_stack_concern = render("ecs_Stack_concern.rb", { name: project_name }, path)
|
76
|
+
gemfile = render("Gemfile", { version: Rubycfn::VERSION }, path)
|
77
|
+
gitignore = render(".gitignore", {}, path)
|
78
|
+
global_variables = render("global_variables.rb", { name: project_name.downcase }, path)
|
79
|
+
helpers = render("helpers.rb", {}, path)
|
80
|
+
helper_methods = render("helper_methods.rb", {}, path)
|
81
|
+
main = render("main.rb", {}, path)
|
82
|
+
main_aws_helper = render("main_aws_helper.rb", {}, path)
|
83
|
+
parent_spec = render("parent_stack_spec.rb", { name: project_name.capitalize }, path)
|
84
|
+
project_concern = render("project_concern.rb", { name: project_name.capitalize }, path)
|
85
|
+
project_stack = render("project_stack.rb", { name: project_name.capitalize }, path)
|
86
|
+
rakefile = render("Rakefile", {}, path)
|
87
|
+
rubocop = render(".rubocop.yml", {}, path)
|
88
|
+
shared_methods = render("shared_methods.rb", {}, path)
|
89
|
+
spec_helper = render("spec_helper.rb", {}, path)
|
90
|
+
subnets = render("subnets.rb", { name: project_name }, path)
|
91
|
+
upload_stack = render("upload_stack.rb", {}, path)
|
92
|
+
vpc_stack = render("vpc_stack.rb", { name: project_name }, path)
|
93
|
+
vpc_concern = render("vpc_concerns.rb", { name: project_name }, path)
|
94
|
+
vpc_spec = render("vpc_spec.rb", { name: project_name.capitalize }, path)
|
92
95
|
|
93
96
|
# Create directory structure
|
94
97
|
rubycfn_structure(project_path).each do |dir|
|
95
98
|
FileUtils.mkdir_p dir
|
96
99
|
end
|
97
100
|
|
98
|
-
File.open("#{project_path}/lib/aws_helper/aws_sdk.rb",
|
99
|
-
File.open("#{project_path}/lib/aws_helper/compiler.rb",
|
100
|
-
File.open("#{project_path}/lib/aws_helper/dependencies.rb",
|
101
|
-
File.open("#{project_path}/lib/aws_helper/deploy.rb",
|
102
|
-
File.open("#{project_path}/lib/core/deploy.rb",
|
103
|
-
File.open("#{project_path}/lib/core/compile.rb",
|
104
|
-
File.open("#{project_path}/lib/core/diff.rb",
|
105
|
-
File.open("#{project_path}/lib/core/upload.rb",
|
106
|
-
File.open("#{project_path}/.env",
|
107
|
-
File.open("#{project_path}/.env.test",
|
108
|
-
File.open("#{project_path}/.env.production",
|
109
|
-
File.open("#{project_path}/.env.rspec",
|
110
|
-
File.open("#{project_path}/lib/stacks/ecs_stack.rb",
|
111
|
-
File.open("#{project_path}/lib/stacks/ecs_stack/ecs_cluster.rb",
|
112
|
-
File.open("#{project_path}/Gemfile",
|
113
|
-
File.open("#{project_path}/.gitignore",
|
114
|
-
File.open("#{project_path}/lib/shared_concerns/global_variables.rb",
|
115
|
-
File.open("#{project_path}/lib/aws_helper/helpers.rb",
|
116
|
-
File.open("#{project_path}/lib/shared_concerns/helper_methods.rb",
|
117
|
-
File.open("#{project_path}/lib/main.rb",
|
118
|
-
File.open("#{project_path}/lib/aws_helper/main.rb",
|
119
|
-
File.open("#{project_path}/spec/lib/parent_spec.rb",
|
120
|
-
File.open("#{project_path}/lib/stacks/parent_stack.rb",
|
121
|
-
File.open("#{project_path}/lib/stacks/parent_stack/parent.rb",
|
122
|
-
File.open("#{project_path}/Rakefile",
|
123
|
-
File.open("#{project_path}/.rubocop.yml",
|
124
|
-
File.open("#{project_path}/lib/shared_concerns/shared_methods.rb",
|
125
|
-
File.open("#{project_path}/spec/spec_helper.rb",
|
126
|
-
File.open("#{project_path}/lib/stacks/vpc_stack/subnets.rb",
|
127
|
-
File.open("#{project_path}/lib/aws_helper/upload_stack.rb",
|
128
|
-
File.open("#{project_path}/spec/lib/vpc_spec.rb",
|
129
|
-
File.open("#{project_path}/lib/stacks/vpc_stack.rb",
|
130
|
-
File.open("#{project_path}/lib/stacks/vpc_stack/vpc.rb",
|
101
|
+
File.open("#{project_path}/lib/aws_helper/aws_sdk.rb", "w") { |file| file.write(aws_sdk) }
|
102
|
+
File.open("#{project_path}/lib/aws_helper/compiler.rb", "w") { |file| file.write(compiler) }
|
103
|
+
File.open("#{project_path}/lib/aws_helper/dependencies.rb", "w") { |file| file.write(dependencies) }
|
104
|
+
File.open("#{project_path}/lib/aws_helper/deploy.rb", "w") { |file| file.write(deploy) }
|
105
|
+
File.open("#{project_path}/lib/core/deploy.rb", "w") { |file| file.write(core_deploy) }
|
106
|
+
File.open("#{project_path}/lib/core/compile.rb", "w") { |file| file.write(core_compile) }
|
107
|
+
File.open("#{project_path}/lib/core/diff.rb", "w") { |file| file.write(core_diff) }
|
108
|
+
File.open("#{project_path}/lib/core/upload.rb", "w") { |file| file.write(core_upload) }
|
109
|
+
File.open("#{project_path}/.env", "w") { |file| file.write(dotenv) }
|
110
|
+
File.open("#{project_path}/.env.test", "w") { |file| file.write(dotenv_test) }
|
111
|
+
File.open("#{project_path}/.env.production", "w") { |file| file.write(dotenv_production) }
|
112
|
+
File.open("#{project_path}/.env.rspec", "w") { |file| file.write(dotenv_rspec) }
|
113
|
+
File.open("#{project_path}/lib/stacks/ecs_stack.rb", "w") { |file| file.write(ecs_stack) }
|
114
|
+
File.open("#{project_path}/lib/stacks/ecs_stack/ecs_cluster.rb", "w") { |file| file.write(ecs_stack_concern) }
|
115
|
+
File.open("#{project_path}/Gemfile", "w") { |file| file.write(gemfile) }
|
116
|
+
File.open("#{project_path}/.gitignore", "w") { |file| file.write(gitignore) }
|
117
|
+
File.open("#{project_path}/lib/shared_concerns/global_variables.rb", "w") { |file| file.write(global_variables) }
|
118
|
+
File.open("#{project_path}/lib/aws_helper/helpers.rb", "w") { |file| file.write(helpers) }
|
119
|
+
File.open("#{project_path}/lib/shared_concerns/helper_methods.rb", "w") { |file| file.write(helper_methods) }
|
120
|
+
File.open("#{project_path}/lib/main.rb", "w") { |file| file.write(main) }
|
121
|
+
File.open("#{project_path}/lib/aws_helper/main.rb", "w") { |file| file.write(main_aws_helper) }
|
122
|
+
File.open("#{project_path}/spec/lib/parent_spec.rb", "w") { |file| file.write(parent_spec) }
|
123
|
+
File.open("#{project_path}/lib/stacks/parent_stack.rb", "w") { |file| file.write(project_stack) }
|
124
|
+
File.open("#{project_path}/lib/stacks/parent_stack/parent.rb", "w") { |file| file.write(project_concern) }
|
125
|
+
File.open("#{project_path}/Rakefile", "w") { |file| file.write(rakefile) }
|
126
|
+
File.open("#{project_path}/.rubocop.yml", "w") { |file| file.write(rubocop) }
|
127
|
+
File.open("#{project_path}/lib/shared_concerns/shared_methods.rb", "w") { |file| file.write(shared_methods) }
|
128
|
+
File.open("#{project_path}/spec/spec_helper.rb", "w") { |file| file.write(spec_helper) }
|
129
|
+
File.open("#{project_path}/lib/stacks/vpc_stack/subnets.rb", "w") { |file| file.write(subnets) }
|
130
|
+
File.open("#{project_path}/lib/aws_helper/upload_stack.rb", "w") { |file| file.write(upload_stack) }
|
131
|
+
File.open("#{project_path}/spec/lib/vpc_spec.rb", "w") { |file| file.write(vpc_spec) }
|
132
|
+
File.open("#{project_path}/lib/stacks/vpc_stack.rb", "w") { |file| file.write(vpc_stack) }
|
133
|
+
File.open("#{project_path}/lib/stacks/vpc_stack/vpc.rb", "w") { |file| file.write(vpc_concern) }
|
131
134
|
|
132
135
|
puts "Setting up Rubycfn #{project_name} project..."
|
133
136
|
`cd #{project_name}-rubycfn && git init && bundle`
|
data/lib/cli_methods.rb
CHANGED
@@ -38,15 +38,15 @@ end
|
|
38
38
|
def rubycfn_structure(project_name)
|
39
39
|
[
|
40
40
|
project_name,
|
41
|
-
project_name +
|
42
|
-
project_name +
|
43
|
-
project_name +
|
44
|
-
project_name +
|
45
|
-
project_name +
|
46
|
-
project_name +
|
47
|
-
project_name +
|
48
|
-
project_name +
|
49
|
-
project_name +
|
50
|
-
project_name +
|
41
|
+
project_name + "/build",
|
42
|
+
project_name + "/lib/aws_helper",
|
43
|
+
project_name + "/lib/core",
|
44
|
+
project_name + "/lib/shared_concerns",
|
45
|
+
project_name + "/lib/stacks",
|
46
|
+
project_name + "/lib/stacks/ecs_stack",
|
47
|
+
project_name + "/lib/stacks/parent_stack",
|
48
|
+
project_name + "/lib/stacks/vpc_stack",
|
49
|
+
project_name + "/spec",
|
50
|
+
project_name + "/spec/lib"
|
51
51
|
]
|
52
52
|
end
|
data/lib/rubycfn/version.rb
CHANGED
data/lib/rubycfn.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# Rubycfn RubyCFN is a light-weight CloudFormation DSL
|
2
|
-
require
|
2
|
+
require "active_support/concern"
|
3
3
|
require "json"
|
4
4
|
require "neatjson"
|
5
5
|
require "rubycfn/version"
|
6
|
-
#require "tasks/tasks"
|
7
6
|
|
8
|
-
@depends_on = []
|
7
|
+
@depends_on = []
|
9
8
|
@description = ""
|
10
9
|
@transform = ""
|
11
10
|
@outputs = {}
|
@@ -14,7 +13,7 @@ require "rubycfn/version"
|
|
14
13
|
@metadata = {}
|
15
14
|
@mappings = {}
|
16
15
|
@conditions = {}
|
17
|
-
@
|
16
|
+
@aws_resources = {}
|
18
17
|
@imports = []
|
19
18
|
@resource_name = ""
|
20
19
|
@variables = {}
|
@@ -24,10 +23,24 @@ require "rubycfn/version"
|
|
24
23
|
class Symbol
|
25
24
|
def ref(attr = nil)
|
26
25
|
unless attr
|
27
|
-
return { Ref:
|
26
|
+
return { Ref: to_s.split("_").map(&:capitalize).join }
|
28
27
|
end
|
29
|
-
attr = attr.class == String ? attr : attr.to_s.split(
|
30
|
-
|
28
|
+
attr = attr.class == String ? attr : attr.to_s.split("_").map(&:capitalize).join
|
29
|
+
{
|
30
|
+
"Fn::GetAtt": [
|
31
|
+
to_s.split("_").map(&:capitalize).join, attr
|
32
|
+
]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def fntransform(parameters = nil)
|
37
|
+
raise "fntransform parameters must be of type Hash" unless parameters.class == Hash
|
38
|
+
{
|
39
|
+
"Fn::Transform": {
|
40
|
+
"Name": to_s.split("_").map(&:capitalize).join,
|
41
|
+
"Parameters": parameters
|
42
|
+
}
|
43
|
+
}
|
31
44
|
end
|
32
45
|
end
|
33
46
|
|
@@ -45,15 +58,30 @@ end
|
|
45
58
|
class String
|
46
59
|
def cfnize
|
47
60
|
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
48
|
-
split(
|
61
|
+
split("_").map(&:capitalize).join
|
49
62
|
end
|
50
63
|
|
51
64
|
def ref(attr = nil)
|
52
65
|
unless attr
|
53
66
|
return { Ref: self }
|
54
67
|
end
|
55
|
-
attr = attr.class == String ? attr : attr.to_s.split(
|
56
|
-
|
68
|
+
attr = attr.class == String ? attr : attr.to_s.split("_").map(&:capitalize).join
|
69
|
+
{
|
70
|
+
"Fn::GetAtt": [
|
71
|
+
self,
|
72
|
+
attr
|
73
|
+
]
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def fntransform(parameters = nil)
|
78
|
+
raise "fntransform parameters must be of type Hash" unless parameters.class == Hash
|
79
|
+
{
|
80
|
+
"Fn::Transform": {
|
81
|
+
"Name": self,
|
82
|
+
"Parameters": parameters
|
83
|
+
}
|
84
|
+
}
|
57
85
|
end
|
58
86
|
|
59
87
|
def fnsplit(separator = "")
|
@@ -66,25 +94,35 @@ class String
|
|
66
94
|
end
|
67
95
|
|
68
96
|
def fnbase64
|
69
|
-
|
97
|
+
{
|
98
|
+
"Fn::Base64": self
|
99
|
+
}
|
70
100
|
end
|
71
101
|
|
72
102
|
def fngetazs
|
73
|
-
|
103
|
+
{
|
104
|
+
"Fn::GetAZs": self
|
105
|
+
}
|
74
106
|
end
|
75
107
|
|
76
108
|
def fnsub(variable_map = nil)
|
77
109
|
unless variable_map
|
78
110
|
return { "Fn::Sub": self }
|
79
111
|
end
|
80
|
-
|
112
|
+
{
|
113
|
+
"Fn::Sub": [
|
114
|
+
self,
|
115
|
+
variable_map
|
116
|
+
]
|
117
|
+
}
|
81
118
|
end
|
82
119
|
|
83
120
|
def fnimportvalue
|
84
|
-
|
121
|
+
{
|
122
|
+
"Fn::Import": self
|
123
|
+
}
|
85
124
|
end
|
86
125
|
alias_method :fnimport, :fnimportvalue
|
87
|
-
|
88
126
|
end
|
89
127
|
|
90
128
|
class Array
|
@@ -126,7 +164,7 @@ class Array
|
|
126
164
|
end
|
127
165
|
|
128
166
|
def fnfindinmap(name = nil)
|
129
|
-
|
167
|
+
unshift(name.cfnize) if name
|
130
168
|
{
|
131
169
|
"Fn::FindInMap": self
|
132
170
|
}
|
@@ -154,20 +192,26 @@ class Array
|
|
154
192
|
end
|
155
193
|
|
156
194
|
class ::Hash
|
195
|
+
# rubocop:disable Style/RedundantSelf
|
196
|
+
# rubocop:disable Style/CaseEquality
|
197
|
+
# rubocop:disable Lint/UnusedBlockArgument
|
157
198
|
def deep_merge(second)
|
158
199
|
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
|
159
200
|
self.merge(second.to_h, &merger)
|
160
201
|
end
|
202
|
+
# rubocop:enable Style/RedundantSelf
|
203
|
+
# rubocop:enable Style/CaseEquality
|
204
|
+
# rubocop:enable Lint/UnusedBlockArgument
|
161
205
|
|
162
206
|
def recursive_compact
|
163
207
|
delete_if do |k, v|
|
164
|
-
next if v
|
165
|
-
(v.respond_to?(:empty?) ? v.empty? : !v)
|
208
|
+
next if v == false || k =~ /Fn\:/
|
209
|
+
(v.respond_to?(:empty?) ? v.empty? : !v) || v.instance_of?(Hash) && v.recursive_compact.empty?
|
166
210
|
end
|
167
211
|
end
|
168
212
|
|
169
213
|
def compact
|
170
|
-
delete_if { |
|
214
|
+
delete_if { |_k, v| v.nil? }
|
171
215
|
end
|
172
216
|
|
173
217
|
def fnselect(index = 0)
|
@@ -184,6 +228,7 @@ module Rubycfn
|
|
184
228
|
extend ActiveSupport::Concern
|
185
229
|
|
186
230
|
included do
|
231
|
+
# rubocop:disable Style/UnneededCondition
|
187
232
|
def self.method_missing(name, *args)
|
188
233
|
super unless TOPLEVEL_BINDING.eval("@variables[:#{name}]") || \
|
189
234
|
TOPLEVEL_BINDING.eval("@variables[:#{name}] === false") ||
|
@@ -195,17 +240,16 @@ module Rubycfn
|
|
195
240
|
TOPLEVEL_BINDING.eval("@global_variables[:#{name}]")
|
196
241
|
end
|
197
242
|
end
|
243
|
+
# rubocop:enable Style/UnneededCondition
|
198
244
|
|
199
245
|
def self.transform(transform = "AWS::Serverless-2016-10-31")
|
200
|
-
|
201
|
-
|
202
|
-
end
|
246
|
+
return if transform.nil?
|
247
|
+
TOPLEVEL_BINDING.eval("@transform = '#{transform}'")
|
203
248
|
end
|
204
249
|
|
205
250
|
def self.description(description = "")
|
206
|
-
|
207
|
-
|
208
|
-
end
|
251
|
+
return if description.nil?
|
252
|
+
TOPLEVEL_BINDING.eval("@description = '#{description}'")
|
209
253
|
end
|
210
254
|
|
211
255
|
def self.condition(name, arguments)
|
@@ -225,7 +269,9 @@ module Rubycfn
|
|
225
269
|
end
|
226
270
|
|
227
271
|
name = name.to_s.cfnize
|
228
|
-
|
272
|
+
# rubocop:disable Style/UnneededCondition
|
273
|
+
kv_pairs = arguments[:data] ? arguments[:data] : { "#{arguments[:key]}": (arguments[:value]).to_s }
|
274
|
+
# rubocop:enable Style/UnneededCondition
|
229
275
|
res = {
|
230
276
|
"#{name}": {
|
231
277
|
"#{arguments[:name]}": kv_pairs
|
@@ -287,26 +333,22 @@ module Rubycfn
|
|
287
333
|
end
|
288
334
|
|
289
335
|
if arguments[:filter]
|
290
|
-
arguments[:value] =
|
336
|
+
arguments[:value] = send(arguments[:filter], arguments[:value])
|
291
337
|
end
|
292
338
|
|
293
339
|
res = {
|
294
340
|
"#{name}": arguments[:value]
|
295
341
|
}
|
296
|
-
|
297
|
-
|
298
|
-
else
|
299
|
-
TOPLEVEL_BINDING.eval("@global_variables = @global_variables.deep_merge(#{res})")
|
300
|
-
TOPLEVEL_BINDING.eval("@variables = @variables.deep_merge(#{res})")
|
301
|
-
end
|
342
|
+
TOPLEVEL_BINDING.eval("@global_variables = @global_variables.deep_merge(#{res})") unless arguments[:global] == false
|
343
|
+
TOPLEVEL_BINDING.eval("@variables = @variables.deep_merge(#{res})")
|
302
344
|
end
|
303
345
|
|
304
346
|
def self.depends_on(resources)
|
305
347
|
case resources
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
348
|
+
when String
|
349
|
+
resources = [resources.cfnize]
|
350
|
+
when Array
|
351
|
+
resources = resources.map(&:cfnize)
|
310
352
|
end
|
311
353
|
TOPLEVEL_BINDING.eval("@depends_on = #{resources}")
|
312
354
|
end
|
@@ -315,29 +357,23 @@ module Rubycfn
|
|
315
357
|
TOPLEVEL_BINDING.eval("@resource_name = '#{name}'")
|
316
358
|
end
|
317
359
|
|
318
|
-
|
360
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
361
|
+
def self.set(name, _index = 0, &block)
|
319
362
|
res = {
|
320
363
|
"#{name}": yield
|
321
364
|
}
|
322
365
|
TOPLEVEL_BINDING.eval("@variables = @variables.deep_merge(#{res})")
|
323
366
|
end
|
367
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
324
368
|
|
325
|
-
def self.meta(name,
|
326
|
-
|
327
|
-
name = TOPLEVEL_BINDING.eval("'#{name}'.cfnize")
|
328
|
-
else
|
329
|
-
name = TOPLEVEL_BINDING.eval("'#{name}'")
|
330
|
-
end
|
369
|
+
def self.meta(name, _index = 0, &block)
|
370
|
+
name = name.class == Symbol ? TOPLEVEL_BINDING.eval("'#{name}'.cfnize") : TOPLEVEL_BINDING.eval("'#{name}'")
|
331
371
|
res = { "#{name}": yield(block) }
|
332
372
|
TOPLEVEL_BINDING.eval("@metadata = @metadata.deep_merge(#{res})")
|
333
373
|
end
|
334
374
|
|
335
|
-
def self.property(name,
|
336
|
-
|
337
|
-
name = TOPLEVEL_BINDING.eval("'#{name}'.cfnize")
|
338
|
-
else
|
339
|
-
name = TOPLEVEL_BINDING.eval("'#{name}'")
|
340
|
-
end
|
375
|
+
def self.property(name, _index = 0, &block)
|
376
|
+
name = name.class == Symbol ? TOPLEVEL_BINDING.eval("'#{name}'.cfnize") : TOPLEVEL_BINDING.eval("'#{name}'")
|
341
377
|
res = { "#{name}": yield(block) }
|
342
378
|
TOPLEVEL_BINDING.eval("@properties = @properties.deep_merge(#{res})")
|
343
379
|
end
|
@@ -345,12 +381,8 @@ module Rubycfn
|
|
345
381
|
def self.resource(name, arguments, &block)
|
346
382
|
arguments[:amount] ||= 1
|
347
383
|
origname = name.to_s
|
348
|
-
# Allow for non-camelcased resource names
|
349
|
-
|
350
|
-
name = name.to_s.cfnize
|
351
|
-
else
|
352
|
-
name = name.to_s
|
353
|
-
end
|
384
|
+
# Allow for non-camelcased resource names
|
385
|
+
name = name.class == Symbol ? name.to_s.cfnize : name = name.to_s
|
354
386
|
arguments[:type] =~ /^([A-Za-z0-9]*)\:\:/
|
355
387
|
arguments[:cloud] ||= $1
|
356
388
|
|
@@ -359,20 +391,20 @@ module Rubycfn
|
|
359
391
|
arguments[:cloud] = "AWS"
|
360
392
|
end
|
361
393
|
arguments[:amount].times do |i|
|
362
|
-
resource_suffix = i
|
394
|
+
resource_suffix = i.zero? ? "" : (i + 1).to_s
|
363
395
|
if arguments[:type].class == Module
|
364
396
|
send("include", arguments[:type][origname, resource_suffix, &block])
|
365
397
|
else
|
366
398
|
yield self, i if block_given?
|
367
399
|
|
368
|
-
resource_postpend = TOPLEVEL_BINDING.eval("@resource_name").empty? ? i+1 : ""
|
400
|
+
resource_postpend = TOPLEVEL_BINDING.eval("@resource_name").empty? ? i + 1 : ""
|
369
401
|
unless TOPLEVEL_BINDING.eval("@resource_name").empty?
|
370
402
|
name = TOPLEVEL_BINDING.eval("@resource_name")
|
371
403
|
TOPLEVEL_BINDING.eval("@resource_name = ''")
|
372
404
|
end
|
373
405
|
|
374
406
|
res = {
|
375
|
-
"#{name.to_s}#{i
|
407
|
+
"#{name.to_s}#{i.zero? ? "" : resource_postpend}": {
|
376
408
|
DependsOn: TOPLEVEL_BINDING.eval("@depends_on"),
|
377
409
|
Metadata: TOPLEVEL_BINDING.eval("@metadata"),
|
378
410
|
Properties: TOPLEVEL_BINDING.eval("@properties"),
|
@@ -380,7 +412,7 @@ module Rubycfn
|
|
380
412
|
Condition: arguments[:condition]
|
381
413
|
}
|
382
414
|
}
|
383
|
-
TOPLEVEL_BINDING.eval("@
|
415
|
+
TOPLEVEL_BINDING.eval("@aws_resources = @aws_resources.deep_merge(#{res})")
|
384
416
|
end
|
385
417
|
TOPLEVEL_BINDING.eval("@depends_on = []")
|
386
418
|
TOPLEVEL_BINDING.eval("@properties = {}")
|
@@ -399,14 +431,14 @@ module Rubycfn
|
|
399
431
|
when "AWS"
|
400
432
|
skeleton = { "AWSTemplateFormatVersion": "2010-09-09" }
|
401
433
|
skeleton = JSON.parse(skeleton.to_json)
|
402
|
-
skeleton
|
403
|
-
skeleton
|
404
|
-
skeleton
|
405
|
-
skeleton
|
406
|
-
skeleton
|
407
|
-
skeleton
|
408
|
-
skeleton
|
409
|
-
TOPLEVEL_BINDING.eval("@variables = @
|
434
|
+
skeleton[:Transform] = TOPLEVEL_BINDING.eval("@transform")
|
435
|
+
skeleton[:Description] = TOPLEVEL_BINDING.eval("@description")
|
436
|
+
skeleton[:Mappings] = sort_json(TOPLEVEL_BINDING.eval("@mappings"))
|
437
|
+
skeleton[:Parameters] = sort_json(TOPLEVEL_BINDING.eval("@parameters"))
|
438
|
+
skeleton[:Conditions] = sort_json(TOPLEVEL_BINDING.eval("@conditions"))
|
439
|
+
skeleton[:Resources] = sort_json(TOPLEVEL_BINDING.eval("@aws_resources"))
|
440
|
+
skeleton[:Outputs] = sort_json(TOPLEVEL_BINDING.eval("@outputs"))
|
441
|
+
TOPLEVEL_BINDING.eval("@variables = @aws_resources = @outputs = @metadata = @properties = @mappings = @parameters = {}")
|
410
442
|
TOPLEVEL_BINDING.eval("@depends_on = []")
|
411
443
|
TOPLEVEL_BINDING.eval("@description = ''")
|
412
444
|
TOPLEVEL_BINDING.eval("@transform = ''")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycfn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Vink
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|
@@ -257,6 +257,7 @@ extensions: []
|
|
257
257
|
extra_rdoc_files: []
|
258
258
|
files:
|
259
259
|
- ".gitignore"
|
260
|
+
- ".rubocop.yml"
|
260
261
|
- CHANGELOG.md
|
261
262
|
- Gemfile
|
262
263
|
- Gemfile.lock
|
@@ -324,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
325
|
version: '0'
|
325
326
|
requirements: []
|
326
327
|
rubyforge_project:
|
327
|
-
rubygems_version: 2.
|
328
|
+
rubygems_version: 2.5.1
|
328
329
|
signing_key:
|
329
330
|
specification_version: 4
|
330
331
|
summary: Rubycfn
|