Sha256: 8ed96e46ee82417bd4250d8ed5d4c105a94c85e2d147b4fb66b8ad891c74b601

Contents?: true

Size: 1.96 KB

Versions: 71

Compression:

Stored size: 1.96 KB

Contents

require 'fog/aws/models/elb/policy'

module Fog
  module AWS
    class ELB
      class Policies < Fog::Collection

        attribute :load_balancer_id

        model Fog::AWS::ELB::Policy

        def all(options={})
          merge_attributes(options)

          requires :load_balancer_id

          data = service.describe_load_balancer_policies(self.load_balancer_id).
            body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"]

          load(munge(data))
        end

        def get(id)
          all.find { |policy| id == policy.id }
        end

        def new(attributes={})
          super(self.attributes.merge(attributes))
        end

        private

        def munge(data)
          data.reduce([]) { |m,e|
            policy_attribute_descriptions = e["PolicyAttributeDescriptions"]

            policy = {
              :id                => e["PolicyName"],
              :type_name         => e["PolicyTypeName"],
              :policy_attributes => policy_attributes(policy_attribute_descriptions),
              :load_balancer_id  => self.load_balancer_id,
            }

            case e["PolicyTypeName"]
            when 'AppCookieStickinessPolicyType'
              cookie_name = policy_attribute_descriptions.find{|h| h['AttributeName'] == 'CookieName'}['AttributeValue']
              policy['CookieName'] = cookie_name if cookie_name
            when 'LBCookieStickinessPolicyType'
              cookie_expiration_period = policy_attribute_descriptions.find{|h| h['AttributeName'] == 'CookieExpirationPeriod'}['AttributeValue'].to_i
              policy['CookieExpirationPeriod'] = cookie_expiration_period if cookie_expiration_period > 0
            end

            m << policy
            m
          }
        end

        def policy_attributes(policy_attribute_descriptions)
          policy_attribute_descriptions.reduce({}){|m,e|
            m[e["AttributeName"]] = e["AttributeValue"]
            m
          }
        end
      end
    end
  end
end

Version data entries

71 entries across 69 versions & 3 rubygems

Version Path
fog-aws-3.11.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.10.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.9.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.8.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.7.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.7 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.6 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.5 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.4 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.3 lib/fog/aws/models/elb/policies.rb
fog-aws-3.6.2 lib/fog/aws/models/elb/policies.rb
fog-aws-3.5.2 lib/fog/aws/models/elb/policies.rb
fog-aws-3.5.1 lib/fog/aws/models/elb/policies.rb
fog-aws-3.5.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.4.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.3.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.2.0 lib/fog/aws/models/elb/policies.rb
fog-aws-3.1.0 lib/fog/aws/models/elb/policies.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aws-2.0.1/lib/fog/aws/models/elb/policies.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aws-2.0.1/lib/fog/aws/models/elb/policies.rb