Class: Jets::Resource::ApiGateway::Authorizer

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/resource/api_gateway/authorizer.rb

Instance Method Summary collapse

Methods inherited from Base

#replacements, #resource

Constructor Details

#initialize(props = {}) ⇒ Authorizer

Returns a new instance of Authorizer.



3
4
5
# File 'lib/jets/resource/api_gateway/authorizer.rb', line 3

def initialize(props={})
  @props = props # associated_properties from dsl.rb
end

Instance Method Details

#authorizer_logical_idObject



47
48
49
# File 'lib/jets/resource/api_gateway/authorizer.rb', line 47

def authorizer_logical_id
  "{namespace}_authorizer" # IE: protect_authorizer
end

#definitionObject



7
8
9
10
11
12
13
14
# File 'lib/jets/resource/api_gateway/authorizer.rb', line 7

def definition
  {
    authorizer_logical_id => {
      type: "AWS::ApiGateway::Authorizer",
      properties: props,
    }
  }
end

#outputsObject



51
52
53
54
55
56
# File 'lib/jets/resource/api_gateway/authorizer.rb', line 51

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

#propsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jets/resource/api_gateway/authorizer.rb', line 16

def props
  default = {
    # authorizer_credentials: '',
    # authorizer_result_ttl_in_seconds: '',
    # auth_type: '',
    # identity_source: '', # required
    # identity_validation_expression: '',
    # name: '',
    # provider_arns: [],
    rest_api_id: '!Ref RestApi', # Required: Yes
    type: '', # Required: Yes
  }

  unless @props[:type].to_s.upcase == 'COGNITO_USER_POOLS'
    @props[:authorizer_uri] = { # Required: Conditional
      "Fn::Join" => ['', [
        'arn:aws:apigateway:',
        "!Ref 'AWS::Region'",
        ':lambda:path/2015-03-31/functions/',
        {"Fn::GetAtt" => ["{namespace}LambdaFunction", "Arn"]},
        '/invocations'
      ]]
    }
  end
  @props[:authorizer_result_ttl_in_seconds] = @props.delete(:ttl) if @props[:ttl]

  normalize_type!(@props)
  normalize_identity_source!(@props)
  default.merge(@props)
end