Class: Ufo::Info

Inherits:
CLI::Base show all
Includes:
AwsServices
Defined in:
lib/ufo/info.rb

Instance Attribute Summary

Attributes inherited from CLI::Base

#task_definition

Instance Method Summary collapse

Methods included from AwsServices

#acm, #applicationautoscaling, #aws_options, #cloudformation, #cloudwatchlogs, #ec2, #ecr, #ecs, #elb, #find_stack, #ssm_client, #status, #task_definition_arns

Methods inherited from CLI::Base

#initialize

Methods included from Utils::Sure

#sure?

Methods included from Utils::Pretty

#pretty_home, #pretty_path, #pretty_time

Methods included from Utils::Logging

#logger

Methods included from Concerns

#build, #deploy, #info, #ps

Methods included from Concerns::Names

#names

Constructor Details

This class inherits a constructor from Ufo::CLI::Base

Instance Method Details

#load_balancer(service) ⇒ Object

Passing in service so method can be used else where.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ufo/info.rb', line 22

def load_balancer(service)
  load_balancer = service.load_balancers.first
  return unless load_balancer

  resp = elb.describe_target_groups(
    target_group_arns: [load_balancer.target_group_arn]
  )
  target_group = resp.target_groups.first
  load_balancer_arn = target_group.load_balancer_arns.first # assume first only

  resp = elb.describe_load_balancers(load_balancer_arns: [load_balancer_arn])
  resp.load_balancers.first
end

#no_service_messageObject



17
18
19
# File 'lib/ufo/info.rb', line 17

def no_service_message
  "No stack #{@stack_name.color(:green)} found"
end

#runObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ufo/info.rb', line 5

def run
  unless service
    puts no_service_message
    return
  end
  puts "Resources:"
  stack_resources.each do |r|
    puts "#{r.logical_resource_id} - #{r.resource_type}:".color(:green)
    puts "  #{r.physical_resource_id}"
  end
end

#serviceObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/ufo/info.rb', line 37

def service
  return unless stack

  service = stack_resources.find { |r| r.resource_type == "AWS::ECS::Service" }
  return unless service # stack is still creating
  arn = service.physical_resource_id
  return unless arn # can be nil for a few seconds while stack is still creating it
  resp = ecs.describe_services(services: [arn], cluster: @cluster)
  resp.services.first
end

#service?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ufo/info.rb', line 49

def service?
  !!service
end

#stackObject



53
54
55
# File 'lib/ufo/info.rb', line 53

def stack
  find_stack(@stack_name)
end

#stack_resourcesObject



75
76
77
78
# File 'lib/ufo/info.rb', line 75

def stack_resources
  resp = cloudformation.describe_stack_resources(stack_name: @stack_name)
  resp.stack_resources
end

#urlObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ufo/info.rb', line 58

def url
  return unless stack

  output = stack.outputs.find do |o|
    o.output_key == "Route53Dns"
  end
  dns_name = output.output_value if output
  return unless dns_name

  ssl = stack_resources.find do |r|
    r.logical_resource_id == "ListenerSsl"
  end

  protocol = ssl ? 'https' : 'http'
  "#{protocol}://#{dns_name}"
end