diff --git a/lib/fog/aws/elb.rb b/lib/fog/aws/elb.rb index e6c08fd47..4487c658b 100644 --- a/lib/fog/aws/elb.rb +++ b/lib/fog/aws/elb.rb @@ -21,7 +21,7 @@ module Fog request :enable_availability_zones_for_load_balancer request :register_instances_with_load_balancer #request :set_load_balancer_listener_ssl_certificate - #request :set_load_balancer_policies_of_listener + request :set_load_balancer_policies_of_listener class Mock 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 new file mode 100644 index 000000000..f8b209b68 --- /dev/null +++ b/lib/fog/aws/requests/elb/set_load_balancer_policies_of_listener.rb @@ -0,0 +1,43 @@ +module Fog + module AWS + class ELB + class Real + + require 'fog/aws/parsers/elb/empty' + + # Associates, updates, or disables a policy with a listener on the + # load balancer. Currently only zero (0) or one (1) policy can be + # associated with a listener. + # + # ==== Parameters + # * lb_name<~String> - Name of the ELB + # * load_balancer_port<~Integer> - The external port of the LoadBalancer + # with which this policy has to be associated. + + # * policy_names<~Array> - List of policies to be associated with the + # listener. Currently this list can have at most one policy. If the + # list is empty, the current policy is removed from the listener. + # ==== Returns + # * response<~Excon::Response>: + # * body<~Hash>: + # * 'ResponseMetadata'<~Hash>: + # * 'RequestId'<~String> - Id of request + def set_load_balancer_policies_of_listener(lb_name, load_balancer_port, policy_names) + params = {'LoadBalancerPort' => load_balancer_port} + if policy_names.any? + params.merge!(AWS.indexed_param('PolicyNames.member', policy_names)) + else + params['PolicyNames'] = '' + end + + request({ + 'Action' => 'SetLoadBalancerPoliciesOfListener', + 'LoadBalancerName' => lb_name, + :parser => Fog::Parsers::AWS::ELB::Empty.new + }.merge!(params)) + end + + end + end + end +end diff --git a/tests/aws/requests/elb/load_balancer_tests.rb b/tests/aws/requests/elb/load_balancer_tests.rb index e1e67cf84..9ec86adc9 100644 --- a/tests/aws/requests/elb/load_balancer_tests.rb +++ b/tests/aws/requests/elb/load_balancer_tests.rb @@ -55,6 +55,17 @@ Shindo.tests('AWS::ELB | load_balancer_tests', ['aws', 'elb']) do AWS[:elb].create_load_balancer_listeners(@load_balancer_id, listeners).body end + tests("#set_load_balancer_policies_of_listener adds policy").formats(AWS::ELB::Formats::BASIC) do + port, policies = 80, ['fog-lb-expiry'] + body = AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, policies).body + end + + tests("#set_load_balancer_policies_of_listener removes policy").formats(AWS::ELB::Formats::BASIC) do + port = 80 + body = AWS[:elb].set_load_balancer_policies_of_listener(@load_balancer_id, port, []).body + end + + tests("#delete_load_balancer_listeners").formats(AWS::ELB::Formats::BASIC) do ports = [80, 443] AWS[:elb].delete_load_balancer_listeners(@load_balancer_id, ports).body