Sha256: c12d760f67ac2120e31d9df750783ad7cf4f409fdb17fb86ae7490cc507f32d1

Contents?: true

Size: 1.99 KB

Versions: 13

Compression:

Stored size: 1.99 KB

Contents

module Jets::Resource::ApiGateway
  class RestApi < Jets::Resource::Base
    def definition
      properties = {
        name: Jets::Names.gateway_api_name,
        endpoint_configuration: { types: endpoint_types }
      }
      properties[:endpoint_configuration][:vpc_endpoint_ids] = vpce_ids if vpce_ids
      properties[:binary_media_types] = binary_media_types if binary_media_types
      properties[:policy] = endpoint_policy if endpoint_policy

      {
        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

    def endpoint_policy
      endpoint_policy = Jets.config.api.endpoint_policy
      return nil if endpoint_policy.nil? || endpoint_policy.empty?

      endpoint_policy
    end

    private

    def vpce_ids
      ids = Jets.config.api.vpc_endpoint_ids
      return nil if ids.nil? || ids.empty?

      ids
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jets-4.0.12 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.11 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.10 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.9 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.8 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.7 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.6 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.5 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.4 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.3 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.2 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.1 lib/jets/resource/api_gateway/rest_api.rb
jets-4.0.0 lib/jets/resource/api_gateway/rest_api.rb