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

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
AwsServices
Defined in:
lib/jets/resource/api_gateway/rest_api/logical_id.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #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

included

Instance Method Details

#api_gateway_exists?Boolean

Returns:

  • (Boolean)


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

def api_gateway_exists?
  !!api_gateway_stack_arn
end

#api_gateway_stack_arnObject



46
47
48
49
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 46

def api_gateway_stack_arn
  stack = cfn.describe_stacks(stack_name: parent_stack_name).stacks.first
  lookup(stack[:outputs], "ApiGateway") # api_gateway_stack_arn
end

#changed?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 16

def changed?
  change_detection = ChangeDetection.new
  change_detection.changed?
end

#currentObject



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

def current
  resources = cfn.describe_stack_resources(stack_name: api_gateway_stack_arn).stack_resources
  rest_api = resources.find { |r| r.resource_type == 'AWS::ApiGateway::RestApi' }
  rest_api.logical_resource_id
end

#defaultObject



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

def default
  "RestApi"
end

#getObject



6
7
8
9
10
11
12
13
14
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 6

def get
  return default unless stack_exists?(parent_stack_name) && api_gateway_exists?

  if changed?
    new_id
  else
    current
  end
end

#new_idObject

Takes current logical id and increments the number that is appended to it.

Examples:

RestApi => RestApi1
RestApi1 => RestApi2
RestApi2 => RestApi3
RestApi7 => RestApi8


29
30
31
32
33
34
35
36
37
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 29

def new_id
  regexp = /(\d+)/
  md = current.match(regexp)
  if md
    current.gsub(regexp,'') + (md[1].to_i + 1).to_s
  else
    current + "1"
  end
end

#parent_stack_nameObject



55
56
57
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 55

def parent_stack_name
  Jets::Naming.parent_stack_name
end