1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[AWS|ELB] add support for OtherPolicies

This commit is contained in:
Michael Hale 2013-07-31 23:34:03 -04:00
parent 686e51bc12
commit 992a248711
5 changed files with 43 additions and 21 deletions

View file

@ -8,14 +8,14 @@ module Fog
def reset
reset_load_balancer
reset_listener_description
reset_policy
reset_stickiness_policy
reset_backend_server_description
@results = { 'LoadBalancerDescriptions' => [] }
@response = { 'DescribeLoadBalancersResult' => {}, 'ResponseMetadata' => {} }
end
def reset_load_balancer
@load_balancer = { 'Subnets' => [], 'SecurityGroups' => [], 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [] }, 'HealthCheck' => {}, 'SourceSecurityGroup' => {}, 'BackendServerDescriptions' => [] }
@load_balancer = { 'Subnets' => [], 'SecurityGroups' => [], 'ListenerDescriptions' => [], 'Instances' => [], 'AvailabilityZones' => [], 'Policies' => {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => [], 'OtherPolicies' => []}, 'HealthCheck' => {}, 'SourceSecurityGroup' => {}, 'BackendServerDescriptions' => [] }
end
def reset_listener_description
@ -26,8 +26,8 @@ module Fog
@backend_server_description = {}
end
def reset_policy
@policy = {}
def reset_stickiness_policy
@stickiness_policy = {}
end
def start_element(name, attrs = [])
@ -53,6 +53,8 @@ module Fog
@in_app_cookies = true
when 'AppCookieStickinessPolicies'
@in_app_cookies = true
when 'OtherPolicies'
@in_other_policies = true
when 'BackendServerDescriptions'
@in_backend_server_descriptions = true
end
@ -73,11 +75,13 @@ module Fog
@load_balancer['ListenerDescriptions'] << @listener_description
reset_listener_description
elsif @in_app_cookies
@load_balancer['Policies']['AppCookieStickinessPolicies'] << @policy
reset_policy
@load_balancer['Policies']['AppCookieStickinessPolicies'] << @stickiness_policy
reset_stickiness_policy
elsif @in_lb_cookies
@load_balancer['Policies']['LBCookieStickinessPolicies'] << @policy
reset_policy
@load_balancer['Policies']['LBCookieStickinessPolicies'] << @stickiness_policy
reset_stickiness_policy
elsif @in_other_policies
@load_balancer['Policies']['OtherPolicies'] << value
elsif @in_backend_server_descriptions && @in_policy_names
@backend_server_description['PolicyNames'] ||= []
@backend_server_description['PolicyNames'] << value
@ -130,6 +134,8 @@ module Fog
@in_app_cookies = false
when 'LBCookieStickinessPolicies'
@in_lb_cookies = false
when 'OtherPolicies'
@in_other_policies = false
when 'OwnerAlias', 'GroupName'
@load_balancer['SourceSecurityGroup'][name] = value
@ -140,9 +146,9 @@ module Fog
@load_balancer['HealthCheck'][name] = value
when 'PolicyName', 'CookieName'
@policy[name] = value
@stickiness_policy[name] = value
when 'CookieExpirationPeriod'
@policy[name] = value.to_i
@stickiness_policy[name] = value.to_i
when 'RequestId'
@response['ResponseMetadata'][name] = value

View file

@ -110,6 +110,7 @@ module Fog
'Policies' => {
'AppCookieStickinessPolicies' => [],
'LBCookieStickinessPolicies' => [],
'OtherPolicies' => [],
'Proper' => []
},
'SourceSecurityGroup' => {

View file

@ -33,12 +33,12 @@ module Fog
params.merge!(Fog::AWS.indexed_param('PolicyAttributes.member.%d.AttributeValue', attribute_value))
request({
'Action' => 'CreateLoadBalancerPolicy',
'LoadBalancerName' => lb_name,
'PolicyName' => name,
'PolicyTypeName' => type_name,
:parser => Fog::Parsers::AWS::ELB::Empty.new
}.merge!(params))
'Action' => 'CreateLoadBalancerPolicy',
'LoadBalancerName' => lb_name,
'PolicyName' => name,
'PolicyTypeName' => type_name,
:parser => Fog::Parsers::AWS::ELB::Empty.new
}.merge!(params))
end
end
@ -46,8 +46,8 @@ module Fog
class Mock
def create_load_balancer_policy(lb_name, name, type_name, attributes = {})
if load_balancer = self.data[:load_balancers][lb_name]
raise Fog::AWS::IAM::DuplicatePolicyName if policy = load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == name }
raise Fog::AWS::IAM::PolicyTypeNotFound unless policy_type = self.data[:policy_types].find { |pt| pt['PolicyTypeName'] == type_name }
raise Fog::AWS::ELB::DuplicatePolicyName, name if policy = load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == name }
raise Fog::AWS::ELB::PolicyTypeNotFound, policy_type unless policy_type = self.data[:policy_types].find { |pt| pt['PolicyTypeName'] == type_name }
response = Excon::Response.new
@ -55,6 +55,13 @@ module Fog
{"AttributeName" => key, "AttributeValue" => value.to_s}
end
# Update other policies
if %w[PublicKeyPolicyType ProxyProtocolPolicyType].include?(type_name)
unless load_balancer['Policies']['OtherPolicies'].include?(name)
load_balancer['Policies']['OtherPolicies'] << name
end
end
load_balancer['Policies']['Proper'] << {
'PolicyAttributeDescriptions' => attributes,
'PolicyName' => name,

View file

@ -44,6 +44,7 @@ module Fog
# * 'Policies'<~Hash>:
# * 'LBCookieStickinessPolicies'<~Array> - list of Load Balancer Generated Cookie Stickiness policies for the LoadBalancer
# * 'AppCookieStickinessPolicies'<~Array> - list of Application Generated Cookie Stickiness policies for the LoadBalancer
# * 'OtherPolicies'<~Array> - list of policy names other than the stickiness policies
# * 'SourceSecurityGroup'<~Hash>:
# * 'GroupName'<~String> - Name of the source security group to use with inbound security group rules
# * 'OwnerAlias'<~String> - Owner of the source security group

View file

@ -49,12 +49,19 @@ Shindo.tests('AWS::ELB | policy_tests', ['aws', 'elb']) do
Fog::AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, []).body
end
proxy_policy = "EnableProxyProtocol"
Fog::AWS[:elb].create_load_balancer_policy(@load_balancer_id, proxy_policy, 'ProxyProtocolPolicyType', { "ProxyProtocol" => true })
tests("#set_load_balancer_policies_for_backend_server replaces policies on port").formats(AWS::ELB::Formats::BASIC) do
policy = "EnableProxyProtocol"
Fog::AWS[:elb].create_load_balancer_policy(@load_balancer_id, policy, 'ProxyProtocolPolicyType', { "ProxyProtocol" => true })
Fog::AWS[:elb].set_load_balancer_policies_for_backend_server(@load_balancer_id, 80, [policy]).body
Fog::AWS[:elb].set_load_balancer_policies_for_backend_server(@load_balancer_id, 80, [proxy_policy]).body
end
tests("#describe_load_balancers has other policies") do
Fog::AWS[:elb].set_load_balancer_policies_for_backend_server(@load_balancer_id, 80, [proxy_policy]).body
description = Fog::AWS[:elb].describe_load_balancers("LoadBalancerNames" => [@load_balancer_id]).body["DescribeLoadBalancersResult"]["LoadBalancerDescriptions"].first
returns(true) { description["Policies"]["OtherPolicies"].include?(proxy_policy) }
end
Fog::AWS[:elb].delete_load_balancer(@load_balancer_id)
end
end