Method: Moonshot::StackLister#list

Defined in:
lib/moonshot/stack_lister.rb

#listObject

rubocop:disable Metrics/AbcSize



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/moonshot/stack_lister.rb', line 14

def list
  result = []
  next_token = nil
  loop do
    resp = cf_client.describe_stacks(next_token:)
    resp.stacks.each do |stack|
      app_tag = stack.tags.find { |t| t.key == 'moonshot_application' }
      env_tag = stack.tags.find { |t| t.key == 'moonshot_environment' }
      legacy_tag = stack.tags.find { |t| t.key == 'ah_stage' }

      if app_tag && app_tag.value == Moonshot.config.app_name
        result <<
          EnvironmentDescription.new(env_tag.value, stack.creation_time, stack.stack_status)
      elsif legacy_tag&.value&.start_with?(Moonshot.config.app_name)
        result <<
          EnvironmentDescription.new(legacy_tag.value, stack.creation_time, stack.stack_status)
      end
    end
    break unless resp.next_token

    next_token = resp.next_token
  end
  result.sort_by(&:name)
end