Class: Jets::Cfn::TemplateBuilders::ControllerBuilder
- Inherits:
-
BaseChildBuilder
- Object
- BaseChildBuilder
- Jets::Cfn::TemplateBuilders::ControllerBuilder
- Defined in:
- lib/jets/cfn/template_builders/controller_builder.rb
Instance Method Summary collapse
- #add_api_gateway_parameters ⇒ Object
- #add_cors(map) ⇒ Object
- #add_permission(map) ⇒ Object
- #add_route(route, map) ⇒ Object
- #add_routes ⇒ Object
-
#compose ⇒ Object
compose is an interface method for Interface module.
-
#scoped_routes ⇒ Object
routes scoped to this controller template.
Methods inherited from BaseChildBuilder
#add_class_iam_policy, #add_common_parameters, #add_function, #add_functions, #add_iam_policy, #initialize, #template_path
Methods included from Interface
#add_output, #add_parameter, #add_resource, #build, #post_process_template, #template, #text, #write
Constructor Details
This class inherits a constructor from Jets::Cfn::TemplateBuilders::BaseChildBuilder
Instance Method Details
#add_api_gateway_parameters ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 11 def add_api_gateway_parameters return if Jets::Router.routes.empty? add_parameter("RestApi", Description: "RestApi") scoped_routes.each do |route| map = Jets::Cfn::TemplateMappers::GatewayResourceMapper.new(route.path) add_parameter(map.logical_id, Description: map.desc) end end |
#add_cors(map) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 48 def add_cors(map) # TODO: provide a way to allow specify CORs domains return unless Jets.config.cors add_resource(map.cors_logical_id, "AWS::ApiGateway::Method", AuthorizationType: "NONE", HttpMethod: "OPTIONS", MethodResponses: [ { StatusCode: "200", ResponseParameters: { "method.response.header.Access-Control-AllowOrigin" => true, "method.response.header.Access-Control-AllowHeaders" => true, "method.response.header.Access-Control-AllowMethods" => true, "method.response.header.Access-Control-AllowCredentials" => true }, ResponseModels: {} } ], RequestParameters: {}, Integration: { Type: "MOCK", RequestTemplates: { "application/json" => "{statusCode:200}" }, IntegrationResponses: [ { StatusCode: "200", ResponseParameters: { "method.response.header.Access-Control-AllowOrigin" => "'*'", "method.response.header.Access-Control-AllowHeaders" => "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'", "method.response.header.Access-Control-AllowMethods" => "'OPTIONS,GET'", "method.response.header.Access-Control-AllowCredentials" => "'false'" }, ResponseTemplates: {"application/json" => ""} } ] }, ResourceId: "!Ref #{map.gateway_resource_logical_id}", RestApiId: "!Ref RestApi", ) end |
#add_permission(map) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 91 def (map) add_resource(map., "AWS::Lambda::Permission", FunctionName: "!GetAtt #{map.lambda_function_logical_id}.Arn", Action: "lambda:InvokeFunction", Principal: "apigateway.amazonaws.com", SourceArn: "!Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestApi}/*/*" ) end |
#add_route(route, map) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 30 def add_route(route, map) # AWS::ApiGateway::Method # Example map.logical_id: ApiGatewayMethodPostsControllerIndex add_resource(map.logical_id, "AWS::ApiGateway::Method", HttpMethod: route.method, RequestParameters: {}, ResourceId: "!Ref #{map.gateway_resource_logical_id}", RestApiId: "!Ref RestApi", AuthorizationType: "NONE", Integration: { IntegrationHttpMethod: "POST", Type: "AWS_PROXY", Uri: "!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${#{map.lambda_function_logical_id}.Arn}/invocations" }, MethodResponses:[] ) end |
#add_routes ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 21 def add_routes scoped_routes.each_with_index do |route, i| map = Jets::Cfn::TemplateMappers::GatewayMethodMapper.new(route) add_route(route, map) add_cors(map) (map) end end |
#compose ⇒ Object
compose is an interface method for Interface module
4 5 6 7 8 9 |
# File 'lib/jets/cfn/template_builders/controller_builder.rb', line 4 def compose add_common_parameters add_api_gateway_parameters add_functions add_routes end |