Sha256: 3ee718062c8ea2a3965ead88d3ae470a08986dbe29a25160269be2085321ccd8

Contents?: true

Size: 1.76 KB

Versions: 72

Compression:

Stored size: 1.76 KB

Contents

module Jets::Resource::ApiGateway
  class RestApi < Jets::Resource::Base
    autoload :ChangeDetection, 'jets/resource/api_gateway/rest_api/change_detection'
    autoload :LogicalId, 'jets/resource/api_gateway/rest_api/logical_id'
    autoload :Routes, 'jets/resource/api_gateway/rest_api/routes'

    def definition
      properties = {
        name: Jets::Naming.gateway_api_name,
        endpoint_configuration: { types: endpoint_types }
      }
      properties[:binary_media_types] = binary_media_types if binary_media_types

      {
        internal_logical_id => {
          type: "AWS::ApiGateway::RestApi",
          properties: properties
        }
      }
    end

    def internal_logical_id
      self.class.logical_id(true)
    end

    def self.logical_id(internal=false)
      internal ? internal_logical_id : "RestApi"
    end

    @@internal_logical_id = nil
    def self.internal_logical_id
      @@internal_logical_id ||= LogicalId.new.get
    end

    def outputs
      {
        "RestApi" => "!Ref #{internal_logical_id}",
        "Region" => "!Ref AWS::Region",
        "RootResourceId" => "!GetAtt #{internal_logical_id}.RootResourceId",
      }
    end

    def endpoint_types
      [Jets.config.api.endpoint_type].flatten
    end

    # TODO: Looks like there's a bug with CloudFormation. On an API Gateway update
    # we need to pass in the escaped version: multipart~1form-data
    # On a brand new API Gateway creation, we need to pass in the unescaped form:
    # multipart/form-data
    # We are handling this with a full API Gateway replacement instead because it
    # can be generalized more easily.
    def binary_media_types
      types = Jets.config.api.binary_media_types
      return nil if types.nil? || types.empty?

      [types].flatten
    end
  end
end

Version data entries

72 entries across 72 versions & 2 rubygems

Version Path
jets-1.8.2 lib/jets/resource/api_gateway/rest_api.rb
jets-1.8.1 lib/jets/resource/api_gateway/rest_api.rb
jets-1.8.0 lib/jets/resource/api_gateway/rest_api.rb
jets-1.7.2 lib/jets/resource/api_gateway/rest_api.rb
jets-1.7.1 lib/jets/resource/api_gateway/rest_api.rb
jets-1.7.0 lib/jets/resource/api_gateway/rest_api.rb
jets-fs-1.6.10 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.9 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.8 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.7 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.6 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.5 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.4 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.3 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.2 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.1 lib/jets/resource/api_gateway/rest_api.rb
jets-1.6.0 lib/jets/resource/api_gateway/rest_api.rb
jets-1.5.10 lib/jets/resource/api_gateway/rest_api.rb
jets-1.5.9 lib/jets/resource/api_gateway/rest_api.rb
jets-1.5.8 lib/jets/resource/api_gateway/rest_api.rb