Class: Jets::Resource::ChildStack::ApiResource

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

Defined Under Namespace

Classes: Page

Instance Method Summary collapse

Methods inherited from Base

#outputs, #template_url

Methods inherited from Base

#replacements, #resource

Constructor Details

#initializeApiResource

Returns a new instance of ApiResource.



8
9
10
11
# File 'lib/jets/resource/child_stack/api_resource.rb', line 8

def initialize(*)
  super
  @page = @options[:page]
end

Instance Method Details

#api_resource_page(parameter) ⇒ Object



46
47
48
# File 'lib/jets/resource/child_stack/api_resource.rb', line 46

def api_resource_page(parameter)
  Page.logical_id(parameter)
end

#definitionObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jets/resource/child_stack/api_resource.rb', line 13

def definition
  {
    "api_resources_#{@page}" =>  {
      type: "AWS::CloudFormation::Stack",
      # depends_on: "ApiGateway", # CloudFormation seems to be smart enough
      properties: {
        template_url: template_url,
        parameters: parameters,
      }
    }
  }
end

#parametersObject



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

def parameters
  params = {}
  # Since dont have all the info required.
  # Read the template back to find the parameters required.
  # Actually might be easier to rationalize this approach.
  template_path = Jets::Names.api_resources_template_path(@page)
  template = Jets::Cfn::BuiltTemplate.get(template_path)
  template['Parameters'].keys.each do |p|
    case p
    when "RestApi"
      params[p] = "!GetAtt ApiGateway.Outputs.RestApi"
    when "RootResourceId"
      params[p] = "!GetAtt ApiGateway.Outputs.RootResourceId"
    else
      params[p] = "!GetAtt #{api_resource_page(p)}.Outputs.#{p}"
    end
  end
  params
end

#template_filenameObject



50
51
52
# File 'lib/jets/resource/child_stack/api_resource.rb', line 50

def template_filename
  "#{Jets.config.project_namespace}-api-resources-#{@page}.yml"
end