From caaccecc9f666612a1bd4dcfe9b1a4d851486ca7 Mon Sep 17 00:00:00 2001 From: Dylan Egan Date: Mon, 19 Dec 2011 16:14:27 -0800 Subject: [PATCH] [aws|fog] crapiness and hacks. :v: --- .../create_app_cookie_stickiness_policy.rb | 19 ++++++++++++++++++- .../elb/create_lb_cookie_stickiness_policy.rb | 19 ++++++++++++++++++- .../aws/requests/elb/create_load_balancer.rb | 6 +++++- .../elb/create_load_balancer_policy.rb | 8 ++++---- .../elb/delete_load_balancer_policy.rb | 4 ++-- .../elb/describe_load_balancer_policies.rb | 4 ++-- .../requests/elb/describe_load_balancers.rb | 6 +++++- .../set_load_balancer_policies_of_listener.rb | 2 +- tests/aws/requests/elb/policy_tests.rb | 2 +- 9 files changed, 56 insertions(+), 14 deletions(-) diff --git a/lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb b/lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb index e8462431b..639482931 100644 --- a/lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb +++ b/lib/fog/aws/requests/elb/create_app_cookie_stickiness_policy.rb @@ -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 diff --git a/lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb b/lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb index 07d1cf3ae..37bf4591c 100644 --- a/lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb +++ b/lib/fog/aws/requests/elb/create_lb_cookie_stickiness_policy.rb @@ -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 diff --git a/lib/fog/aws/requests/elb/create_load_balancer.rb b/lib/fog/aws/requests/elb/create_load_balancer.rb index 229a7068a..87a0e9c3a 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer.rb @@ -82,7 +82,11 @@ module Fog 'Instances' => [], 'ListenerDescriptions' => listeners, 'LoadBalancerName' => lb_name, - 'Policies' => [], + 'Policies' => { + 'AppCookieStickinessPolicies' => [], + 'LBCookieStickinessPolicies' => [], + 'Proper' => [] + }, 'SourceSecurityGroup' => { 'GroupName' => '', 'OwnerAlias' => '' diff --git a/lib/fog/aws/requests/elb/create_load_balancer_policy.rb b/lib/fog/aws/requests/elb/create_load_balancer_policy.rb index 0ef610b36..9259ceac9 100644 --- a/lib/fog/aws/requests/elb/create_load_balancer_policy.rb +++ b/lib/fog/aws/requests/elb/create_load_balancer_policy.rb @@ -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 diff --git a/lib/fog/aws/requests/elb/delete_load_balancer_policy.rb b/lib/fog/aws/requests/elb/delete_load_balancer_policy.rb index 9eb3f5335..e5d0b40ea 100644 --- a/lib/fog/aws/requests/elb/delete_load_balancer_policy.rb +++ b/lib/fog/aws/requests/elb/delete_load_balancer_policy.rb @@ -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 = { diff --git a/lib/fog/aws/requests/elb/describe_load_balancer_policies.rb b/lib/fog/aws/requests/elb/describe_load_balancer_policies.rb index 691e997ce..28214ef54 100644 --- a/lib/fog/aws/requests/elb/describe_load_balancer_policies.rb +++ b/lib/fog/aws/requests/elb/describe_load_balancer_policies.rb @@ -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 = [] diff --git a/lib/fog/aws/requests/elb/describe_load_balancers.rb b/lib/fog/aws/requests/elb/describe_load_balancers.rb index 0c6532222..8b0c150e0 100644 --- a/lib/fog/aws/requests/elb/describe_load_balancers.rb +++ b/lib/fog/aws/requests/elb/describe_load_balancers.rb @@ -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 } } diff --git a/lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb b/lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb index 6b6b8348c..1fb9a3121 100644 --- a/lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb +++ b/lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb @@ -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 = "PolicyNotFoundOne or more specified policies were not found.#{Fog::AWS::Mock.request_id}" raise Excon::Errors.status_error({:expects => 200}, response) diff --git a/tests/aws/requests/elb/policy_tests.rb b/tests/aws/requests/elb/policy_tests.rb index 5ec79fc73..7761370ba 100644 --- a/tests/aws/requests/elb/policy_tests.rb +++ b/tests/aws/requests/elb/policy_tests.rb @@ -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