Sha256: b1e19e144669745e988e6d74eb83cde309e04b75088250bd763c9b685af67949

Contents?: true

Size: 1.89 KB

Versions: 4

Compression:

Stored size: 1.89 KB

Contents

require "date"

require "digicert/cli/order_retriever"
require "digicert/cli/certificate_downloader"

module Digicert
  module CLI
    class OrderReissuer < Digicert::CLI::Base
      def create
        apply_output_options(reissue_an_order)
      end

      def self.create(attributes)
        new(attributes).create
      end

      private

      attr_reader :csr_file, :output_path

      def extract_local_attributes(options)
        @csr_file = options.fetch(:csr, nil)
        @output_path = options.fetch(:output, "/tmp")
      end

      def reissue_an_order
        Digicert::OrderReissuer.create(order_params)
      end

      def order_params
        Hash.new.tap do |order_params|
          order_params[:order_id] = order_id

          if csr_file && File.exists?(csr_file)
            order_params[:csr] = File.read(csr_file)
          end
        end
      end

      def apply_output_options(reissue)
        if reissue
          print_request_details(reissue.requests.first)
          fetch_and_download_certificate(reissue.id)
        end
      end

      def print_request_details(request)
        Digicert::CLI::Util.say(
          "Reissue request #{request.id} created for order - #{order_id}",
        )
      end

      def fetch_and_download_certificate(reissued_order_id)
        if options[:output]
          order = fetch_reissued_order(reissued_order_id)
          download_certificate_order(order.certificate.id)
        end
      end

      def fetch_reissued_order(reissued_order_id)
        Digicert::CLI::OrderRetriever.fetch(
          reissued_order_id,
          wait_time: options[:wait_time],
          number_of_times: options[:number_of_times]
        )
      end

      def download_certificate_order(certificate_id)
        Digicert::CLI::CertificateDownloader.download(
          filename: order_id, path: output_path, certificate_id: certificate_id
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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