Class: CfnManage::TagFinder
- Inherits:
-
Object
- Object
- CfnManage::TagFinder
- Defined in:
- lib/cfn_manage/tag_finder.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Instance Method Summary collapse
- #asg ⇒ Object
- #ec2 ⇒ Object
- #ecs_cluster ⇒ Object
- #get_tags(resource_type) ⇒ Object
-
#initialize(resource_id) ⇒ TagFinder
constructor
A new instance of TagFinder.
- #options ⇒ Object
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
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/cfn_manage/tag_finder.rb', line 8 def opts @opts end |
#priority ⇒ Object (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
#asg ⇒ Object
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.({ filters: [ { name: "auto-scaling-group", values: [@resource_id] } ] }) @tags = resp. end |
#ec2 ⇒ Object
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.({ filters: [ { name: "resource-id", values: [@resource_id] } ] }) @tags = resp. end |
#ecs_cluster ⇒ Object
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. 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 (resource_type) case resource_type when 'AWS::AutoScaling::AutoScalingGroup' asg() when 'AWS::EC2::Instance' ec2() when 'AWS::ECS::Cluster' ecs_cluster() end end |
#options ⇒ Object
30 31 32 33 34 35 |
# File 'lib/cfn_manage/tag_finder.rb', line 30 def () # collect all the cfn_manage tags and pass the back as a hash # so they can be passed into the resource handers = @tags.select {|tag| tag.key.start_with?('cfn_manage:') } .collect { |tag| { tag.key.split(':').last.to_sym => tag.value } }.reduce(Hash.new,:merge) end |