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, #sqs, #sts
#lookup, #stack_exists?, #stack_in_progress?
Instance Method Details
#api_gateway_exists? ⇒ 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_arn ⇒ Object
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") end
|
#changed? ⇒ 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
|
#current ⇒ Object
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
|
#default ⇒ Object
60
61
62
|
# File 'lib/jets/resource/api_gateway/rest_api/logical_id.rb', line 60
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?
if 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
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_name ⇒ Object
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
|