Class: Jets::Cfn::Builder::Api::Gateway
- Defined in:
- lib/jets/cfn/builder/api/gateway.rb
Instance Method Summary collapse
- #add_custom_domain ⇒ Object
- #add_domain_name ⇒ Object
-
#add_gateway_rest_api ⇒ Object
If the are routes in config/routes.rb add Gateway API in parent stack.
- #add_route53_dns ⇒ Object
- #api_gateway_physical_resource_id ⇒ Object
-
#compose ⇒ Object
interface method.
- #create_domain_name ⇒ Object
- #existing_dns_record_on_stack? ⇒ Boolean
- #existing_domain_name?(resource) ⇒ Boolean
- #existing_domain_name_on_stack? ⇒ Boolean
-
#template_path ⇒ Object
interface method.
-
#write ⇒ Object
do write a template if routes are empty.
Methods inherited from Base
Methods included from AwsServices
#apigateway, #aws_lambda, #aws_options, #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
Methods included from Interface
#add_description, #add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #build?, #template, #text
Methods included from Util::Camelize
Constructor Details
This class inherits a constructor from Jets::Cfn::Builder::Api::Base
Instance Method Details
#add_custom_domain ⇒ Object
30 31 32 33 34 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 30 def add_custom_domain return unless Jets.custom_domain? add_domain_name add_route53_dns if Jets.config.domain.route53 end |
#add_domain_name ⇒ Object
36 37 38 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 36 def add_domain_name add_outputs(create_domain_name) end |
#add_gateway_rest_api ⇒ Object
If the are routes in config/routes.rb add Gateway API in parent stack
20 21 22 23 24 25 26 27 28 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 20 def add_gateway_rest_api rest_api = Jets::Cfn::Resource::ApiGateway::RestApi.new add_resource(rest_api) add_outputs(rest_api.outputs) deployment = Jets::Cfn::Resource::ApiGateway::Deployment.new outputs = deployment.outputs(true) add_output(:RestApiUrl, Value: outputs[:RestApiUrl]) end |
#add_route53_dns ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 40 def add_route53_dns dns = Jets::Cfn::Resource::Route53::RecordSet.new if !existing_domain_name?(dns.domain_name) or existing_dns_record_on_stack? add_resource(dns) add_outputs(dns.outputs) end end |
#api_gateway_physical_resource_id ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 92 def api_gateway_physical_resource_id resp = cfn.describe_stack_resource( stack_name: Jets::Names.parent_stack_name, logical_resource_id: "ApiGateway" ) resp&.stack_resource_detail&.physical_resource_id # IE: Aws::CloudFormation::Errors::ValidationError (Resource ApiGateway does not exist for stack demo-dev) rescue Aws::CloudFormation::Errors::ValidationError nil end |
#compose ⇒ Object
interface method
4 5 6 7 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 4 def compose add_gateway_rest_api # changes parent template add_custom_domain # changes parent template end |
#create_domain_name ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 48 def create_domain_name resource = Jets::Cfn::Resource::ApiGateway::DomainName.new return { DomainName: resource.domain_name } if (existing_domain_name?(resource) and !existing_domain_name_on_stack?) add_resource(resource) return resource.outputs end |
#existing_dns_record_on_stack? ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 81 def existing_dns_record_on_stack? cfn.describe_stack_resource( stack_name: api_gateway_physical_resource_id, logical_resource_id: "DnsRecord" ) true # IE: Aws::CloudFormation::Errors::ValidationError (Resource DnsRecord does not exist for stack demo-dev) rescue Aws::CloudFormation::Errors::ValidationError false end |
#existing_domain_name?(resource) ⇒ Boolean
59 60 61 62 63 64 65 66 67 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 59 def existing_domain_name?(resource) apigateway.get_domain_name( domain_name: resource.domain_name ) true # IE: Aws::APIGateway::Errors::NotFoundException Invalid domain name identifier specified rescue Aws::APIGateway::Errors::NotFoundException false end |
#existing_domain_name_on_stack? ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 70 def existing_domain_name_on_stack? cfn.describe_stack_resource( stack_name: api_gateway_physical_resource_id, logical_resource_id: "DomainName" ) true # IE: Aws::CloudFormation::Errors::ValidationError (Resource DomainName does not exist for stack demo-dev) rescue Aws::CloudFormation::Errors::ValidationError false end |
#template_path ⇒ Object
interface method
10 11 12 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 10 def template_path Jets::Names.api_gateway_template_path end |
#write ⇒ Object
do write a template if routes are empty
15 16 17 |
# File 'lib/jets/cfn/builder/api/gateway.rb', line 15 def write super unless Jets::Router.no_routes? end |