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

[AWS|ELB] policy model and collection support creating and showing OtherPolicies

This commit is contained in:
Michael Hale 2013-08-01 16:36:11 -04:00
parent 8ae33f1a2e
commit 8128fce600
3 changed files with 35 additions and 15 deletions

View file

@ -19,17 +19,21 @@ module Fog
private
# Munge a hash like:
# {'LBCookieStickinessPolicies' => [policies...],
# 'AppCookieStickinessPolicies' => [policies...]}
# to a single array of policies with a cookie_stickiness value
# 'AppCookieStickinessPolicies' => [policies...],
# 'OtherPolicies' => [policies...]}
# to a single array of policies with an optional cookie_stickiness value
def munged_data
munged_data = []
data['LBCookieStickinessPolicies'].each do |policy|
munged_data << policy.merge(:cookie_stickiness => :lb)
end
data['AppCookieStickinessPolicies'].each do |policy|
data['AppCookieStickinessPolicies'].each do |policy|
munged_data << policy.merge(:cookie_stickiness => :app)
end
munged_data
data['OtherPolicies'].each do |policy|
munged_data << {'PolicyName' => policy}
end
munged_data
end
end

View file

@ -8,23 +8,33 @@ module Fog
attribute :cookie, :aliases => 'CookieName'
attribute :expiration, :aliases => 'CookieExpirationPeriod'
attribute :type_name
attribute :policy_attributes
attr_accessor :cookie_stickiness # Either :app or :lb
def save
requires :id, :load_balancer, :cookie_stickiness
requires :id, :load_balancer
service_method = nil
args = [load_balancer.id, id]
case cookie_stickiness
when :app
requires :cookie
method = :create_app_cookie_stickiness_policy
args << cookie
when :lb
method = :create_lb_cookie_stickiness_policy
args << expiration if expiration
if cookie_stickiness
case cookie_stickiness
when :app
requires :cookie
method = :create_app_cookie_stickiness_policy
args << cookie
when :lb
method = :create_lb_cookie_stickiness_policy
args << expiration if expiration
else
raise ArgumentError.new('cookie_stickiness must be :app or :lb')
end
else
raise ArgumentError.new('cookie_stickiness must be :app or :lb')
requires :type_name, :policy_attributes
method = :create_load_balancer_policy
args << type_name
args << policy_attributes
end
service.send(method, *args)

View file

@ -277,6 +277,12 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
returns([]) { elb.listeners.get(80).policy_names }
end
public_key_policy_id = 'fog-public-key-policy'
tests('create public key policy') do
elb.policies.create(:id => public_key_policy_id, :type_name => 'PublicKeyPolicyType', :policy_attributes => {'PublicKey' => AWS::IAM::SERVER_CERT_PUBLIC_KEY})
returns(public_key_policy_id) { elb.policies.get(public_key_policy_id).id }
end
tests('a malformed policy') do
raises(ArgumentError) { elb.policies.create(:id => 'foo', :cookie_stickiness => 'invalid stickiness') }
end
@ -290,7 +296,7 @@ Shindo.tests('AWS::ELB | models', ['aws', 'elb']) do
tests('with a backend policy') do
policy = "EnableProxyProtocol"
port = 80
Fog::AWS[:elb].create_load_balancer_policy(elb.id, policy, 'ProxyProtocolPolicyType', { "ProxyProtocol" => true })
elb.policies.create(:id => policy, :type_name => 'ProxyProtocolPolicyType', :policy_attributes => { "ProxyProtocol" => true })
Fog::AWS[:elb].set_load_balancer_policies_for_backend_server(elb.id, port, [policy]).body
elb.reload
returns([policy]) { elb.backend_server_descriptions.get(port).policy_names }