Sha256: c803badc7db96970417dafa6774d1c92982848cb32fa48bf0502206035c1dde4

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require "digicert/base"

module Digicert
  class OrderManager < Digicert::Base
    include Digicert::Actions::Create

    def self.create(order_id:, **attributes)
      new(resource_id: order_id, **attributes).create
    end

    private

    def validate(attributes)
      { certificate: order_attributes.merge(attributes) }
    end

    def order_attributes
      {
        common_name: order.certificate.common_name,
        dns_names: simplified_certificate_dns_names,
        csr: order.certificate.csr,
        signature_hash: order.certificate.signature_hash,

        # In a recent changes, the order response does not seem
        # to have the paltform id in it, so let's not try to fetch
        # the platform id for now, and once confirmed then we can
        # also adjust this as necessary.
        #
        # server_platform: { id: order.certificate.server_platform.id },
      }
    end

    def order
      @order ||= Digicert::Order.fetch(order_id)
    end

    def simplified_certificate_dns_names
      if order.product.name_id == "ssl_ev_plus"
        simplify_dns_name_to_duplicate_ev_plus
      else
        order.certificate.dns_names
      end
    end

    def simplify_dns_name_to_duplicate_ev_plus
      dns_names = order.certificate.dns_names
      dns_names.select { |dns_name| dns_name.match(/.+\..+\..+/) }.uniq
    end

    # Expose the resource_id as order_id, as it sounds
    # more readable and all of it's subclasses are only
    # gonna deal with order.
    #
    alias_method :order_id, :resource_id
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
digicert-0.4.1 lib/digicert/order_manager.rb
digicert-0.4.0 lib/digicert/order_manager.rb