Class: Jets::Cfn::Builders::BaseChildBuilder
- Inherits:
-
Object
- Object
- Jets::Cfn::Builders::BaseChildBuilder
show all
- Includes:
- Interface
- Defined in:
- lib/jets/cfn/builders/base_child_builder.rb
Instance Method Summary
collapse
Methods included from Interface
#add_description, #add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #post_process_template, #template, #text, #write
Constructor Details
The app_class is can be a controller, job or anonymous function class. IE: PostsController, HardJob
14
15
16
17
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 14
def initialize(app_class)
@app_class = app_class
@template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end
|
Instance Method Details
#add_class_iam_policy ⇒ Object
56
57
58
59
60
61
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 56
def add_class_iam_policy
return unless @app_class.build_class_iam?
resource = Jets::Resource::Iam::ClassRole.new(@app_class)
add_resource(resource)
end
|
#add_common_parameters ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 24
def add_common_parameters
common_parameters = Jets::Resource::ChildStack::CommonParameters.common_parameters
common_parameters.each do |k,_|
add_parameter(k, Description: k.to_s)
end
depends_on_params.each do |output_key, output_value|
desc = output_value.gsub("!GetAtt ", "") add_parameter(output_key, Description: desc)
end
end
|
#add_function(task) ⇒ Object
51
52
53
54
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 51
def add_function(task)
resource = Jets::Resource::Lambda::Function.new(task)
add_resource(resource)
end
|
#add_function_iam_policy(task) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 63
def add_function_iam_policy(task)
return unless task.build_function_iam?
resource = Jets::Resource::Iam::FunctionRole.new(task)
add_resource(resource)
end
|
#add_functions ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 42
def add_functions
validate_function_names!
add_class_iam_policy
@app_class.tasks.each do |task|
add_function(task)
add_function_iam_policy(task)
end
end
|
#depends_on_params ⇒ Object
36
37
38
39
40
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 36
def depends_on_params
return {} unless @app_class.depends_on
depends = Jets::Stack::Depends.new(@app_class.depends_on)
depends.params
end
|
#template_path ⇒ Object
template_path is an interface method for Interface module
20
21
22
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 20
def template_path
Jets::Names.app_template_path(@app_class)
end
|
#validate_function_names! ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 70
def validate_function_names!
invalids = @app_class.tasks.reject do |task|
task.meth.to_s =~ /^[a-zA-Z][a-zA-Z0-9_]/
end
return if invalids.empty?
list = invalids.map do |task|
" #{task.class_name}##{task.meth}" end.join("\n")
puts "ERROR: Detected invalid AWS Lambda function names".color(:red)
puts <<~EOL
Lambda function names must start with a letter and can only contain letters, numbers, and underscores.
Invalid function names:
#{list}
EOL
exit 1
end
|