Class: Lono::Seed::Base
Instance Method Summary
collapse
#create_service_linked_role
#template_param_convention
#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts
#find_stack, #rollback_complete?, #stack_exists?, #testing_update?
#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root
Constructor Details
#initialize(blueprint, options) ⇒ Base
29
30
31
32
|
# File 'lib/lono/seed/base.rb', line 29
def initialize(blueprint, options)
@blueprint, @options = blueprint, options
@template, @param = template_param_convention(options)
end
|
Instance Method Details
#check_dsl_type! ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/lono/seed/base.rb', line 95
def check_dsl_type!
dsl_type = template_type == 'dsl'
unless dsl_type
puts "Detected template_type: #{template_type}"
puts "lono seed only supports dsl template types currently."
exit 1
end
end
|
#create_param_file(app_template_path) ⇒ Object
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
|
# File 'lib/lono/seed/base.rb', line 62
def create_param_file(app_template_path)
parameters = parameters(app_template_path)
lines = []
required = required(parameters)
lines << "# Required parameters:" unless required.empty?
required.each do |name, data|
example = description_example(data["Description"])
lines << "#{name}=#{example}"
end
optional = optional(parameters)
lines << "# Optional parameters:" unless optional.empty?
optional.each do |name, data|
value = default_value(data)
lines << "# #{name}=#{value}"
end
if lines.empty?
puts "Template has no parameters."
return
end
content = lines.join("\n") + "\n"
dest_path = "configs/#{@blueprint}/params/#{Lono.env}.txt" create_file(dest_path, content) end
|
#create_params ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/lono/seed/base.rb', line 43
def create_params
return unless params
path = "#{Lono.config.templates_path}/#{@blueprint}.rb"
if File.exist?(path)
create_param_file(path)
end
end
|
#create_variables ⇒ Object
89
90
91
92
93
|
# File 'lib/lono/seed/base.rb', line 89
def create_variables
return unless variables
dest_path = "configs/#{@blueprint}/variables/#{Lono.env}.rb"
create_file(dest_path, variables) end
|
#default_value(data) ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/lono/seed/base.rb', line 135
def default_value(data)
value = data["Default"]
if value.nil? || value == ''
description_example(data["Description"])
else
value
end
end
|
#description_example(description) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/lono/seed/base.rb', line 127
def description_example(description)
default = ''
return default unless description
md = description.match(/(Example|IE): (.*)/)
return default unless md
md[2]
end
|
#finish ⇒ Object
114
|
# File 'lib/lono/seed/base.rb', line 114
def finish; end
|
#optional(parameters) ⇒ Object
157
158
159
|
# File 'lib/lono/seed/base.rb', line 157
def optional(parameters)
parameters.select { |logical_id, p| !p["Default"].nil? } end
|
#parameters(app_template_path) ⇒ Object
146
147
148
149
150
|
# File 'lib/lono/seed/base.rb', line 146
def parameters(app_template_path)
builder = Lono::Template::Dsl::Builder.new(app_template_path, @blueprint, quiet: false)
template = builder.template
template["Parameters"] || []
end
|
#params ⇒ Object
58
59
60
|
# File 'lib/lono/seed/base.rb', line 58
def params
true
end
|
#required(parameters) ⇒ Object
153
154
155
|
# File 'lib/lono/seed/base.rb', line 153
def required(parameters)
parameters.select { |logical_id, p| p["Default"].nil? } end
|
#run ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/lono/seed/base.rb', line 34
def run
check_dsl_type!
setup
self.destination_root = Dir.pwd create_params
create_variables
finish
end
|
#setup ⇒ Object
113
|
# File 'lib/lono/seed/base.rb', line 113
def setup; end
|
#template_type ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/lono/seed/base.rb', line 104
def template_type
blueprint_root = find_blueprint_root(@blueprint)
meta_config = "#{blueprint_root}/.meta/config.yml"
return false unless File.exist?(meta_config)
meta = YAML.load_file(meta_config)
meta['template_type']
end
|
#variables ⇒ Object
Meant to be overriden by subclass Return String with contents of variables file.
118
119
120
|
# File 'lib/lono/seed/base.rb', line 118
def variables
false
end
|
#write(path, content) ⇒ Object
122
123
124
125
|
# File 'lib/lono/seed/base.rb', line 122
def write(path, content)
FileUtils.mkdir_p(File.dirname(path))
IO.write(path, content)
end
|