Class: Awsrm::AutoscalingGroup

Inherits:
Resource
  • Object
show all
Defined in:
lib/awsrm/resources/autoscaling_group.rb

Defined Under Namespace

Classes: AutoscalingGroupReader

Constant Summary collapse

FILTER_MAP =
{
  id: ->(value) { [value] },
  arn: ->(value) { [value.split('/').last] },
  name: ->(value) { [value] },
  tags: ->(value) { AutoscalingGroup.tags2names(value) }
}.freeze

Constants inherited from Resource

Resource::CLIENTS, Resource::CLIENT_OPTIONS

Class Method Summary collapse

Methods inherited from Resource

check_one, one

Class Method Details

.all(params) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/awsrm/resources/autoscaling_group.rb', line 10

def all(params)
  res = autoscaling_client.describe_auto_scaling_groups(
    auto_scaling_group_names: filters(params)
  )
  res.auto_scaling_groups.map do |as|
    AutoscalingGroupReader.new(as)
  end
end

.filters(params) ⇒ Object



19
20
21
22
23
24
# File 'lib/awsrm/resources/autoscaling_group.rb', line 19

def filters(params)
  params.map do |key, value|
    raise UndefinedFilterParamError, key unless self::FILTER_MAP.key?(key)
    next self::FILTER_MAP[key].call(value) if self::FILTER_MAP[key].is_a?(Proc)
  end.flatten.uniq
end

.tags2names(tag_hash) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/awsrm/resources/autoscaling_group.rb', line 26

def tags2names(tag_hash)
  tags = autoscaling_client.describe_tags.flat_map { |page| page.tags }
  maps = tag_hash.map do |key, value|
    tags.map do |tag|
      tag.resource_id if tag.key == key.to_s && tag.value == value.to_s
    end.compact
  end
  maps.reduce do |memo, item|
    memo & item
  end
end