mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Implement ELBV2 describe_tags endpoint
This commit is contained in:
parent
e220c91298
commit
2e7bb9aedf
3 changed files with 104 additions and 0 deletions
|
@ -7,6 +7,7 @@ module Fog
|
|||
request_path 'fog/aws/requests/elbv2'
|
||||
request :add_tags
|
||||
request :create_load_balancer
|
||||
request :describe_tags
|
||||
request :describe_load_balancers
|
||||
request :describe_listeners
|
||||
|
||||
|
|
53
lib/fog/aws/parsers/elbv2/describe_tags.rb
Normal file
53
lib/fog/aws/parsers/elbv2/describe_tags.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ELBV2
|
||||
class DescribeTags < Fog::Parsers::Base
|
||||
def reset
|
||||
@this_key = nil
|
||||
@this_value = nil
|
||||
@tags = Hash.new
|
||||
@response = { 'DescribeTagsResult' => { 'TagDescriptions' => [] }, 'ResponseMetadata' => {} }
|
||||
@in_tags = false
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
unless @in_tags
|
||||
@resource_arn = nil
|
||||
@tags = {}
|
||||
end
|
||||
when 'Tags'
|
||||
@in_tags = true
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
if @in_tags
|
||||
@tags[@this_key] = @this_value
|
||||
@this_key, @this_value = nil, nil
|
||||
else
|
||||
@response['DescribeTagsResult']['TagDescriptions'] << { 'Tags' => @tags, 'ResourceArn' => @resource_arn }
|
||||
end
|
||||
when 'Key'
|
||||
@this_key = value
|
||||
when 'Value'
|
||||
@this_value = value
|
||||
when 'ResourceArn'
|
||||
@resource_arn = value
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = value
|
||||
when 'Tags'
|
||||
@in_tags = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
50
lib/fog/aws/requests/elbv2/describe_tags.rb
Normal file
50
lib/fog/aws/requests/elbv2/describe_tags.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ELBV2
|
||||
class Real
|
||||
require 'fog/aws/parsers/elbv2/describe_tags'
|
||||
|
||||
# returns a Hash of tags for a load balancer
|
||||
# http://docs.aws.amazon.com/ElasticLoadBalancing/latest/APIReference/API_DescribeTags.html
|
||||
# ==== Parameters
|
||||
# * resource_arns <~Array> - ARN(s) of the ELB instance whose tags are to be retrieved
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
def describe_tags(resource_arns)
|
||||
request({
|
||||
'Action' => 'DescribeTags',
|
||||
:parser => Fog::Parsers::AWS::ELBV2::DescribeTags.new
|
||||
}.merge!(Fog::AWS.indexed_param('ResourceArns.member.%d', [*resource_arns]))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_tags(resource_arns)
|
||||
response = Excon::Response.new
|
||||
resource_arns = [*resource_arns]
|
||||
|
||||
tag_describtions = resource_arns.map do |resource_arn|
|
||||
if self.data[:load_balancers_v2][resource_arn]
|
||||
{
|
||||
"Tags"=>self.data[:tags][resource_arn],
|
||||
"ResourceArn"=>resource_arn
|
||||
}
|
||||
else
|
||||
raise Fog::AWS::ELBV2::NotFound.new("Elastic load balancer #{resource_arns} not found")
|
||||
end
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
response.body = {
|
||||
"ResponseMetadata"=>{"RequestId"=> Fog::AWS::Mock.request_id },
|
||||
"DescribeTagsResult"=>{"TagDescriptions"=> tag_describtions}
|
||||
}
|
||||
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue