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)


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

def api_gateway_exists?
  !!api_gateway_stack_arn
end

#api_gateway_stack_arnObject



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

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)


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

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

#currentObject



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

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



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

def default
  "RestApi"
end

#getObject



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

def get
  return default if ENV['JETS_BUILD_NO_INTERNET']
  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


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

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



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

def parent_stack_name
  Jets::Naming.parent_stack_name
end