2011-05-11 15:27:27 -04:00
|
|
|
require 'fog/aws/models/elb/policy'
|
2011-05-02 18:17:19 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class ELB
|
|
|
|
class Policies < Fog::Collection
|
2011-05-04 18:29:07 -04:00
|
|
|
|
2011-05-02 18:17:19 -04:00
|
|
|
model Fog::AWS::ELB::Policy
|
|
|
|
|
|
|
|
attr_accessor :data, :load_balancer
|
|
|
|
|
|
|
|
def all
|
|
|
|
load(munged_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(id)
|
|
|
|
all.detect{|policy| id == policy.id}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def munged_data
|
2013-08-02 18:21:42 -04:00
|
|
|
data.inject([]){|m,e|
|
2013-08-05 22:29:47 -04:00
|
|
|
policy_attribute_descriptions = e["PolicyAttributeDescriptions"]
|
|
|
|
|
|
|
|
policy = {
|
2013-08-02 18:21:42 -04:00
|
|
|
:id => e["PolicyName"],
|
|
|
|
:type_name => e["PolicyTypeName"],
|
2013-08-05 22:29:47 -04:00
|
|
|
:policy_attributes => policy_attributes(policy_attribute_descriptions)
|
2013-08-02 18:21:42 -04:00
|
|
|
}
|
2013-08-05 22:29:47 -04:00
|
|
|
|
|
|
|
case e["PolicyTypeName"]
|
|
|
|
when 'AppCookieStickinessPolicyType'
|
|
|
|
cookie_name = policy_attribute_descriptions.detect{|h| h['AttributeName'] == 'CookieName'}['AttributeValue']
|
|
|
|
policy['CookieName'] = cookie_name if cookie_name
|
|
|
|
when 'LBCookieStickinessPolicyType'
|
|
|
|
cookie_expiration_period = policy_attribute_descriptions.detect{|h| h['AttributeName'] == 'CookieExpirationPeriod'}['AttributeValue'].to_i
|
|
|
|
policy['CookieExpirationPeriod'] = cookie_expiration_period if cookie_expiration_period > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
m << policy
|
2013-08-02 18:21:42 -04:00
|
|
|
m
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def policy_attributes(policy_attribute_descriptions)
|
|
|
|
policy_attribute_descriptions.inject({}){|m,e|
|
|
|
|
m[e["AttributeName"]] = e["AttributeValue"]
|
|
|
|
m
|
|
|
|
}
|
2011-05-02 18:17:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|