Class: Jets::Resource::ChildStack::ApiDeployment

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/resource/child_stack/api_deployment.rb

Instance Method Summary collapse

Methods inherited from Base

#replacements, #resource

Constructor Details

#initialize(s3_bucket) ⇒ ApiDeployment

Returns a new instance of ApiDeployment.



3
4
5
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 3

def initialize(s3_bucket)
  @s3_bucket = s3_bucket
end

Instance Method Details

#definitionObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 7

def definition
  {
    deployment_id => {
      type: "AWS::CloudFormation::Stack",
      properties: {
        template_url: template_url,
        parameters: parameters,
      },
      depends_on: depends_on,
    }
  }
end

#depends_onObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 26

def depends_on
  expression = "#{Jets::Naming.template_path_prefix}-*_controller*"
  controller_logical_ids = []
  Dir.glob(expression).each do |path|
    next unless File.file?(path)

    # map the path to a camelized logical_id. Example:
    #   /tmp/jets/demo/templates/demo-dev-2-posts_controller.yml to
    #   PostsController
    regexp = Regexp.new(".*#{Jets.config.project_namespace}-")
    controller_name = path.sub(regexp, '').sub('.yml', '')
    controller_logical_id = controller_name.underscore.camelize
    controller_logical_ids << controller_logical_id
  end
  controller_logical_ids
end

#deployment_idObject



49
50
51
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 49

def deployment_id
  Jets::Resource::ApiGateway::Deployment.logical_id
end

#outputsObject



43
44
45
46
47
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 43

def outputs
  {
    logical_id => "!Ref #{logical_id}",
  }
end

#parametersObject



20
21
22
23
24
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 20

def parameters
  {
    RestApi: "!GetAtt ApiGateway.Outputs.RestApi",
  }
end

#template_urlObject



53
54
55
56
# File 'lib/jets/resource/child_stack/api_deployment.rb', line 53

def template_url
  path = File.basename("#{Jets.config.project_namespace}-api-deployment.yml")
  "https://s3.amazonaws.com/#{@s3_bucket}/jets/cfn-templates/#{path}"
end