Class: Moonshot::StackLister
- Inherits:
-
Object
- Object
- Moonshot::StackLister
- Includes:
- CredsHelper
- Defined in:
- lib/moonshot/stack_lister.rb
Overview
The StackLister is world renoun for it’s ability to list stacks.
Defined Under Namespace
Classes: EnvironmentDescription
Instance Method Summary collapse
-
#initialize(app_name) ⇒ StackLister
constructor
A new instance of StackLister.
-
#list ⇒ Object
rubocop:disable Metrics/AbcSize.
Methods included from CredsHelper
#as_client, #cd_client, #cf_client, #ec2_client, #iam_client, #s3_client
Constructor Details
#initialize(app_name) ⇒ StackLister
Returns a new instance of StackLister.
7 8 9 |
# File 'lib/moonshot/stack_lister.rb', line 7 def initialize(app_name) @app_name = app_name end |
Instance Method Details
#list ⇒ Object
rubocop:disable Metrics/AbcSize
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/moonshot/stack_lister.rb', line 12 def list result = [] next_token = nil loop do resp = cf_client.describe_stacks(next_token: next_token) resp.stacks.each do |stack| app_tag = stack..find { |t| t.key == 'moonshot_application' } env_tag = stack..find { |t| t.key == 'moonshot_environment' } legacy_tag = stack..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 && 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 |