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

[aws|fog] crapiness and hacks. ✌️

This commit is contained in:
Dylan Egan 2011-12-19 16:14:27 -08:00
parent c4cb974a37
commit caaccecc9f
9 changed files with 56 additions and 14 deletions

View file

@ -31,7 +31,24 @@ module Fog
class Mock
def create_app_cookie_stickiness_policy(lb_name, policy_name, cookie_name)
create_load_balancer_policy(lb_name, policy_name, 'AppCookieStickinessPolicyType', {'CookieName' => cookie_name})
if load_balancer = self.data[:load_balancers][lb_name]
response = Excon::Response.new
response.status = 200
load_balancer['Policies']['AppCookieStickinessPolicies'] << { 'CookieName' => cookie_name, 'PolicyName' => policy_name }
create_load_balancer_policy(lb_name, policy_name, 'AppCookieStickinessPolicyType', {'CookieName' => cookie_name})
response.body = {
'ResponseMetadata' => {
'RequestId' => Fog::AWS::Mock.request_id
}
}
response
else
raise Fog::AWS::ELB::NotFound
end
end
end
end

View file

@ -33,7 +33,24 @@ module Fog
class Mock
def create_lb_cookie_stickiness_policy(lb_name, policy_name, cookie_expiration_period=nil)
create_load_balancer_policy(lb_name, policy_name, 'LBCookieStickinessPolicyType', {'CookieExpirationPeriod' => cookie_expiration_period})
if load_balancer = self.data[:load_balancers][lb_name]
response = Excon::Response.new
response.status = 200
load_balancer['Policies']['LBCookieStickinessPolicies'] << { 'CookieExpirationPeriod' => cookie_expiration_period, 'PolicyName' => policy_name }
create_load_balancer_policy(lb_name, policy_name, 'LBCookieStickinessPolicyType', {'CookieExpirationPeriod' => cookie_expiration_period})
response.body = {
'ResponseMetadata' => {
'RequestId' => Fog::AWS::Mock.request_id
}
}
response
else
raise Fog::AWS::ELB::NotFound
end
end
end
end

View file

@ -82,7 +82,11 @@ module Fog
'Instances' => [],
'ListenerDescriptions' => listeners,
'LoadBalancerName' => lb_name,
'Policies' => [],
'Policies' => {
'AppCookieStickinessPolicies' => [],
'LBCookieStickinessPolicies' => [],
'Proper' => []
},
'SourceSecurityGroup' => {
'GroupName' => '',
'OwnerAlias' => ''

View file

@ -46,16 +46,16 @@ 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'].find { |p| p['PolicyName'] == 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 }
response = Excon::Response.new
attributes = attributes.map do |name, value|
{"AttributeName" => name, "AttributeValue" => value}
attributes = attributes.map do |key, value|
{"AttributeName" => key, "AttributeValue" => value.to_s}
end
load_balancer['Policies'] << {
load_balancer['Policies']['Proper'] << {
'PolicyAttributeDescriptions' => attributes,
'PolicyName' => name,
'PolicyTypeName' => type_name

View file

@ -33,8 +33,8 @@ module Fog
response = Excon::Response.new
response.status = 200
load_balancer['Policies'].delete_if do |policy|
policy['PolicyName'] == policy_name
load_balancer['Policies'].each do |name, policies|
policies.delete_if { |policy| policy['PolicyName'] == policy_name }
end
response.body = {

View file

@ -41,11 +41,11 @@ module Fog
names = [*names]
policies = if names.any?
names.map do |name|
raise Fog::AWS::ELB::PolicyNotFound unless policy = load_balancer['Policies'].find { |p| p['PolicyName'] == name }
raise Fog::AWS::ELB::PolicyNotFound unless policy = load_balancer['Policies']['Proper'].find { |p| p['PolicyName'] == name }
policy.dup
end.compact
else
load_balancer['Policies']
load_balancer['Policies']['Proper']
end
else
policies = []

View file

@ -73,7 +73,11 @@ module Fog
'RequestId' => Fog::AWS::Mock.request_id
},
'DescribeLoadBalancersResult' => {
'LoadBalancerDescriptions' => load_balancers.map { |lb| lb['Instances'] = lb['Instances'].map { |i| i['InstanceId'] }; lb }
'LoadBalancerDescriptions' => load_balancers.map do |lb|
lb['Instances'] = lb['Instances'].map { |i| i['InstanceId'] }
lb['Policies'] = lb['Policies'].reject { |name, policies| name == 'Proper' }
lb
end
}
}

View file

@ -57,7 +57,7 @@ module Fog
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless load_balancer['Policies'].find { |policy| policy['PolicyName'] == policy_names.first }
unless load_balancer['Policies']['Proper'].find { |policy| policy['PolicyName'] == policy_names.first }
response.status = 400
response.body = "<?xml version=\"1.0\"?><Response><Errors><Error><Code>PolicyNotFound</Code><Message>One or more specified policies were not found.</Message></Error></Errors><RequestID>#{Fog::AWS::Mock.request_id}</RequestId></Response>"
raise Excon::Errors.status_error({:expects => 200}, response)

View file

@ -33,7 +33,7 @@ Shindo.tests('AWS::ELB | policy_tests', ['aws', 'elb']) do
end
tests("#describe_load_balancer_policies").formats(AWS::ELB::Formats::DESCRIBE_LOAD_BALANCER_POLICIES) do
Fog::AWS[:elb].describe_load_balancer_policies(@load_balancer_id, 'fog-policy').body
Fog::AWS[:elb].describe_load_balancer_policies(@load_balancer_id).body
end
tests("#delete_load_balancer_policy").formats(AWS::ELB::Formats::BASIC) do