Sha256: ce4d780178981cd515a12e85f5de9266f94734d6966fbbe2996cfcca871fdb1c

Contents?: true

Size: 1.94 KB

Versions: 15

Compression:

Stored size: 1.94 KB

Contents

class Jets::Cfn::Builder
  class Authorizer < Nested
    include Interface
    include Jets::AwsServices

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

    # interface method
    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

    # interface method
    def template_path
      Jets::Names.authorizer_template_path(@path)
    end

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

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

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

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

    def add_api_gateway_parameters
      return if Jets::Router.no_routes?

      add_parameter(:RestApi)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/cfn/builder/authorizer.rb
jets-5.0.12 lib/jets/cfn/builder/authorizer.rb
jets-5.0.11 lib/jets/cfn/builder/authorizer.rb
jets-5.0.10 lib/jets/cfn/builder/authorizer.rb
jets-5.0.9 lib/jets/cfn/builder/authorizer.rb
jets-5.0.8 lib/jets/cfn/builder/authorizer.rb
jets-5.0.7 lib/jets/cfn/builder/authorizer.rb
jets-5.0.6 lib/jets/cfn/builder/authorizer.rb
jets-5.0.5 lib/jets/cfn/builder/authorizer.rb
jets-5.0.4 lib/jets/cfn/builder/authorizer.rb
jets-5.0.3 lib/jets/cfn/builder/authorizer.rb
jets-5.0.2 lib/jets/cfn/builder/authorizer.rb
jets-5.0.1 lib/jets/cfn/builder/authorizer.rb
jets-5.0.0 lib/jets/cfn/builder/authorizer.rb
jets-5.0.0.beta1 lib/jets/cfn/builder/authorizer.rb