forked from fog/fog
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aws|elb] start working on policies. ✌️
- Loading branch information
Showing
5 changed files
with
177 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
lib/fog/aws/parsers/elb/describe_load_balancer_policy_types.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Fog | ||
module Parsers | ||
module AWS | ||
module ELB | ||
|
||
class DescribeLoadBalancerPolicyTypes < Fog::Parsers::Base | ||
|
||
def reset | ||
reset_policy_type | ||
reset_policy_attribute_type_description | ||
@results = { 'PolicyTypeDescriptions' => [] } | ||
@response = { 'DescribeLoadBalancerPolicyTypesResult' => {}, 'ResponseMetadata' => {} } | ||
end | ||
|
||
def reset_policy_type | ||
@policy_type = { 'Description' => '', 'PolicyAttributeTypeDescriptions' => [], 'PolicyTypeName' => '' } | ||
end | ||
|
||
def reset_policy_attribute_type_description | ||
@policy_attribute_type_description = { 'AttributeName' => '', 'AttributeValue' => '', 'Cardinality' => '', 'DefaultValue' => '', 'Description' => '' } | ||
end | ||
|
||
def start_element(name, attrs = []) | ||
super | ||
case name | ||
when 'PolicyAttributeTypeDescriptions' | ||
@in_policy_attribute_types = true | ||
end | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'member' | ||
if @in_policy_attribute_types | ||
@policy_type['PolicyAttributeTypeDescriptions'] << @policy_attribute_type_description | ||
reset_policy_attribute_type_description | ||
elsif !@in_policy_attribute_types | ||
@results['PolicyTypeDescriptions'] << @policy_type | ||
end | ||
|
||
when 'Description' | ||
if @in_policy_attribute_types | ||
@policy_attribute_type_description[name] = value | ||
else | ||
@policy_type[name] = value | ||
end | ||
when 'PolicyTypeName' | ||
@policy_type[name] = value | ||
|
||
when 'PolicyAttributeTypeDescriptions' | ||
@in_policy_attribute_types = false | ||
|
||
when 'AttributeName', 'AttributeValue', 'Cardinality', 'DefaultValue' | ||
@policy_attribute_type_description[name] = value | ||
|
||
when 'RequestId' | ||
@response['ResponseMetadata'][name] = value | ||
|
||
when 'DescribeLoadBalancerPolicyTypesResponse' | ||
@response['DescribeLoadBalancerPolicyTypesResult'] = @results | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
68 changes: 68 additions & 0 deletions
68
lib/fog/aws/requests/elb/describe_load_balancer_policy_types.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
module Fog | ||
module AWS | ||
class ELB | ||
class Real | ||
|
||
require 'fog/aws/parsers/elb/describe_load_balancer_policy_types' | ||
|
||
# Describe all or specified load balancer policy types | ||
# | ||
# ==== Parameters | ||
# * type_name<~Array> - Specifies the name of the policy types. If no names are specified, returns the description of all the policy types defined by Elastic Load Balancing service. | ||
# | ||
# ==== Returns | ||
# * response<~Excon::Response>: | ||
# * body<~Hash>: | ||
# * 'ResponseMetadata'<~Hash>: | ||
# * 'RequestId'<~String> - Id of request | ||
# * 'DescribeLoadBalancerPolicyTypesResult'<~Hash>: | ||
# * 'PolicyTypeDescriptions'<~Array> | ||
# * 'Description'<~String> - A human-readable description of the policy type. | ||
# * 'PolicyAttributeTypeDescriptions'<~Array> | ||
# * 'AttributeName'<~String> - The name of the attribute associated with the policy type. | ||
# * 'AttributeValue'<~String> - The type of attribute. For example, Boolean, Integer, etc. | ||
# * 'Cardinality'<~String> - The cardinality of the attribute. | ||
# * 'DefaultValue'<~String> - The default value of the attribute, if applicable. | ||
# * 'Description'<~String> - A human-readable description of the attribute. | ||
# * 'PolicyTypeName'<~String> - The name of the policy type. | ||
def describe_load_balancer_policy_types(type_names = []) | ||
params = Fog::AWS.indexed_param('PolicyTypeNames.member', [*type_names]) | ||
request({ | ||
'Action' => 'DescribeLoadBalancerPolicyTypes', | ||
:parser => Fog::Parsers::AWS::ELB::DescribeLoadBalancerPolicyTypes.new | ||
}.merge!(params)) | ||
end | ||
|
||
end | ||
|
||
class Mock | ||
def describe_load_balancer_policy_types(type_names = []) | ||
type_names = [*type_names] | ||
policy_types = if type_names.any? | ||
type_names.map do |type_name| | ||
policy_type = self.data[:policy_types].find { |name, data| name == type_name } | ||
raise Fog::AWS::ELB::PolicyTypeNotFound unless policy_type | ||
policy_type[1].dup | ||
end.compact | ||
else | ||
self.data[:policy_types].map { |policy_type, values| values.dup } | ||
end | ||
|
||
response = Excon::Response.new | ||
response.status = 200 | ||
|
||
response.body = { | ||
'ResponseMetadata' => { | ||
'RequestId' => Fog::AWS::Mock.request_id | ||
}, | ||
'DescribeLoadBalancerPolicyTypesResult' => { | ||
'PolicyTypeDescriptions' => policy_types | ||
} | ||
} | ||
|
||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters