Class: Jets::Commands::Url
- Inherits:
-
Object
- Object
- Jets::Commands::Url
show all
- Includes:
- AwsServices
- Defined in:
- lib/jets/commands/url.rb
Instance Method Summary
collapse
#apigateway, #cfn, #lambda, #logs, #s3, #s3_resource, #sns, #sqs, #sts
#lookup, #stack_exists?, #stack_in_progress?
Constructor Details
#initialize(options) ⇒ Url
Returns a new instance of Url.
5
6
7
|
# File 'lib/jets/commands/url.rb', line 5
def initialize(options)
@options = options
end
|
Instance Method Details
#display ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/jets/commands/url.rb', line 9
def display
stack_name = Jets::Naming.parent_stack_name
unless stack_exists?(stack_name)
puts "Stack for #{Jets.config.project_name.colorize(:green)} project for environment #{Jets.env.colorize(:green)}. Couldn't find #{stack_name.colorize(:green)} stack."
exit
end
stack = cfn.describe_stacks(stack_name: stack_name).stacks.first
api_gateway_stack_arn = lookup(stack[:outputs], "ApiGateway")
if api_gateway_stack_arn && endpoint_available?
api_gateway_endpoint = get_gateway_endpoint(api_gateway_stack_arn)
STDOUT.puts "API Gateway Endpoint: #{api_gateway_endpoint}"
show_custom_domain
else
puts "API Gateway not found. This jets app does have an API Gateway associated with it. Please double check your config/routes.rb if you were expecting to see a url for the app. Also check that #{stack_name.colorize(:green)} is a jets app."
end
end
|
#endpoint_available? ⇒ Boolean
55
56
57
|
# File 'lib/jets/commands/url.rb', line 55
def endpoint_available?
!endpoint_unavailable?
end
|
#endpoint_unavailable? ⇒ Boolean
49
50
51
52
53
|
# File 'lib/jets/commands/url.rb', line 49
def endpoint_unavailable?
return false if Jets::Router.routes.empty?
resp, status = stack_status
return false if status.include?("ROLLBACK")
end
|
#get_gateway_endpoint(api_gateway_stack_arn) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/jets/commands/url.rb', line 28
def get_gateway_endpoint(api_gateway_stack_arn)
stack = cfn.describe_stacks(stack_name: api_gateway_stack_arn).stacks.first
rest_api = lookup(stack[:outputs], "RestApi")
region_id = lookup(stack[:outputs], "Region")
stage_name = Jets::Resource::ApiGateway::Deployment.stage_name
"https://#{rest_api}.execute-api.#{region_id}.amazonaws.com/#{stage_name}"
end
|
#show_custom_domain ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/jets/commands/url.rb', line 39
def show_custom_domain
return unless endpoint_available? && Jets.custom_domain? && Jets.config.domain.route53
domain_name = Jets::Resource::ApiGateway::DomainName.new
url = "https://#{domain_name.domain_name}"
puts "Custom Domain: #{url}"
end
|
#stack_status ⇒ Object
61
62
63
64
65
|
# File 'lib/jets/commands/url.rb', line 61
def stack_status
resp = cfn.describe_stacks(stack_name: @parent_stack_name)
status = resp.stacks[0].stack_status
[resp, status]
end
|