lib/jets/resource/api_gateway/method.rb in jets-2.1.7 vs lib/jets/resource/api_gateway/method.rb in jets-2.2.0

- old
+ new

@@ -1,39 +1,46 @@ # Converts a Jets::Route to a CloudFormation Jets::Resource::ApiGateway::Method resource module Jets::Resource::ApiGateway class Method < Jets::Resource::Base + include Authorization + # also delegate permission for a method - delegate :permission, - to: :resource + delegate :permission, to: :resource # route - Jets::Route def initialize(route) @route = route end def definition { method_logical_id => { type: "AWS::ApiGateway::Method", - properties: { - resource_id: "!Ref #{resource_id}", - rest_api_id: "!Ref #{RestApi.logical_id}", - http_method: @route.method, - request_parameters: {}, - authorization_type: authorization_type, - api_key_required: api_key_required?, - integration: { - integration_http_method: "POST", - type: "AWS_PROXY", - uri: "!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${{namespace}LambdaFunction.Arn}/invocations" - }, - method_responses: [] - } + properties: props } } end + def props + props = { + resource_id: "!Ref #{resource_id}", + rest_api_id: "!Ref #{RestApi.logical_id}", + http_method: @route.method, + request_parameters: {}, + authorization_type: authorization_type, + api_key_required: api_key_required?, + integration: { + integration_http_method: "POST", + type: "AWS_PROXY", + uri: "!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${{namespace}LambdaFunction.Arn}/invocations" + }, + method_responses: [] + } + props[:authorizer_id] = authorizer_id if authorizer_id + props + end + def method_logical_id # https://stackoverflow.com/questions/6104240/how-do-i-strip-non-alphanumeric-characters-from-a-string-and-keep-spaces # Add path to the logical id to allow 2 different paths to be connected to the same controller action. # Example: # @@ -62,31 +69,9 @@ Cors.new(@route) end memoize :cors private - - def authorization_type - type = @route.authorization_type || - controller_auth_type || - Jets.config.api.authorization_type - type.to_s.upcase - end - - def controller_auth_type - # Already handles inheritance via class_attribute - controller_klass.authorization_type - end - - def api_key_required? - api_key_required == true - end - - def api_key_required - @route.api_key_required || - controller_klass.api_key_required || - Jets.config.api.api_key_required - end def controller_klass @controller_klass ||= "#{controller_name}_controller".camelize.constantize end