rubycfn 0.4.5 → 0.4.6
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/CHANGELOG.md +7 -1
- data/Gemfile.lock +2 -2
- data/README.md +5 -1
- data/bin/rubycfn +28 -21
- data/lib/cli_methods.rb +19 -0
- data/lib/monkeypatch.rb +18 -0
- data/lib/rubycfn/version.rb +1 -1
- data/lib/rubycfn.rb +7 -1
- data/templates/new_concern.rb.erb +10 -0
- data/templates/new_stack.rb.erb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54323e492522b3ea1a2d1052b07792fee27e2a95
|
4
|
+
data.tar.gz: 106b5915d1354d4a4753bccf45eb54b4f2af6375
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b41fc96833ad3d852dd2092324bd8283a5e39e847860b9677c4c7ab7edaf5760bd940710ba38f6c1f2530fa17edab71a0992605b5cd87673534185864115dbe
|
7
|
+
data.tar.gz: 7985ac469a239223734bb8f3a2e9c976f3f5af42c365de7fd439df7ecf78149c99d2d33391f42fd685d90d62f53a7f942b694afaef9432798596c38cab1cab82
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,13 @@
|
|
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.4.
|
5
|
+
## 0.4.7 (Next Release)
|
6
|
+
|
7
|
+
## 0.4.6
|
8
|
+
|
9
|
+
* Added `template` attribute to variables -- [@dennisvink][@dennisvink]
|
10
|
+
* Added `rubycfn stack` command to add new stack quickly -- [@dennisvink][@dennisvink]
|
11
|
+
* Added `get_output` method -- [@dennisvink][@dennisvink]
|
6
12
|
|
7
13
|
## 0.4.5
|
8
14
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubycfn (0.4.
|
4
|
+
rubycfn (0.4.6)
|
5
5
|
activesupport (~> 5.1.5)
|
6
6
|
dotenv (~> 2.4.0)
|
7
7
|
json (~> 2.1.0)
|
@@ -119,7 +119,7 @@ GEM
|
|
119
119
|
tty-screen (0.6.5)
|
120
120
|
tzinfo (1.2.5)
|
121
121
|
thread_safe (~> 0.1)
|
122
|
-
wisper (2.0.
|
122
|
+
wisper (2.0.1)
|
123
123
|
|
124
124
|
PLATFORMS
|
125
125
|
ruby
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ __________ ____ __________________.___._________ _____________________
|
|
61
61
|
| _/ | /| | _// | |/ \ \/ | __) | | _/
|
62
62
|
| | \ | / | | \\____ |\ \____| \ | | \
|
63
63
|
|____|_ /______/ |______ // ______| \______ /\___ / |______ /
|
64
|
-
\/ \/ \/ \/ \/ \/ [v0.4.
|
64
|
+
\/ \/ \/ \/ \/ \/ [v0.4.6]
|
65
65
|
Project name? example
|
66
66
|
Account ID? 1234567890
|
67
67
|
Select region EU (Frankfurt)
|
@@ -313,6 +313,10 @@ part of `VpcStack`. The second line defines the name of the module, in this case
|
|
313
313
|
`Main`. The code beteen `included do` and `end` is the implementation of this
|
314
314
|
module.
|
315
315
|
|
316
|
+
Adding a new stack is trivial: Go to the root folder of the project and type
|
317
|
+
`rubycfn stack`. This will prompt you for a stack name (do not include the 'stack' keyword)
|
318
|
+
and it will generate the stack for you.
|
319
|
+
|
316
320
|
## AWS Intrinsic functions
|
317
321
|
|
318
322
|
You can Ref by postpending the .ref method to any string or hash, e.g. :foobar.ref
|
data/bin/rubycfn
CHANGED
@@ -10,29 +10,36 @@ require_relative "../lib/cli_methods"
|
|
10
10
|
|
11
11
|
# rubocop:disable Style/AndOr
|
12
12
|
if ARGV.first || (ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?)) # rubocop:disable Style/Not
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# rubocop:enable Style/AndOr
|
18
|
-
contents = []
|
19
|
-
ARGF.each_line do |line|
|
20
|
-
contents.push(line)
|
21
|
-
end
|
22
|
-
contents = contents.join("\n")
|
23
|
-
else
|
24
|
-
raise "File #{ARGV.first} not found!" unless File.file?(ARGV.first)
|
25
|
-
contents = File.read(ARGV.first)
|
13
|
+
if ARGV.class == Array && ARGV.first == "stack"
|
14
|
+
case ARGV.first
|
15
|
+
when "stack"
|
16
|
+
scaffold_stack
|
26
17
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
else
|
19
|
+
require "rubycfn"
|
20
|
+
require "active_support/concern"
|
21
|
+
module RubycfnStack
|
22
|
+
if ARGF.filename != "-" or (not STDIN.tty? and not STDIN.closed?) # rubocop:disable Style/Not
|
23
|
+
# rubocop:enable Style/AndOr
|
24
|
+
contents = []
|
25
|
+
ARGF.each_line do |line|
|
26
|
+
contents.push(line)
|
27
|
+
end
|
28
|
+
contents = contents.join("\n")
|
29
|
+
else
|
30
|
+
raise "File #{ARGV.first} not found!" unless File.file?(ARGV.first)
|
31
|
+
contents = File.read(ARGV.first)
|
32
|
+
end
|
33
|
+
extend ActiveSupport::Concern
|
34
|
+
include Rubycfn
|
35
|
+
included do
|
36
|
+
eval(contents) # rubocop:disable Security/Eval
|
37
|
+
end
|
31
38
|
end
|
39
|
+
cfn = include RubycfnStack # rubocop:disable Style/MixinUsage
|
40
|
+
puts cfn.render_template
|
41
|
+
exit
|
32
42
|
end
|
33
|
-
cfn = include RubycfnStack # rubocop:disable Style/MixinUsage
|
34
|
-
puts cfn.render_template
|
35
|
-
exit
|
36
43
|
end
|
37
44
|
|
38
45
|
path = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
@@ -72,7 +79,7 @@ dotenv_test = render(".env.test", { name: project_name }, path)
|
|
72
79
|
dotenv_production = render(".env.production", { name: project_name }, path)
|
73
80
|
dotenv_rspec = render(".env.rspec", { name: project_name }, path)
|
74
81
|
ecs_stack = render("ecs_stack.rb", {}, path)
|
75
|
-
ecs_stack_concern = render("
|
82
|
+
ecs_stack_concern = render("ecs_stack_concern.rb", { name: project_name }, path)
|
76
83
|
gemfile = render("Gemfile", { version: Rubycfn::VERSION }, path)
|
77
84
|
gitignore = render(".gitignore", {}, path)
|
78
85
|
global_variables = render("global_variables.rb", { name: project_name.downcase }, path)
|
data/lib/cli_methods.rb
CHANGED
@@ -50,3 +50,22 @@ def rubycfn_structure(project_name)
|
|
50
50
|
project_name + "/spec/lib"
|
51
51
|
]
|
52
52
|
end
|
53
|
+
|
54
|
+
def scaffold_stack
|
55
|
+
puts rubycfn_banner(Rubycfn::VERSION)
|
56
|
+
raise "Run `rubycfn stack` from project root folder" unless File.file? "lib/stacks/parent_stack/parent.rb"
|
57
|
+
prompt = TTY::Prompt.new
|
58
|
+
stack_name = prompt.ask("Stack name?", default: "application") do |q|
|
59
|
+
q.validate(/^([a-zA-Z]*)$/, "Invalid stack name")
|
60
|
+
end
|
61
|
+
stack_name = "#{stack_name.downcase}_stack"
|
62
|
+
raise "Stack already exists" if File.file? "lib/stacks/#{stack_name}.rb"
|
63
|
+
path = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
64
|
+
new_stack = render("new_stack.rb", { stack_name: stack_name.split("_").collect(&:capitalize).join }, path)
|
65
|
+
new_concern = render("new_concern.rb", { stack_name: stack_name.split("_").collect(&:capitalize).join }, path)
|
66
|
+
File.open("lib/stacks/#{stack_name}.rb", "w") { |file| file.write(new_stack) }
|
67
|
+
FileUtils.mkdir_p "lib/stacks/#{stack_name}"
|
68
|
+
File.open("lib/stacks/#{stack_name}/my_module.rb", "w") { |file| file.write(new_concern) }
|
69
|
+
puts "Created stack. Don't forget to add it to lib/stacks/parent_stack/parent.rb !"
|
70
|
+
exit
|
71
|
+
end
|
data/lib/monkeypatch.rb
CHANGED
@@ -4,6 +4,15 @@ class Symbol
|
|
4
4
|
to_s.split("_").map(&:capitalize).join
|
5
5
|
end
|
6
6
|
|
7
|
+
def get_output(attr)
|
8
|
+
attr = attr.class == String ? attr : attr.to_s.split("_").map(&:capitalize).join
|
9
|
+
{
|
10
|
+
"Fn::GetAtt": [
|
11
|
+
to_s.split("_").map(&:capitalize).join, "Outputs.#{attr}"
|
12
|
+
]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
7
16
|
def ref(attr = nil)
|
8
17
|
unless attr
|
9
18
|
return { Ref: to_s.split("_").map(&:capitalize).join }
|
@@ -44,6 +53,15 @@ class String
|
|
44
53
|
split("_").map(&:capitalize).join
|
45
54
|
end
|
46
55
|
|
56
|
+
def get_output(attr)
|
57
|
+
attr = attr.class == String ? attr : attr.to_s.split("_").map(&:capitalize).join
|
58
|
+
{
|
59
|
+
"Fn::GetAtt": [
|
60
|
+
to_s.split("_").map(&:capitalize).join, "Outputs.#{attr}"
|
61
|
+
]
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
47
65
|
def ref(attr = nil)
|
48
66
|
unless attr
|
49
67
|
return { Ref: self }
|
data/lib/rubycfn/version.rb
CHANGED
data/lib/rubycfn.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Rubycfn RubyCFN is a light-weight CloudFormation DSL
|
2
2
|
require "active_support/concern"
|
3
|
+
require "erb"
|
3
4
|
require "json"
|
4
5
|
require "neatjson"
|
5
6
|
require "rubycfn/version"
|
@@ -125,6 +126,7 @@ module Rubycfn
|
|
125
126
|
arguments[:required] ||= false
|
126
127
|
arguments[:global] ||= false
|
127
128
|
arguments[:filter] ||= nil
|
129
|
+
arguments[:template] ||= nil
|
128
130
|
|
129
131
|
if arguments[:value].empty?
|
130
132
|
arguments[:value] = arguments[:default]
|
@@ -139,6 +141,10 @@ module Rubycfn
|
|
139
141
|
arguments[:value] = send(arguments[:filter], arguments[:value])
|
140
142
|
end
|
141
143
|
|
144
|
+
if arguments[:template]
|
145
|
+
arguments[:value] = ERB.new("#{File.open(arguments[:template]).read}").result(binding)
|
146
|
+
end
|
147
|
+
|
142
148
|
res = {
|
143
149
|
"#{name}": arguments[:value]
|
144
150
|
}
|
@@ -292,7 +298,7 @@ module Rubycfn
|
|
292
298
|
TOPLEVEL_BINDING.eval("@depends_on = []")
|
293
299
|
TOPLEVEL_BINDING.eval("@description = ''")
|
294
300
|
TOPLEVEL_BINDING.eval("@transform = ''")
|
295
|
-
JSON.pretty_generate(skeleton.recursive_compact).gsub("<emptyString>","")
|
301
|
+
JSON.pretty_generate(skeleton.recursive_compact).gsub("<emptyString>", "")
|
296
302
|
end
|
297
303
|
end
|
298
304
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module <%= stack_name %>
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
include Rubycfn
|
4
|
+
|
5
|
+
included do
|
6
|
+
include Concerns::GlobalVariables
|
7
|
+
include Concerns::SharedMethods
|
8
|
+
include <%= stack_name %>::MyModule
|
9
|
+
|
10
|
+
description generate_stack_description("<%= stack_name %>")
|
11
|
+
end
|
12
|
+
end
|
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.4.
|
4
|
+
version: 0.4.6
|
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-10-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neatjson
|
@@ -297,6 +297,8 @@ files:
|
|
297
297
|
- templates/helpers.rb.erb
|
298
298
|
- templates/main.rb.erb
|
299
299
|
- templates/main_aws_helper.rb.erb
|
300
|
+
- templates/new_concern.rb.erb
|
301
|
+
- templates/new_stack.rb.erb
|
300
302
|
- templates/parent_stack_spec.rb.erb
|
301
303
|
- templates/project_concern.rb.erb
|
302
304
|
- templates/project_stack.rb.erb
|