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



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

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

.logical_id(internal = false) ⇒ Object



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

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.



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

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
18
# File 'lib/jets/resource/api_gateway/rest_api.rb', line 3

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

#endpoint_policyObject



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

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

  endpoint_policy
end

#endpoint_typesObject



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

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

#internal_logical_idObject



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

def internal_logical_id
  self.class.logical_id(true)
end

#outputsObject



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

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