Class: Jets::Cfn::Builders::AuthorizerBuilder

Inherits:
BaseChildBuilder show all
Includes:
AwsServices, Interface
Defined in:
lib/jets/cfn/builders/authorizer_builder.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Methods included from Interface

#add_description, #add_output, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #post_process_template, #template, #text, #write

Methods inherited from BaseChildBuilder

#add_class_iam_policy, #add_common_parameters, #add_function, #add_function_iam_policy, #add_functions, #depends_on_params

Constructor Details

#initialize(path) ⇒ AuthorizerBuilder

Returns a new instance of AuthorizerBuilder.



11
12
13
14
15
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 11

def initialize(path)
  @path = path # IE: app/authorizers/main_authorizer.rb
  @app_class = Jets::Klass.from_path(path)
  @template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end

Instance Method Details

#add_api_gateway_parametersObject



57
58
59
60
61
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 57

def add_api_gateway_parameters
  return if Jets::Router.routes.empty?

  add_parameter("RestApi", Description: "RestApi")
end

#add_cognito_authorizersObject



28
29
30
31
32
33
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 28

def add_cognito_authorizers
  @app_class.cognito_authorizers.each do |authorizer|
    resource = Jets::Resource.new(authorizer[:definition], authorizer[:replacements])
    add_resource(resource)
  end
end

#add_cognito_outputsObject



49
50
51
52
53
54
55
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 49

def add_cognito_outputs
  @app_class.cognito_authorizers.each do |authorizer|
    resource = Jets::Resource.new(authorizer[:definition], authorizer[:replacements])
    logical_id = resource.logical_id
    add_output(logical_id, value: "!Ref #{logical_id}")
  end
end

#add_outputsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 35

def add_outputs
  # IE: @app_class = MainAuthorizer
  # The associated resource is the Jets::Resource::ApiGateway::Authorizer definition built during evaluation
  # of the user defined Authorizer class. We'll use it to compute the logical id.
  @app_class.tasks.each do |task|
    authorizer = task.associated_resources.first
    next unless authorizer

    resource = Jets::Resource.new(authorizer.definition, task.replacements)
    logical_id = resource.logical_id
    add_output(logical_id, value: "!Ref #{logical_id}")
  end
end

#composeObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 17

def compose
  add_common_parameters
  add_api_gateway_parameters
  add_functions
  add_resources
  add_outputs
  # These dont have lambda functions associated with them
  add_cognito_authorizers
  add_cognito_outputs
end

#template_pathObject



63
64
65
# File 'lib/jets/cfn/builders/authorizer_builder.rb', line 63

def template_path
  Jets::Naming.authorizer_template_path(@path)
end