Class: Jets::Resource::ApiGateway::RestApi

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/resource/api_gateway/rest_api.rb,
lib/jets/resource/api_gateway/rest_api/routes.rb,
lib/jets/resource/api_gateway/rest_api/logical_id.rb,
lib/jets/resource/api_gateway/rest_api/change_detection.rb

Defined Under Namespace

Classes: ChangeDetection, LogicalId, Routes

Constant Summary collapse

@@internal_logical_id =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#replacements, #resource

Class Method Details

.internal_logical_idObject



28
29
30
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 28

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

.logical_id(internal = false) ⇒ Object



23
24
25
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 23

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

Instance Method Details

#binary_media_typesObject

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.



50
51
52
53
54
55
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 50

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

  [types].flatten
end

#definitionObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 3

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
  properties[:policy] = endpoint_policy if endpoint_policy

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

#endpoint_policyObject



57
58
59
60
61
62
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 57

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

  endpoint_policy
end

#endpoint_typesObject



40
41
42
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 40

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

#internal_logical_idObject



19
20
21
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 19

def internal_logical_id
  self.class.logical_id(true)
end

#outputsObject



32
33
34
35
36
37
38
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 32

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