lono 6.0.1 → 6.1.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/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/lib/lono/cfn.rb +3 -2
- data/lib/lono/cfn/base.rb +11 -21
- data/lib/lono/cli.rb +1 -0
- data/lib/lono/config_location.rb +93 -0
- data/lib/lono/param.rb +1 -0
- data/lib/lono/param/generator.rb +41 -93
- data/lib/lono/template/context/loader.rb +7 -38
- data/lib/lono/template/dsl/builder/fn.rb +7 -3
- data/lib/lono/template/dsl/builder/helpers.rb +1 -66
- data/lib/lono/template/dsl/builder/helpers/core_helper.rb +76 -0
- data/lib/lono/template/dsl/builder/helpers/param_helper.rb +29 -9
- data/lib/lono/template/dsl/builder/syntax.rb +1 -1
- data/lib/lono/template/generator.rb +4 -4
- data/lib/lono/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00b82bf7f6fe03723b4819ebe0852b507d141654905d9fab6be7755d5bda22d2
|
4
|
+
data.tar.gz: 20552ff66d7d729e114c1539f1f5e8df2956b746c444a3bc3ce699021b46ce28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e408ef09601c5472db878a329968fa4da5bca6f14980cc7adf56fee36895ae5a7312ebe4ebf8bbb969b12dcdeac8ef01b9bf9f542149b4c230ed6e271678a804
|
7
|
+
data.tar.gz: 437bb6232f2ab9b605c7653cf3da3fba70ab93d8a4e6bc201598a2917eac4a365612a2fb66a1359a71fbc38c3fc30a32b4f25b4ebc9f65793f8ad1d4ffd2297c
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [6.1.0]
|
7
|
+
- #17 big improvements to how the configs lookup logic happens: simpler and easier to understand
|
8
|
+
- variables lookup strategy is same as params
|
9
|
+
- `--config` option sets both `--param` and `--variable`
|
10
|
+
- also account for stack name as part of conventional lookup - big win to help provide consistent and organized configs files.
|
11
|
+
- #18 parameter(name, Conditional: true)
|
12
|
+
- ref(name, Conditional: true)
|
13
|
+
- deprecated `conditional_parameter`, `optional_ref`
|
14
|
+
- deprecated `tags` helper, use `tag_list` instead
|
15
|
+
- cleanup: organize CoreHelper
|
16
|
+
|
6
17
|
## [6.0.1]
|
7
18
|
- #14 restructure dsl methods are available in variables definition
|
8
19
|
- #15 fix Type camelize bug
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ resource("Instance", "AWS::EC2::Instance",
|
|
54
54
|
UserData: base64(user_data("bootstrap.sh"))
|
55
55
|
)
|
56
56
|
resource("SecurityGroup", "AWS::EC2::SecurityGroup",
|
57
|
-
|
57
|
+
GroupDescription: "demo security group",
|
58
58
|
)
|
59
59
|
|
60
60
|
output("Instance")
|
data/lib/lono/cfn.rb
CHANGED
@@ -5,15 +5,16 @@ module Lono
|
|
5
5
|
|
6
6
|
base_options = Proc.new do
|
7
7
|
# common to create, update and deploy
|
8
|
+
option :config, aliases: "c", desc: "override convention and specify both the param and variable file to use"
|
8
9
|
option :blueprint, desc: "override convention and specify the template file to use"
|
9
10
|
option :capabilities, type: :array, desc: "iam capabilities. Ex: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
|
10
11
|
option :iam, type: :boolean, desc: "Shortcut for common IAM capabilities: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
|
11
12
|
option :lono, type: :boolean, desc: "invoke lono to generate CloudFormation templates", default: true
|
12
|
-
option :param, desc: "override convention and specify the param file to use"
|
13
|
+
option :param, aliases: "p", desc: "override convention and specify the param file to use"
|
13
14
|
option :rollback, type: :boolean, desc: "rollback", default: true
|
14
15
|
option :tags, type: :hash, desc: "Tags for the stack. IE: name:api-web owner:bob"
|
15
16
|
option :template, desc: "override convention and specify the template file to use"
|
16
|
-
option :variable, desc: "override convention and specify the variable file to use"
|
17
|
+
option :variable, aliases: "v", desc: "override convention and specify the variable file to use"
|
17
18
|
end
|
18
19
|
wait_option = Proc.new do
|
19
20
|
option :wait, type: :boolean, desc: "Wait for stack operation to complete.", default: true
|
data/lib/lono/cfn/base.rb
CHANGED
@@ -19,9 +19,6 @@ class Lono::Cfn
|
|
19
19
|
@blueprint = options[:blueprint] || remove_suffix(@stack_name)
|
20
20
|
@template, @param = template_param_convention(options)
|
21
21
|
|
22
|
-
# Add template and param to options because used later for Lono::Param::Generator
|
23
|
-
@options[:blueprint], @options[:template], @options[:param] = @blueprint, @template, @param
|
24
|
-
|
25
22
|
set_blueprint_root(@blueprint)
|
26
23
|
|
27
24
|
@template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
|
@@ -149,27 +146,10 @@ class Lono::Cfn
|
|
149
146
|
param_generator.generate # Writes the json file in CamelCase keys format
|
150
147
|
@@generate_all = param_generator.params # Returns Array in underscore keys format
|
151
148
|
|
152
|
-
# At this point we have the info about params path used so we can display it.
|
153
|
-
# We display other useful info here too so it's together logically.
|
154
|
-
unless @options[:mute_using]
|
155
|
-
puts "Using template: #{pretty_path(@template_path)}"
|
156
|
-
param_generator.puts_param_message(:base)
|
157
|
-
param_generator.puts_param_message(:env)
|
158
|
-
end
|
159
|
-
|
160
149
|
check_for_errors
|
161
150
|
@@generate_all
|
162
151
|
end
|
163
152
|
|
164
|
-
def param_generator
|
165
|
-
generator_options = {
|
166
|
-
regenerate: false,
|
167
|
-
allow_not_exists: true
|
168
|
-
}.merge(@options)
|
169
|
-
Lono::Param::Generator.new(@blueprint, generator_options)
|
170
|
-
end
|
171
|
-
memoize :param_generator
|
172
|
-
|
173
153
|
def ensure_s3_bucket_exist
|
174
154
|
bucket = Lono::S3::Bucket.new
|
175
155
|
return if bucket.exist?
|
@@ -185,8 +165,18 @@ class Lono::Cfn
|
|
185
165
|
end
|
186
166
|
|
187
167
|
def generate_templates
|
188
|
-
Lono::Template::Generator.new(@blueprint, @options).run
|
168
|
+
Lono::Template::Generator.new(@blueprint, @options.merge(stack: @stack_name)).run
|
169
|
+
end
|
170
|
+
|
171
|
+
def param_generator
|
172
|
+
generator_options = {
|
173
|
+
regenerate: true,
|
174
|
+
allow_not_exists: true,
|
175
|
+
}.merge(@options)
|
176
|
+
generator_options[:stack] ||= @stack_name || @blueprint
|
177
|
+
Lono::Param::Generator.new(@blueprint, generator_options)
|
189
178
|
end
|
179
|
+
memoize :param_generator
|
190
180
|
|
191
181
|
def post_process_templates
|
192
182
|
Lono::Template::PostProcessor.new(@blueprint, @options).run
|
data/lib/lono/cli.rb
CHANGED
@@ -18,6 +18,7 @@ module Lono
|
|
18
18
|
long_desc Help.text(:generate)
|
19
19
|
option :clean, type: :boolean, default: false, desc: "remove all output files before generating"
|
20
20
|
option :quiet, type: :boolean, desc: "silence the output"
|
21
|
+
option :stack, desc: "stack name. defaults to blueprint name."
|
21
22
|
def generate(blueprint=nil)
|
22
23
|
Blueprint::Find.one_or_all(blueprint).each do |b|
|
23
24
|
Script::Build.new(b, options).run
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Lono
|
2
|
+
class ConfigLocation
|
3
|
+
extend Memoist
|
4
|
+
include Lono::Conventions
|
5
|
+
|
6
|
+
def initialize(config, options={}, env=Lono.env, root=Lono.root)
|
7
|
+
# config can be params or variables
|
8
|
+
@config, @options, @root, @env = config, options, root, env
|
9
|
+
|
10
|
+
@stack = options[:stack]
|
11
|
+
@blueprint = options[:blueprint] || @stack
|
12
|
+
@template, @param = template_param_convention(options)
|
13
|
+
|
14
|
+
@requested = determine_requested
|
15
|
+
end
|
16
|
+
|
17
|
+
def lookup
|
18
|
+
levels = []
|
19
|
+
levels += direct_levels
|
20
|
+
# Standard lookup paths
|
21
|
+
template_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@template}/#{@requested}"
|
22
|
+
env_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}/#{@requested}"
|
23
|
+
config_level = "#{@root}/configs/#{@blueprint}/#{@config}/#{@requested}"
|
24
|
+
generic_env = "#{@root}/configs/#{@blueprint}/#{@config}/#{@env}"
|
25
|
+
levels += [template_level, env_level, config_level, generic_env]
|
26
|
+
|
27
|
+
print_levels(levels)
|
28
|
+
|
29
|
+
found = levels.find do |level|
|
30
|
+
requested_file(level)
|
31
|
+
end
|
32
|
+
if found
|
33
|
+
file = requested_file(found)
|
34
|
+
using_message(file, @env)
|
35
|
+
file
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def direct_levels
|
40
|
+
[
|
41
|
+
@requested, # IE: absolute full path
|
42
|
+
"#{@root}/#{@requested}", # IE : relative path within lono project
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
def lookup_base
|
47
|
+
base = "#{@root}/configs/#{@blueprint}/#{@config}/base"
|
48
|
+
file = requested_file(base)
|
49
|
+
if file
|
50
|
+
using_message(file, "base")
|
51
|
+
file
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_levels(levels)
|
56
|
+
return unless ENV["LONO_DEBUG_CONFIG"]
|
57
|
+
puts "levels:"
|
58
|
+
pp levels
|
59
|
+
end
|
60
|
+
|
61
|
+
@@using_message_displayed = {}
|
62
|
+
def using_message(file, type)
|
63
|
+
return if @@using_message_displayed[file]
|
64
|
+
|
65
|
+
pretty_file = file.sub("#{Lono.root}/", "")
|
66
|
+
puts "Using #{@config} for #{type}: #{pretty_file}"
|
67
|
+
|
68
|
+
@@using_message_displayed[file] = true
|
69
|
+
end
|
70
|
+
|
71
|
+
# Some switching logic between variable and param below
|
72
|
+
|
73
|
+
def determine_requested
|
74
|
+
# param is usually set from the convention. when set from convention stack name takes higher precedence
|
75
|
+
config_key = @config.singularize.to_sym # param or variable
|
76
|
+
from_convention = !@options[config_key] && !@options[:config]
|
77
|
+
if from_convention
|
78
|
+
@options[:stack]
|
79
|
+
else
|
80
|
+
@options[config_key] || @options[:config] || @options[:stack]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def requested_file(path)
|
85
|
+
# List of paths to consider from initial path provided
|
86
|
+
paths = @config == "params" ?
|
87
|
+
[path, "#{path}.txt", "#{path}.sh"] :
|
88
|
+
[path, "#{path}.rb"]
|
89
|
+
paths.find { |p| File.file?(p) }
|
90
|
+
end
|
91
|
+
memoize :requested_file
|
92
|
+
end
|
93
|
+
end
|
data/lib/lono/param.rb
CHANGED
@@ -6,6 +6,7 @@ module Lono
|
|
6
6
|
|
7
7
|
desc "generate", "Generate parameter output files to `output/params`."
|
8
8
|
long_desc Lono::Help.text("param/generate")
|
9
|
+
option :stack, desc: "stack name. defaults to blueprint name."
|
9
10
|
def generate(blueprint=nil)
|
10
11
|
Blueprint::Find.one_or_all(blueprint).each do |b|
|
11
12
|
Generator.new(b, options).generate
|
data/lib/lono/param/generator.rb
CHANGED
@@ -5,107 +5,25 @@ class Lono::Param
|
|
5
5
|
|
6
6
|
attr_reader :env_path, :base_path # set when generate is called
|
7
7
|
def initialize(blueprint, options={})
|
8
|
-
|
8
|
+
# dup because we're modifying the Thor frozen hash
|
9
|
+
# HashWithIndifferentAccess.new again because .dup changes it to a normal Hash
|
10
|
+
@blueprint, @options = blueprint, ActiveSupport::HashWithIndifferentAccess.new(options.dup)
|
11
|
+
@options[:stack] ||= @blueprint
|
9
12
|
set_blueprint_root(@blueprint)
|
10
13
|
@template, @param = template_param_convention(options)
|
11
14
|
end
|
12
15
|
|
13
|
-
def puts_param_message(type)
|
14
|
-
path = send("#{type}_path")
|
15
|
-
return unless path
|
16
|
-
if param_file?(path)
|
17
|
-
pretty_path = path.sub("#{Lono.root}/",'')
|
18
|
-
puts "Using param for #{type}: #{pretty_path}".color(:yellow)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# Lookup precedence:
|
23
|
-
#
|
24
|
-
# configs/BLUEPRINT/params/development/TEMPLATE/PARAM.txt
|
25
|
-
# configs/BLUEPRINT/params/development/PARAM.txt
|
26
|
-
# configs/BLUEPRINT/params/development.txt
|
27
|
-
#
|
28
|
-
def lookup_param_file(root: Lono.root, env: Lono.env)
|
29
|
-
# The docs conver direct_absolute_form and direct_relative_form as the "Direct Form"
|
30
|
-
unless env == "base"
|
31
|
-
direct_absolute_form = @param # user provided the absolute full path
|
32
|
-
direct_relative_form = "#{root}/#{@param}" # user provided the full path within the lono project
|
33
|
-
direct_env_form = "#{root}/configs/#{@blueprint}/params/#{env}/#{@param}" # direct lookup is simple
|
34
|
-
direct_simple_form = "#{root}/configs/#{@blueprint}/params/#{@param}" # direct lookup is simple
|
35
|
-
end
|
36
|
-
long_form = "#{root}/configs/#{@blueprint}/params/#{env}/#{@template}/#{@param}"
|
37
|
-
medium_form = "#{root}/configs/#{@blueprint}/params/#{env}/#{@param}"
|
38
|
-
short_form = "#{root}/configs/#{@blueprint}/params/#{env}"
|
39
|
-
|
40
|
-
if ENV['LONO_DEBUG_PARAM']
|
41
|
-
puts "Lono.blueprint_root #{Lono.blueprint_root}"
|
42
|
-
puts "direct_absolute_form #{direct_absolute_form}"
|
43
|
-
puts "direct_relative_form #{direct_relative_form}"
|
44
|
-
puts "direct_env_form #{direct_env_form}"
|
45
|
-
puts "direct_simple_form #{direct_simple_form}"
|
46
|
-
puts "long_form #{long_form}"
|
47
|
-
puts "medium_form #{medium_form}"
|
48
|
-
puts "short_form #{short_form}"
|
49
|
-
end
|
50
|
-
|
51
|
-
unless env == "base"
|
52
|
-
return param_file(direct_absolute_form) if param_file?(direct_absolute_form)
|
53
|
-
return param_file(direct_relative_form) if param_file?(direct_relative_form)
|
54
|
-
return param_file(direct_env_form) if param_file?(direct_env_form) # consider this first its simple and direct but is scope to env so it's more specific
|
55
|
-
return param_file(direct_simple_form) if param_file?(direct_simple_form) # consider this first its simple and direct but is scope to env so it's more specific
|
56
|
-
end
|
57
|
-
return param_file(long_form) if param_file?(long_form) # consider this first because its more explicit
|
58
|
-
|
59
|
-
# All 3 are the same
|
60
|
-
# Also, blueprint and template the same and explicitly specified param
|
61
|
-
if @blueprint == @template
|
62
|
-
return param_file(medium_form) if param_file?(medium_form) # higher precedence between longer but short form should be encouraged
|
63
|
-
return param_file(short_form) if param_file?(short_form)
|
64
|
-
return # cannot find a param file
|
65
|
-
end
|
66
|
-
|
67
|
-
# Only template and param are the same
|
68
|
-
if @template == @param
|
69
|
-
return param_file(medium_form) if param_file?(medium_form) # only consider medium form
|
70
|
-
return # cannot find a param file
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Allows user to specify the .txt extension or not to.
|
75
|
-
# Also allows user to use other extensions like .sh if they are explicit about it.
|
76
|
-
def param_file?(path)
|
77
|
-
File.file?(path) || File.file?("#{path}.txt") || File.file?("#{path}.sh")
|
78
|
-
end
|
79
|
-
|
80
|
-
def param_file(path)
|
81
|
-
return path if File.file?(path)
|
82
|
-
return "#{path}.txt" if File.file?("#{path}.txt")
|
83
|
-
return "#{path}.sh" if File.file?("#{path}.sh")
|
84
|
-
end
|
85
|
-
|
86
|
-
def lookup_paths
|
87
|
-
@base_path = lookup_param_file(env: "base")
|
88
|
-
@env_path = lookup_param_file(env: Lono.env)
|
89
|
-
|
90
|
-
if ENV['LONO_DEBUG_PARAM']
|
91
|
-
puts " @base_path #{@base_path.inspect}"
|
92
|
-
puts " @env_path #{@env_path.inspect}"
|
93
|
-
end
|
94
|
-
|
95
|
-
[@base_path, @env_path]
|
96
|
-
end
|
97
|
-
|
98
16
|
def generate
|
99
17
|
puts "Generating parameter files for blueprint #{@blueprint.color(:green)}:"
|
100
18
|
|
101
|
-
@base_path, @env_path =
|
19
|
+
@base_path, @env_path = config_locations
|
102
20
|
|
103
21
|
return unless @base_path || @env_path
|
104
22
|
|
105
23
|
# useful option for lono cfn, since some templates dont require params
|
106
|
-
return if @options[:allow_not_exists] && !
|
24
|
+
return if @options[:allow_not_exists] && !params_exist?
|
107
25
|
|
108
|
-
if
|
26
|
+
if params_exist?
|
109
27
|
contents = process_erb
|
110
28
|
data = convert_to_cfn_format(contents)
|
111
29
|
json = JSON.pretty_generate(data)
|
@@ -121,21 +39,51 @@ class Lono::Param
|
|
121
39
|
json
|
122
40
|
end
|
123
41
|
|
42
|
+
def config_locations
|
43
|
+
@base_path = lookup_config_location("base")
|
44
|
+
@env_path = lookup_config_location(Lono.env)
|
45
|
+
|
46
|
+
if ENV['LONO_DEBUG_PARAM']
|
47
|
+
puts "LONO_DEBUG_PARAM enabled"
|
48
|
+
puts " @base_path #{@base_path.inspect}"
|
49
|
+
puts " @env_path #{@env_path.inspect}"
|
50
|
+
end
|
51
|
+
|
52
|
+
[@base_path, @env_path]
|
53
|
+
end
|
54
|
+
|
55
|
+
def lookup_config_location(env)
|
56
|
+
options = @options.clone
|
57
|
+
options[:blueprint] = @blueprint
|
58
|
+
options[:stack] ||= @blueprint
|
59
|
+
location = Lono::ConfigLocation.new("params", options, env)
|
60
|
+
env == "base" ? location.lookup_base : location.lookup
|
61
|
+
end
|
62
|
+
|
63
|
+
def puts_param_message(type)
|
64
|
+
path = send("#{type}_path")
|
65
|
+
return unless path
|
66
|
+
if param_file?(path)
|
67
|
+
pretty_path = path.sub("#{Lono.root}/",'')
|
68
|
+
puts "Using param for #{type}: #{pretty_path}".color(:yellow)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
124
72
|
# Checks both base and source path for existing of the param file.
|
125
73
|
# Example:
|
126
74
|
# params/base/mystack.txt - base path
|
127
75
|
# params/production/mystack.txt - source path
|
128
|
-
def
|
76
|
+
def params_exist?
|
129
77
|
@base_path && File.exist?(@base_path) ||
|
130
78
|
@env_path && File.exist?(@env_path)
|
131
79
|
end
|
132
80
|
|
133
81
|
# useful for when calling CloudFormation via the aws-sdk gem
|
134
82
|
def params(casing = :underscore)
|
135
|
-
@base_path, @env_path =
|
83
|
+
@base_path, @env_path = config_locations
|
136
84
|
|
137
85
|
# useful option for lono cfn
|
138
|
-
return {} if @options[:allow_not_exists] && !
|
86
|
+
return {} if @options[:allow_not_exists] && !params_exist?
|
139
87
|
|
140
88
|
contents = process_erb
|
141
89
|
convert_to_cfn_format(contents, casing)
|
@@ -206,7 +154,7 @@ class Lono::Param
|
|
206
154
|
# Now build up the aws json format for parameters
|
207
155
|
params = []
|
208
156
|
data.each do |key,value|
|
209
|
-
param = if value == "use_previous_value"
|
157
|
+
param = if value == "use_previous_value" || value == "UsePreviousValue"
|
210
158
|
{
|
211
159
|
"ParameterKey": key,
|
212
160
|
"UsePreviousValue": true
|
@@ -8,36 +8,12 @@ class Lono::Template::Context
|
|
8
8
|
# config/variables/development.rb - will override any variables in base.rb
|
9
9
|
#
|
10
10
|
def load_variables
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
if ENV['LONO_DEBUG_VARIABLE']
|
18
|
-
puts "direct_absolute_form: #{direct_absolute_form.inspect}"
|
19
|
-
puts "direct_relative_form: #{direct_relative_form.inspect}"
|
20
|
-
puts "conventional_form: #{conventional_form.inspect}"
|
21
|
-
end
|
22
|
-
|
23
|
-
load_variables_file(variable_file(direct_absolute_form)) if variable_file?(direct_absolute_form)
|
24
|
-
load_variables_file(variable_file(direct_relative_form)) if variable_file?(direct_relative_form)
|
25
|
-
load_variables_file(conventional_form) if variable_file?(conventional_form)
|
26
|
-
end
|
27
|
-
|
28
|
-
def variable_file?(path)
|
29
|
-
return if path.nil?
|
30
|
-
return path if File.file?(path) # direct lookup with .rb extension
|
31
|
-
return "#{path}.rb" if File.file?("#{path}.rb") # direct lookup without .rb extension
|
32
|
-
end
|
33
|
-
|
34
|
-
def variable_file(path)
|
35
|
-
return path if File.file?(path)
|
36
|
-
return "#{path}.rb" if File.file?("#{path}.rb")
|
37
|
-
end
|
38
|
-
|
39
|
-
def project_path(name)
|
40
|
-
"#{Lono.root}/configs/#{@blueprint}/variables/#{name}.rb"
|
11
|
+
options = @options.clone
|
12
|
+
options[:blueprint] = @blueprint
|
13
|
+
options[:stack] ||= @blueprint
|
14
|
+
location = Lono::ConfigLocation.new("variables", options, Lono.env)
|
15
|
+
evaluate_variables_file(location.lookup_base) if location.lookup_base
|
16
|
+
evaluate_variables_file(location.lookup) if location.lookup # config file
|
41
17
|
end
|
42
18
|
|
43
19
|
# Load the variables defined in config/variables/* to make available in the
|
@@ -56,15 +32,8 @@ class Lono::Template::Context
|
|
56
32
|
#
|
57
33
|
# NOTE: Only able to make instance variables avaialble with instance_eval,
|
58
34
|
# wasnt able to make local variables available.
|
59
|
-
def
|
60
|
-
# if File.exist?(path)
|
61
|
-
# puts "context.rb loading #{path}"
|
62
|
-
# else
|
63
|
-
# puts "context.rb file doesnt exist #{path}"
|
64
|
-
# end
|
65
|
-
|
35
|
+
def evaluate_variables_file(path)
|
66
36
|
return unless File.exist?(path)
|
67
|
-
|
68
37
|
instance_eval(IO.read(path), path)
|
69
38
|
end
|
70
39
|
|
@@ -67,9 +67,13 @@ class Lono::Template::Dsl::Builder
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# special cases
|
70
|
-
def ref(name)
|
70
|
+
def ref(name, options={})
|
71
71
|
name = name.to_s.camelize
|
72
|
-
|
72
|
+
if options[:Conditional] || options[:conditional]
|
73
|
+
if!("Has#{name}", ref(name), ref("AWS::NoValue"))
|
74
|
+
else
|
75
|
+
{ "Ref" => name }
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
# Examples:
|
@@ -78,7 +82,7 @@ class Lono::Template::Dsl::Builder
|
|
78
82
|
# get_attr(["logical_id", "attribute"])
|
79
83
|
def get_att(*item)
|
80
84
|
item = item.flatten
|
81
|
-
|
85
|
+
item.last.is_a?(Hash) ? item.pop : {}
|
82
86
|
|
83
87
|
# list is an Array
|
84
88
|
list = if item.size == 1
|
@@ -2,72 +2,7 @@
|
|
2
2
|
class Lono::Template::Dsl::Builder
|
3
3
|
module Helpers
|
4
4
|
extend Memoist
|
5
|
+
include CoreHelper
|
5
6
|
include ParamHelper
|
6
|
-
|
7
|
-
def tags(hash, casing: :camelize)
|
8
|
-
hash.map do |k,v|
|
9
|
-
k = k.to_s
|
10
|
-
k = case casing
|
11
|
-
when :camelize
|
12
|
-
k.camelize
|
13
|
-
when :underscore
|
14
|
-
k.underscore
|
15
|
-
when :dasherize
|
16
|
-
k.dasherize
|
17
|
-
else # leave alone
|
18
|
-
k
|
19
|
-
end
|
20
|
-
|
21
|
-
{Key: k, Value: v}
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def dimensions(hash, casing: :camelize)
|
26
|
-
tags(hash, casing: casing).map { |h|
|
27
|
-
h[:Name] = h.delete(:Key) || h.delete(:key)
|
28
|
-
h
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def content(path)
|
33
|
-
render_file(Lono.config.content_path, path)
|
34
|
-
end
|
35
|
-
|
36
|
-
def user_data(path)
|
37
|
-
render_file(Lono.config.user_data_path, path)
|
38
|
-
end
|
39
|
-
|
40
|
-
def render_file(folder, path)
|
41
|
-
path = "#{folder}/#{path}"
|
42
|
-
if File.exist?(path)
|
43
|
-
render_path(path)
|
44
|
-
else
|
45
|
-
message = "WARNING: path #{path} not found"
|
46
|
-
puts message.color(:yellow)
|
47
|
-
puts "Called from:"
|
48
|
-
puts caller[2]
|
49
|
-
message
|
50
|
-
end
|
51
|
-
end
|
52
|
-
memoize :render_file
|
53
|
-
|
54
|
-
def render_path(path)
|
55
|
-
RenderMePretty.result(path, context: self)
|
56
|
-
end
|
57
|
-
|
58
|
-
def s3_bucket
|
59
|
-
Lono::S3::Bucket.name
|
60
|
-
end
|
61
|
-
|
62
|
-
def file_s3_key(name, options={})
|
63
|
-
Lono::AppFile::Registry.register(name, @blueprint, options)
|
64
|
-
"file://app/files/#{name}" # placeholder for post processing
|
65
|
-
end
|
66
|
-
alias_method :s3_key, :file_s3_key
|
67
|
-
|
68
|
-
def setting
|
69
|
-
Lono::Setting.new
|
70
|
-
end
|
71
|
-
memoize :setting
|
72
7
|
end
|
73
8
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Lono::Template::Dsl::Builder::Helpers
|
2
|
+
module CoreHelper
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def tags(hash, casing: :camelize)
|
6
|
+
puts "DEPRECATED: tags helper will be removed. Use tag_list instead."
|
7
|
+
tag_list(hash, casing: casing)
|
8
|
+
end
|
9
|
+
|
10
|
+
def tag_list(hash, casing: :camelize)
|
11
|
+
hash.map do |k,v|
|
12
|
+
k = k.to_s
|
13
|
+
k = case casing
|
14
|
+
when :camelize
|
15
|
+
k.camelize
|
16
|
+
when :underscore
|
17
|
+
k.underscore
|
18
|
+
when :dasherize
|
19
|
+
k.dasherize
|
20
|
+
else # leave alone
|
21
|
+
k
|
22
|
+
end
|
23
|
+
|
24
|
+
{Key: k, Value: v}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def dimensions(hash, casing: :camelize)
|
29
|
+
tags(hash, casing: casing).map { |h|
|
30
|
+
h[:Name] = h.delete(:Key) || h.delete(:key)
|
31
|
+
h
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def content(path)
|
36
|
+
render_file(Lono.config.content_path, path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_data(path)
|
40
|
+
render_file(Lono.config.user_data_path, path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_file(folder, path)
|
44
|
+
path = "#{folder}/#{path}"
|
45
|
+
if File.exist?(path)
|
46
|
+
render_path(path)
|
47
|
+
else
|
48
|
+
message = "WARNING: path #{path} not found"
|
49
|
+
puts message.color(:yellow)
|
50
|
+
puts "Called from:"
|
51
|
+
puts caller[2]
|
52
|
+
message
|
53
|
+
end
|
54
|
+
end
|
55
|
+
memoize :render_file
|
56
|
+
|
57
|
+
def render_path(path)
|
58
|
+
RenderMePretty.result(path, context: self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def s3_bucket
|
62
|
+
Lono::S3::Bucket.name
|
63
|
+
end
|
64
|
+
|
65
|
+
def file_s3_key(name, options={})
|
66
|
+
Lono::AppFile::Registry.register(name, @blueprint, options)
|
67
|
+
"file://app/files/#{name}" # placeholder for post processing
|
68
|
+
end
|
69
|
+
alias_method :s3_key, :file_s3_key
|
70
|
+
|
71
|
+
def setting
|
72
|
+
Lono::Setting.new
|
73
|
+
end
|
74
|
+
memoize :setting
|
75
|
+
end
|
76
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
# Note: These are experimental helpers. Their interface may change or removed entirely.
|
2
2
|
module Lono::Template::Dsl::Builder::Helpers
|
3
3
|
module ParamHelper
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
# Decorate the parameter method to make smarter.
|
5
|
+
def parameter(*definition)
|
6
|
+
name, second, _ = definition
|
7
|
+
# medium form
|
8
|
+
if definition.size == 2 && second.is_a?(Hash) && second[:Conditional]
|
9
|
+
# Creates:
|
10
|
+
#
|
11
|
+
# 1. parameter
|
12
|
+
# 2. condition - used to make it optional
|
13
|
+
#
|
14
|
+
options = normalize_conditional_parameter_options(second)
|
15
|
+
super(name, options)
|
16
|
+
condition("Has#{name}", not!(equals(ref(name), "")))
|
17
|
+
else
|
18
|
+
super
|
19
|
+
end
|
13
20
|
end
|
14
21
|
|
15
22
|
# use long name to minimize method name collision
|
@@ -26,7 +33,20 @@ module Lono::Template::Dsl::Builder::Helpers
|
|
26
33
|
options
|
27
34
|
end
|
28
35
|
|
36
|
+
# Creates:
|
37
|
+
#
|
38
|
+
# 1. parameter
|
39
|
+
# 2. condition - used to make it optional
|
40
|
+
#
|
41
|
+
def conditional_parameter(name, options={})
|
42
|
+
puts "DEPRECATED: Will be removed. Instead use: parameter(name, Conditional: true)"
|
43
|
+
options = normalize_conditional_parameter_options(options)
|
44
|
+
parameter(name, options)
|
45
|
+
condition("Has#{name}", not!(equals(ref(name), "")))
|
46
|
+
end
|
47
|
+
|
29
48
|
def optional_ref(name)
|
49
|
+
puts "DEPRECATED: Will be removed. Instead use: ref(name, Conditional: true)"
|
30
50
|
if!("Has#{name}", ref(name), ref("AWS::NoValue"))
|
31
51
|
end
|
32
52
|
end
|
@@ -5,7 +5,7 @@ class Lono::Template
|
|
5
5
|
include Lono::Blueprint::Root
|
6
6
|
|
7
7
|
def initialize(blueprint, options={})
|
8
|
-
@blueprint, @options = blueprint, options
|
8
|
+
@blueprint, @options = blueprint, ActiveSupport::HashWithIndifferentAccess.new(options.dup)
|
9
9
|
@template = @options[:template] || @blueprint
|
10
10
|
Lono::ProjectChecker.check
|
11
11
|
set_blueprint_root(@blueprint)
|
@@ -13,11 +13,11 @@ class Lono::Template
|
|
13
13
|
|
14
14
|
def run
|
15
15
|
# Examples:
|
16
|
-
# Erb.new(b, options.
|
17
|
-
# Dsl.new(b, options.
|
16
|
+
# Erb.new(b, options.dup).run
|
17
|
+
# Dsl.new(b, options.dup).run
|
18
18
|
generator_class = "Lono::Template::#{template_type.classify}"
|
19
19
|
generator_class = Object.const_get(generator_class)
|
20
|
-
generator_class.new(@blueprint, @options
|
20
|
+
generator_class.new(@blueprint, @options).run
|
21
21
|
end
|
22
22
|
|
23
23
|
def template_type
|
data/lib/lono/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -486,6 +486,7 @@ files:
|
|
486
486
|
- lib/lono/completer/script.rb
|
487
487
|
- lib/lono/completer/script.sh
|
488
488
|
- lib/lono/completion.rb
|
489
|
+
- lib/lono/config_location.rb
|
489
490
|
- lib/lono/conventions.rb
|
490
491
|
- lib/lono/core.rb
|
491
492
|
- lib/lono/core/config.rb
|
@@ -555,6 +556,7 @@ files:
|
|
555
556
|
- lib/lono/template/dsl/builder/condition.rb
|
556
557
|
- lib/lono/template/dsl/builder/fn.rb
|
557
558
|
- lib/lono/template/dsl/builder/helpers.rb
|
559
|
+
- lib/lono/template/dsl/builder/helpers/core_helper.rb
|
558
560
|
- lib/lono/template/dsl/builder/helpers/param_helper.rb
|
559
561
|
- lib/lono/template/dsl/builder/mapping.rb
|
560
562
|
- lib/lono/template/dsl/builder/output.rb
|