jets 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +3 -1
- data/jets.gemspec +2 -0
- data/lib/jets/application.rb +1 -1
- data/lib/jets/cfn.rb +1 -2
- data/lib/jets/cfn/builders.rb +19 -0
- data/lib/jets/cfn/builders/api_deployment_builder.rb +32 -0
- data/lib/jets/cfn/{template_builders → builders}/api_gateway_builder.rb +10 -21
- data/lib/jets/cfn/builders/base_child_builder.rb +49 -0
- data/lib/jets/cfn/{template_builders → builders}/controller_builder.rb +7 -7
- data/lib/jets/cfn/{template_builders → builders}/function_builder.rb +1 -2
- data/lib/jets/cfn/builders/interface.rb +128 -0
- data/lib/jets/cfn/{template_builders → builders}/job_builder.rb +2 -2
- data/lib/jets/cfn/builders/parent_builder.rb +84 -0
- data/lib/jets/cfn/{template_builders → builders}/rule_builder.rb +4 -5
- data/lib/jets/commands/base.rb +1 -1
- data/lib/jets/commands/build.rb +11 -15
- data/lib/jets/commands/delete.rb +12 -0
- data/lib/jets/commands/templates/skeleton/Gemfile.tt +1 -0
- data/lib/jets/commands/templates/skeleton/config/application.rb.tt +1 -1
- data/lib/jets/commands/url.rb +10 -12
- data/lib/jets/controller/base.rb +2 -2
- data/lib/jets/core.rb +1 -1
- data/lib/jets/core_ext/kernel.rb +11 -1
- data/lib/jets/internal/app/controllers/jets/public_controller.rb +11 -8
- data/lib/jets/lambda/dsl.rb +1 -1
- data/lib/jets/lambda/task.rb +9 -1
- data/lib/jets/naming.rb +2 -2
- data/lib/jets/pascalize.rb +9 -1
- data/lib/jets/poly_fun/base_executor.rb +2 -2
- data/lib/jets/preheat.rb +2 -2
- data/lib/jets/rails_overrides/common_methods.rb +1 -1
- data/lib/jets/resource.rb +55 -5
- data/lib/jets/resource/api_gateway.rb +7 -0
- data/lib/jets/resource/{route → api_gateway}/cors.rb +11 -10
- data/lib/jets/resource/api_gateway/deployment.rb +75 -0
- data/lib/jets/resource/{route.rb → api_gateway/method.rb} +26 -22
- data/lib/jets/{cfn/template_mappers/gateway_resource_mapper.rb → resource/api_gateway/resource.rb} +41 -27
- data/lib/jets/resource/api_gateway/rest_api.rb +23 -0
- data/lib/jets/resource/base.rb +17 -0
- data/lib/jets/resource/child_stack.rb +5 -0
- data/lib/jets/resource/child_stack/api_deployment.rb +58 -0
- data/lib/jets/resource/child_stack/api_gateway.rb +29 -0
- data/lib/jets/resource/child_stack/app_class.rb +81 -0
- data/lib/jets/resource/function.rb +184 -0
- data/lib/jets/resource/iam.rb +8 -0
- data/lib/jets/resource/iam/application_role.rb +27 -0
- data/lib/jets/resource/iam/base_role_definition.rb +44 -0
- data/lib/jets/resource/iam/class_role.rb +25 -0
- data/lib/jets/resource/iam/function_role.rb +25 -0
- data/lib/jets/{cfn/template_builders/managed_iam_policy/base_policy.rb → resource/iam/managed_policy.rb} +6 -6
- data/lib/jets/resource/iam/policy_document.rb +43 -0
- data/lib/jets/resource/permission.rb +38 -21
- data/lib/jets/resource/replacer.rb +50 -17
- data/lib/jets/resource/s3.rb +17 -0
- data/lib/jets/route.rb +3 -1
- data/lib/jets/rule/dsl.rb +7 -1
- data/lib/jets/server/route_matcher.rb +2 -1
- data/lib/jets/version.rb +1 -1
- metadata +46 -52
- data/lib/jets/cfn/template_builders.rb +0 -25
- data/lib/jets/cfn/template_builders/api_gateway_deployment_builder.rb +0 -38
- data/lib/jets/cfn/template_builders/base_child_builder.rb +0 -72
- data/lib/jets/cfn/template_builders/function_properties.rb +0 -6
- data/lib/jets/cfn/template_builders/function_properties/base_builder.rb +0 -128
- data/lib/jets/cfn/template_builders/function_properties/node_builder.rb +0 -12
- data/lib/jets/cfn/template_builders/function_properties/python_builder.rb +0 -12
- data/lib/jets/cfn/template_builders/function_properties/ruby_builder.rb +0 -13
- data/lib/jets/cfn/template_builders/iam_policy.rb +0 -6
- data/lib/jets/cfn/template_builders/iam_policy/application_policy.rb +0 -19
- data/lib/jets/cfn/template_builders/iam_policy/base_policy.rb +0 -57
- data/lib/jets/cfn/template_builders/iam_policy/class_policy.rb +0 -20
- data/lib/jets/cfn/template_builders/iam_policy/function_policy.rb +0 -21
- data/lib/jets/cfn/template_builders/interface.rb +0 -97
- data/lib/jets/cfn/template_builders/managed_iam_policy.rb +0 -6
- data/lib/jets/cfn/template_builders/managed_iam_policy/application_policy.rb +0 -11
- data/lib/jets/cfn/template_builders/managed_iam_policy/class_policy.rb +0 -10
- data/lib/jets/cfn/template_builders/managed_iam_policy/function_policy.rb +0 -10
- data/lib/jets/cfn/template_builders/parent_builder.rb +0 -95
- data/lib/jets/cfn/template_builders/templates/minimal-stack.yml +0 -9
- data/lib/jets/cfn/template_mappers.rb +0 -22
- data/lib/jets/cfn/template_mappers/api_gateway_deployment_mapper.rb +0 -48
- data/lib/jets/cfn/template_mappers/api_gateway_mapper.rb +0 -4
- data/lib/jets/cfn/template_mappers/child_mapper.rb +0 -41
- data/lib/jets/cfn/template_mappers/controller_mapper.rb +0 -36
- data/lib/jets/cfn/template_mappers/function_mapper.rb +0 -4
- data/lib/jets/cfn/template_mappers/iam_policy.rb +0 -6
- data/lib/jets/cfn/template_mappers/iam_policy/application_policy_mapper.rb +0 -37
- data/lib/jets/cfn/template_mappers/iam_policy/base_policy_mapper.rb +0 -49
- data/lib/jets/cfn/template_mappers/iam_policy/class_policy_mapper.rb +0 -42
- data/lib/jets/cfn/template_mappers/iam_policy/function_policy_mapper.rb +0 -42
- data/lib/jets/cfn/template_mappers/job_mapper.rb +0 -4
- data/lib/jets/cfn/template_mappers/lambda_function_mapper.rb +0 -52
- data/lib/jets/cfn/template_mappers/rule_mapper.rb +0 -5
- data/lib/jets/resource/attributes.rb +0 -46
- data/lib/jets/resource/creator.rb +0 -17
- data/lib/jets/resource/replacer/base.rb +0 -98
- data/lib/jets/resource/replacer/config_rule.rb +0 -18
- data/lib/jets/resource/route/attributes.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eebd400edfb6c76668917aa7cd01d921e4fe986b19e233aa10a688bd0ea9fe5f
|
4
|
+
data.tar.gz: 17d59f6694b0215e090c34ca250414570888bfef424403c51cfbe580a6487eb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa1419678318a8cfdb27e973ff0a9ee5555ccd4524b38022b29d33cc77cef0a99920ad511c71b9dd6ac72084563bea93205ea4892333ec67d1210da0a96941c
|
7
|
+
data.tar.gz: f7c4a9f5ad1e2cb694a83a82a95a468377dbcb97736f015e6320c4198db31ccecc966a6381412c020710da87b34759a0f8a1c5052d479c87f2fab4063d593cc9
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.8.1]
|
7
|
+
- Upgrade all cfn resources to use the core jets resource model: request #21 from tongueroo/core-resource2
|
8
|
+
- Rid of mimimal-stack.yml and use jets core resource model
|
9
|
+
- Rescue encoding exception for the Jets IO flush to prevent process from crashing
|
10
|
+
- wip: binary support, set proper isBase64Encoded for binary content, but commented out binary media types due to form post breaking
|
11
|
+
|
6
12
|
## [0.8.0]
|
7
13
|
- Introduce core resource, pull request #20
|
8
14
|
- Future template generation will lead to core resource. Start the move away from the older cfn template generator logic.
|
data/Gemfile.lock
CHANGED
@@ -11,7 +11,7 @@ GIT
|
|
11
11
|
PATH
|
12
12
|
remote: .
|
13
13
|
specs:
|
14
|
-
jets (0.8.
|
14
|
+
jets (0.8.1)
|
15
15
|
actionpack (>= 5.2.1)
|
16
16
|
actionview (>= 5.2.1)
|
17
17
|
activerecord (>= 5.2.1)
|
@@ -28,6 +28,7 @@ PATH
|
|
28
28
|
json
|
29
29
|
kramdown
|
30
30
|
memoist
|
31
|
+
mimemagic
|
31
32
|
pg (= 0.21)
|
32
33
|
rack
|
33
34
|
railties (>= 5.2.1)
|
@@ -111,6 +112,7 @@ GEM
|
|
111
112
|
nokogiri (>= 1.5.9)
|
112
113
|
memoist (0.16.0)
|
113
114
|
method_source (0.9.0)
|
115
|
+
mimemagic (0.3.2)
|
114
116
|
mini_portile2 (2.3.0)
|
115
117
|
minitest (5.11.3)
|
116
118
|
nokogiri (1.8.4)
|
data/jets.gemspec
CHANGED
@@ -44,6 +44,8 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_dependency "text-table"
|
45
45
|
spec.add_dependency "rack"
|
46
46
|
spec.add_dependency "json"
|
47
|
+
spec.add_dependency "mimemagic"
|
48
|
+
|
47
49
|
# TODO: only load the database adapters that app's Gemfile instead of jets.gemspec
|
48
50
|
spec.add_dependency "pg", "=0.21"
|
49
51
|
|
data/lib/jets/application.rb
CHANGED
@@ -94,7 +94,7 @@ class Jets::Application
|
|
94
94
|
sid: "Statement1",
|
95
95
|
action: ["logs:*"],
|
96
96
|
effect: "Allow",
|
97
|
-
resource: "arn:aws:logs:#{Jets.aws.region}:#{Jets.aws.account}:log-group
|
97
|
+
resource: "arn:aws:logs:#{Jets.aws.region}:#{Jets.aws.account}:log-group:/aws/lambda/#{project_namespace}-*",
|
98
98
|
}]
|
99
99
|
end
|
100
100
|
|
data/lib/jets/cfn.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Jets::Cfn
|
5
|
+
class Builders
|
6
|
+
autoload :Interface, "jets/cfn/builders/interface"
|
7
|
+
autoload :ParentBuilder, "jets/cfn/builders/parent_builder"
|
8
|
+
|
9
|
+
# These build the app/controllers, app/jobs, and app/functions
|
10
|
+
autoload :BaseChildBuilder, "jets/cfn/builders/base_child_builder"
|
11
|
+
autoload :ControllerBuilder, "jets/cfn/builders/controller_builder"
|
12
|
+
autoload :JobBuilder, "jets/cfn/builders/job_builder"
|
13
|
+
autoload :FunctionBuilder, "jets/cfn/builders/function_builder"
|
14
|
+
autoload :RuleBuilder, "jets/cfn/builders/rule_builder"
|
15
|
+
|
16
|
+
autoload :ApiGatewayBuilder, "jets/cfn/builders/api_gateway_builder"
|
17
|
+
autoload :ApiDeploymentBuilder, "jets/cfn/builders/api_deployment_builder"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Jets::Cfn::Builders
|
2
|
+
class ApiDeploymentBuilder
|
3
|
+
include Interface
|
4
|
+
include Jets::AwsServices
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
@template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
|
9
|
+
end
|
10
|
+
|
11
|
+
# compose is an interface method
|
12
|
+
def compose
|
13
|
+
return if @options[:stack_type] == :minimal
|
14
|
+
|
15
|
+
puts "Building API Gateway Deployment template."
|
16
|
+
deployment = Jets::Resource::ApiGateway::Deployment.new
|
17
|
+
add_resource(deployment)
|
18
|
+
add_parameters(deployment.parameters)
|
19
|
+
add_outputs(deployment.outputs)
|
20
|
+
end
|
21
|
+
|
22
|
+
# template_path is an interface method
|
23
|
+
def template_path
|
24
|
+
Jets::Naming.api_deployment_template_path
|
25
|
+
end
|
26
|
+
|
27
|
+
# do not bother writing a template if routes are empty
|
28
|
+
def write
|
29
|
+
super unless Jets::Router.routes.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Jets::Cfn::
|
1
|
+
class Jets::Cfn::Builders
|
2
2
|
class ApiGatewayBuilder
|
3
3
|
include Interface
|
4
4
|
include Jets::AwsServices
|
@@ -29,22 +29,19 @@ class Jets::Cfn::TemplateBuilders
|
|
29
29
|
|
30
30
|
# If the are routes in config/routes.rb add Gateway API in parent stack
|
31
31
|
def add_gateway_rest_api
|
32
|
-
|
33
|
-
|
34
|
-
)
|
32
|
+
rest_api = Jets::Resource::ApiGateway::RestApi.new
|
33
|
+
add_resource(rest_api)
|
34
|
+
add_outputs(rest_api.outputs)
|
35
35
|
|
36
|
-
|
37
|
-
add_output("
|
38
|
-
add_output("RestApiUrl", Value: "!Sub 'https://${RestApi}.execute-api.${AWS::Region}.amazonaws.com/#{stage_name}/'")
|
39
|
-
add_output("Region", Value: "!Ref AWS::Region")
|
40
|
-
add_output("RootResourceId", Value: "!GetAtt RestApi.RootResourceId")
|
36
|
+
deployment = Jets::Resource::ApiGateway::Deployment.new
|
37
|
+
add_output("RestApiUrl", Value: deployment.outputs["RestApiUrl"])
|
41
38
|
end
|
42
39
|
|
43
40
|
# Adds route related Resources and Outputs
|
44
41
|
def add_gateway_routes
|
45
42
|
# The routes required a Gateway Resource to contain them.
|
46
43
|
# TODO: Support more routes. Right now outputing all routes in 1 template will hit the 60 routes limit.
|
47
|
-
# Will have to either output them as a joined string or break this up to multiple
|
44
|
+
# Will have to either output them as a joined string or break this up to multiple templates.
|
48
45
|
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html
|
49
46
|
# Outputs: Maximum number of outputs that you can declare in your AWS CloudFormation template. 60 outputs
|
50
47
|
# Output name: Maximum size of an output name. 255 characters.
|
@@ -55,17 +52,9 @@ class Jets::Cfn::TemplateBuilders
|
|
55
52
|
homepage = path == ''
|
56
53
|
next if homepage # handled by RootResourceId output already
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
add_resource(map.logical_id, "AWS::ApiGateway::Resource",
|
62
|
-
ParentId: map.parent_id,
|
63
|
-
PathPart: map.path_part,
|
64
|
-
RestApiId: "!Ref RestApi"
|
65
|
-
)
|
66
|
-
end
|
67
|
-
|
68
|
-
add_output(map.logical_id, Value: "!Ref #{map.logical_id}")
|
55
|
+
resource = Jets::Resource::ApiGateway::Resource.new(path)
|
56
|
+
add_resource(resource)
|
57
|
+
add_outputs(resource.outputs)
|
69
58
|
end
|
70
59
|
end
|
71
60
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Jets::Cfn::Builders
|
2
|
+
class BaseChildBuilder
|
3
|
+
include Interface
|
4
|
+
|
5
|
+
# The app_klass is can be a controller, job or anonymous function class.
|
6
|
+
# IE: PostsController, HardJob
|
7
|
+
def initialize(app_klass)
|
8
|
+
@app_klass = app_klass
|
9
|
+
@template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
|
10
|
+
end
|
11
|
+
|
12
|
+
# template_path is an interface method for Interface module
|
13
|
+
def template_path
|
14
|
+
Jets::Naming.template_path(@app_klass)
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_common_parameters
|
18
|
+
add_parameter("IamRole", Description: "Iam Role that Lambda function uses.")
|
19
|
+
add_parameter("S3Bucket", Description: "S3 Bucket for source code.")
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_functions
|
23
|
+
add_class_iam_policy
|
24
|
+
@app_klass.tasks.each do |task|
|
25
|
+
add_function(task)
|
26
|
+
add_function_iam_policy(task)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_function(task)
|
31
|
+
resource = Jets::Resource::Function.new(task)
|
32
|
+
add_resource(resource)
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_class_iam_policy
|
36
|
+
return unless @app_klass.build_class_iam?
|
37
|
+
|
38
|
+
resource = Jets::Resource::Iam::ClassRole.new(@app_klass)
|
39
|
+
add_resource(resource)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_function_iam_policy(task)
|
43
|
+
return unless task.build_function_iam?
|
44
|
+
|
45
|
+
resource = Jets::Resource::Iam::FunctionRole.new(task)
|
46
|
+
add_resource(resource)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Jets::Cfn::
|
1
|
+
class Jets::Cfn::Builders
|
2
2
|
class ControllerBuilder < BaseChildBuilder
|
3
3
|
# compose is an interface method for Interface module
|
4
4
|
def compose
|
@@ -13,17 +13,17 @@ class Jets::Cfn::TemplateBuilders
|
|
13
13
|
|
14
14
|
add_parameter("RestApi", Description: "RestApi")
|
15
15
|
scoped_routes.each do |route|
|
16
|
-
|
17
|
-
add_parameter(
|
16
|
+
resource = Jets::Resource::ApiGateway::Resource.new(route.path)
|
17
|
+
add_parameter(resource.logical_id, Description: resource.desc)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
def add_routes
|
22
22
|
scoped_routes.each_with_index do |route, i|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
method = Jets::Resource::ApiGateway::Method.new(route)
|
24
|
+
add_resource(method)
|
25
|
+
add_resource(method.permission)
|
26
|
+
add_resource(method.cors) if Jets.config.cors
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Jets::Cfn::
|
1
|
+
class Jets::Cfn::Builders
|
2
2
|
class FunctionBuilder < BaseChildBuilder
|
3
3
|
# compose is an interface method for Interface module
|
4
4
|
def compose
|
@@ -15,6 +15,5 @@ class Jets::Cfn::TemplateBuilders
|
|
15
15
|
end
|
16
16
|
path
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
20
19
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# The class including this module should implement these methods:
|
2
|
+
#
|
3
|
+
# * compose
|
4
|
+
# * template_path
|
5
|
+
class Jets::Cfn::Builders
|
6
|
+
module Interface
|
7
|
+
extend Memoist
|
8
|
+
|
9
|
+
def build
|
10
|
+
# Do not bother building
|
11
|
+
# or writing the template unless there are functions defined
|
12
|
+
return if @app_klass && !@app_klass.build?
|
13
|
+
|
14
|
+
compose # must be implemented by subclass
|
15
|
+
write
|
16
|
+
end
|
17
|
+
|
18
|
+
def write
|
19
|
+
FileUtils.mkdir_p(File.dirname(template_path))
|
20
|
+
IO.write(template_path, text)
|
21
|
+
end
|
22
|
+
|
23
|
+
def template
|
24
|
+
# need the to_hash or the YAML dump has
|
25
|
+
# !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
26
|
+
@template.to_hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def text
|
30
|
+
text = YAML.dump(template)
|
31
|
+
post_process_template(text)
|
32
|
+
end
|
33
|
+
|
34
|
+
# post process the text so that
|
35
|
+
# "!Ref IamRole" => !Ref IamRole
|
36
|
+
# We strip the surrounding quotes
|
37
|
+
def post_process_template(text)
|
38
|
+
results = text.split("\n").map do |line|
|
39
|
+
if line.include?(': "!') # IE: IamRole: "!Ref IamRole",
|
40
|
+
# IamRole: "!Ref IamRole" => IamRole: !Ref IamRole
|
41
|
+
line.sub(/: "(.*)"/, ': \1')
|
42
|
+
elsif line.include?('- "!') # IE: - "!GetAtt Foo.Arn"
|
43
|
+
# IamRole: - "!GetAtt Foo.Arn" => - !GetAtt Foo.Arn
|
44
|
+
line.sub(/- "(.*)"/, '- \1')
|
45
|
+
else
|
46
|
+
line
|
47
|
+
end
|
48
|
+
end
|
49
|
+
results.join("\n") + "\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_parameters(attributes)
|
53
|
+
attributes.each do |name,value|
|
54
|
+
add_parameter(name.to_s.camelize, Description: value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_parameter(name, options={})
|
59
|
+
defaults = { Type: "String" }
|
60
|
+
options = defaults.merge(options)
|
61
|
+
@template[:Parameters] ||= {}
|
62
|
+
@template[:Parameters][name.camelize] = options
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_outputs(attributes)
|
66
|
+
attributes.each do |name,value|
|
67
|
+
add_output(name.to_s.camelize, Value: value)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_output(name, options={})
|
72
|
+
@template[:Outputs] ||= {}
|
73
|
+
@template[:Outputs][name.camelize] = options
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_resources
|
77
|
+
@app_klass.tasks.each do |task|
|
78
|
+
task.resources.each do |definition|
|
79
|
+
resource = Jets::Resource.new(definition, task.replacements)
|
80
|
+
add_resource(resource)
|
81
|
+
add_resource(resource.permission)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_resource(resource)
|
87
|
+
add_template_resource(resource.logical_id, resource.type, resource.attributes)
|
88
|
+
end
|
89
|
+
|
90
|
+
# The add_resource method can take an options Hash with both with either
|
91
|
+
# top level attributes or properties.
|
92
|
+
#
|
93
|
+
# Example:
|
94
|
+
#
|
95
|
+
# Top level options:
|
96
|
+
#
|
97
|
+
# add_template_resource("MyId", "AWS::ApiGateway::RestApi",
|
98
|
+
# type: "AWS::ApiGateway::RestApi",
|
99
|
+
# properties: {
|
100
|
+
# name: "my-api"
|
101
|
+
# },
|
102
|
+
# depends_on: ["AnotherResource"]
|
103
|
+
# )
|
104
|
+
#
|
105
|
+
# Simple options with properties only:
|
106
|
+
#
|
107
|
+
# add_template_resource("MyId", "AWS::CloudFormationStack",
|
108
|
+
# template_url: "template_url",
|
109
|
+
# parameters: {},
|
110
|
+
# )
|
111
|
+
#
|
112
|
+
def add_template_resource(logical_id, type, options)
|
113
|
+
options = Jets::Pascalize.pascalize(options)
|
114
|
+
|
115
|
+
attributes = if options.include?('Type')
|
116
|
+
base = { 'Type' => type }
|
117
|
+
base.merge(options) # options are top-level attributes
|
118
|
+
else
|
119
|
+
{
|
120
|
+
'Type' => type,
|
121
|
+
'Properties' => options # options are properties
|
122
|
+
}
|
123
|
+
end
|
124
|
+
|
125
|
+
@template['Resources'][logical_id] = attributes
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
class Jets::Cfn::Builders
|
4
|
+
class ParentBuilder
|
5
|
+
include Interface
|
6
|
+
include Jets::AwsServices
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
@options = options
|
10
|
+
@template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
|
11
|
+
end
|
12
|
+
|
13
|
+
# compose is an interface method
|
14
|
+
def compose
|
15
|
+
puts "Building parent template."
|
16
|
+
|
17
|
+
build_minimal_resources
|
18
|
+
build_child_resources unless @options[:stack_type] == :minimal
|
19
|
+
end
|
20
|
+
|
21
|
+
# template_path is an interface method
|
22
|
+
def template_path
|
23
|
+
Jets::Naming.parent_template_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_minimal_resources
|
27
|
+
# Initial s3 bucket, used to store code zipfile and templates Jets generates
|
28
|
+
resource = Jets::Resource::S3.new
|
29
|
+
add_resource(resource)
|
30
|
+
add_outputs(resource.outputs)
|
31
|
+
|
32
|
+
# Add application-wide IAM policy from Jets.config.iam_role
|
33
|
+
resource = Jets::Resource::Iam::ApplicationRole.new
|
34
|
+
add_resource(resource)
|
35
|
+
add_outputs(resource.outputs)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_child_resources
|
39
|
+
expression = "#{Jets::Naming.template_path_prefix}-*"
|
40
|
+
# IE: path: #{Jets.build_root}/templates/demo-dev-2-comments_controller.yml
|
41
|
+
Dir.glob(expression).each do |path|
|
42
|
+
next unless File.file?(path)
|
43
|
+
next if api_gateway_paths.include?(path) # specially treated
|
44
|
+
|
45
|
+
add_app_class_stack(path)
|
46
|
+
end
|
47
|
+
|
48
|
+
if @options[:stack_type] == :full and !Jets::Router.routes.empty?
|
49
|
+
add_api_gateway
|
50
|
+
add_api_deployment
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_app_class_stack(path)
|
55
|
+
resource = Jets::Resource::ChildStack::AppClass.new(path, @options[:s3_bucket])
|
56
|
+
add_child_resources(resource)
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_api_gateway
|
60
|
+
resource = Jets::Resource::ChildStack::ApiGateway.new(@options[:s3_bucket])
|
61
|
+
add_child_resources(resource)
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_api_deployment
|
65
|
+
resource = Jets::Resource::ChildStack::ApiDeployment.new(@options[:s3_bucket])
|
66
|
+
add_child_resources(resource)
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_child_resources(resource)
|
70
|
+
add_resource(resource)
|
71
|
+
add_outputs(resource.outputs)
|
72
|
+
end
|
73
|
+
|
74
|
+
def api_gateway_paths
|
75
|
+
files = %w[
|
76
|
+
api-deployment.yml
|
77
|
+
api-gateway.yml
|
78
|
+
]
|
79
|
+
files.map do |name|
|
80
|
+
"#{Jets::Naming.template_path_prefix}-#{name}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|