Class: Jets::Resource::ApiGateway::RestApi::LogicalId
- Inherits:
-
Object
- Object
- Jets::Resource::ApiGateway::RestApi::LogicalId
show all
- Extended by:
- Memoist
- Includes:
- AwsServices
- Defined in:
- lib/jets/resource/api_gateway/rest_api/logical_id.rb
Instance Method Summary
collapse
#apigateway, #cfn, #lambda, #logs, #s3, #s3_resource, #sns, #sts
#lookup, #stack_exists?, #stack_in_progress?
Instance Method Details
#api_gateway_exists? ⇒ Boolean
47
48
49
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 47
def api_gateway_exists?
!!api_gateway_stack_arn
end
|
#api_gateway_stack_arn ⇒ Object
42
43
44
45
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 42
def api_gateway_stack_arn
stack = cfn.describe_stacks(stack_name: parent_stack_name).stacks.first
lookup(stack[:outputs], "ApiGateway")
end
|
#current ⇒ Object
35
36
37
38
39
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 35
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
|
#default ⇒ Object
55
56
57
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 55
def default
"RestApi"
end
|
#get ⇒ Object
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 unless stack_exists?(parent_stack_name) && api_gateway_exists?
change_detection = ChangeDetection.new
if change_detection.changed?
new_id
else
current
end
end
|
#new_id ⇒ Object
Takes current logical id and increments the number that is appended to it.
Examples:
RestApi => RestApi1
RestApi1 => RestApi2
RestApi2 => RestApi3
RestApi7 => RestApi8
25
26
27
28
29
30
31
32
33
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 25
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_name ⇒ Object
51
52
53
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 51
def parent_stack_name
Jets::Naming.parent_stack_name
end
|