Sha256: 177bdf303530b58a4deab1896e05b97f45cd69a250c7843029b32bb93f305952

Contents?: true

Size: 924 Bytes

Versions: 22

Compression:

Stored size: 924 Bytes

Contents

require 'certmeister/policy/response'

module Certmeister

  module Policy

    class Domain

      def initialize(domains)
        validate_domains(domains)
        @domains = domains.map { |domain| ".#{domain}" }
      end

      def authenticate(request)
        if not request[:cn]
          Certmeister::Policy::Response.new(false, "missing cn")
        elsif not @domains.any? { |domain| request[:cn].end_with?(domain) }
          Certmeister::Policy::Response.new(false, "cn in unknown domain")
        else
          Certmeister::Policy::Response.new(true, nil)
        end
      end

      private

      def validate_domains(domains)
        unless domains.is_a?(Enumerable) and domains.respond_to?(:size) and domains.size > 0 and
               domains.all? { |psk| psk.respond_to?(:to_s) }
          raise ArgumentError.new("enumerable collection of domains required")
        end
      end

    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
certmeister-0.0.2 lib/certmeister/policy/domain.rb
certmeister-0.0.1 lib/certmeister/policy/domain.rb