Sha256: 459767671e3c9369a31e051156160f9ce68141fe4c3995c9f7b4fce22c626f19

Contents?: true

Size: 1012 Bytes

Versions: 5

Compression:

Stored size: 1012 Bytes

Contents

module Digicert
  module CLI
    class CSR < Digicert::CLI::Base
      def fetch
        if order
          order.certificate.csr
        end
      end

      def generate
        if order
          generate_csr_for(order)
        end
      end

      private

      attr_reader :rsa_key

      def extract_local_attributes(options)
        @rsa_key = options.fetch(:key, nil)
      end

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

      def generate_csr_for(order)
        if rsa_key && File.exists?(rsa_key)
          Digicert::CSRGenerator.generate(csr_attributes(order))
        end
      end

      def csr_attributes(order)
        Hash.new.tap do |csr|
          csr[:rsa_key] = File.read(rsa_key)
          csr[:organization] = order.organization
          csr[:common_name] =
            options[:common_name] || order.certificate.common_name

          if options[:san]
            csr[:san_names] = options[:san]
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
digicert-cli-0.4.2 lib/digicert/cli/csr.rb
digicert-cli-0.4.1 lib/digicert/cli/csr.rb
digicert-cli-0.4.0 lib/digicert/cli/csr.rb
digicert-cli-0.3.0 lib/digicert/cli/csr.rb
digicert-cli-0.2.0 lib/digicert/cli/csr.rb