Class: CfnManage::TagFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/cfn_manage/tag_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_id) ⇒ TagFinder

Returns a new instance of TagFinder.



10
11
12
13
# File 'lib/cfn_manage/tag_finder.rb', line 10

def initialize(resource_id)
  @resource_id = resource_id
  @tags = []
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/cfn_manage/tag_finder.rb', line 8

def opts
  @opts
end

#priorityObject (readonly)

Returns the value of attribute priority.



8
9
10
# File 'lib/cfn_manage/tag_finder.rb', line 8

def priority
  @priority
end

Instance Method Details

#asgObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cfn_manage/tag_finder.rb', line 37

def asg()
  credentials = CfnManage::AWSCredentials.get_session_credentials("cfn_manage_get_tags")
  client = Aws::AutoScaling::Client.new(credentials: credentials, retry_limit: 20)
  resp = client.describe_tags({
    filters: [
      {
        name: "auto-scaling-group", 
        values: [@resource_id]
      }
    ]
  })
  @tags = resp.tags
end

#ec2Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cfn_manage/tag_finder.rb', line 51

def ec2()
  credentials = CfnManage::AWSCredentials.get_session_credentials("cfn_manage_get_tags")
  client = Aws::EC2::Client.new(credentials: credentials, retry_limit: 20)
  resp = client.describe_tags({
    filters: [
      {
        name: "resource-id", 
        values: [@resource_id]
      }
    ]
  })
  @tags = resp.tags
end

#ecs_clusterObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/cfn_manage/tag_finder.rb', line 65

def ecs_cluster()
  credentials = CfnManage::AWSCredentials.get_session_credentials("cfn_manage_get_tags")
  client = Aws::ECS::Client.new(credentials: credentials, retry_limit: 20)
  resp = client.describe_clusters({
    clusters: [@resource_id],
    include: ["TAGS"]
  })
  cluster = resp.clusters.first
  @tags = cluster.tags
end

#get_tags(resource_type) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/cfn_manage/tag_finder.rb', line 15

def get_tags(resource_type)
  case resource_type
  when 'AWS::AutoScaling::AutoScalingGroup'
    asg()
  when 'AWS::EC2::Instance'
    ec2()
  when 'AWS::ECS::Cluster'
    ecs_cluster()
  end
end

#optionsObject



30
31
32
33
34
35
# File 'lib/cfn_manage/tag_finder.rb', line 30

def options()
  # collect all the cfn_manage tags and pass the back as a hash 
  # so they can be passed into the resource handers
  options = @tags.select {|tag| tag.key.start_with?('cfn_manage:') }
  options.collect { |tag| { tag.key.split(':').last.to_sym => tag.value } }.reduce(Hash.new,:merge)
end