Sha256: aab4676ccc5784bbde825a4616830ab3a2ebc95831bc0dd629a4b586b07cd50e

Contents?: true

Size: 771 Bytes

Versions: 19

Compression:

Stored size: 771 Bytes

Contents

require 'certmeister/policy/response'
require 'ipaddr'

module Certmeister

  module Policy

    class IP

      def initialize(networks)
        @networks = networks.map { |n| IPAddr.new(n) }
      end

      def authenticate(request)
        begin
          if !request[:ip]
            Certmeister::Policy::Response.new(false, "missing ip")
          else
            ip = IPAddr.new(request[:ip])
            if @networks.any? { |n| n.include?(ip) }
              Certmeister::Policy::Response.new(true, nil)
            else
              Certmeister::Policy::Response.new(false, "unauthorized ip")
            end
          end
        rescue IPAddr::Error
          Certmeister::Policy::Response.new(false, "invalid ip")
        end
      end

    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
certmeister-2.3.2 lib/certmeister/policy/ip.rb
certmeister-2.3.1 lib/certmeister/policy/ip.rb
certmeister-2.3.0 lib/certmeister/policy/ip.rb
certmeister-2.2.0 lib/certmeister/policy/ip.rb
certmeister-2.1.0 lib/certmeister/policy/ip.rb
certmeister-2.0.0 lib/certmeister/policy/ip.rb
certmeister-1.2.1 lib/certmeister/policy/ip.rb
certmeister-1.2.0 lib/certmeister/policy/ip.rb
certmeister-1.1.0 lib/certmeister/policy/ip.rb
certmeister-1.0.1 lib/certmeister/policy/ip.rb
certmeister-1.0.0 lib/certmeister/policy/ip.rb
certmeister-0.4.1 lib/certmeister/policy/ip.rb
certmeister-0.4.0 lib/certmeister/policy/ip.rb
certmeister-0.3.2 lib/certmeister/policy/ip.rb
certmeister-0.3.1 lib/certmeister/policy/ip.rb
certmeister-0.3.0 lib/certmeister/policy/ip.rb
certmeister-0.2.3 lib/certmeister/policy/ip.rb
certmeister-0.2.1 lib/certmeister/policy/ip.rb
certmeister-0.2.0 lib/certmeister/policy/ip.rb