Sha256: 5317a9b9fefbbe11fa691c79e16e222ac3942bc02ee86c06eec2c24d3333b680

Contents?: true

Size: 916 Bytes

Versions: 13

Compression:

Stored size: 916 Bytes

Contents

module LetsencryptWebfaction
  class CertificateWriter
    attr_reader :output_dir

    def initialize(output_dir, domain, certificate)
      @certificate = certificate

      cert_date = Time.now.strftime('%Y%m%d%H%M%S')

      expanded_dir = File.expand_path(output_dir)
      @output_dir = File.join(expanded_dir, domain, cert_date)
    end

    def write!
      create_folder!

      # Save the certificate and key
      write_file!('privkey.pem', @certificate.request.private_key.to_pem)
      write_file!('cert.pem', @certificate.to_pem)
      write_file!('chain.pem', @certificate.chain_to_pem)
      write_file!('fullchain.pem', @certificate.fullchain_to_pem)
    end

    private

    def create_folder!
      # Make sure the output directory exists.
      FileUtils.mkdir_p(output_dir)
    end

    def write_file!(filename, data)
      File.write(File.join(@output_dir, filename), data)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
letsencrypt_webfaction-1.1.8 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.7 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.6 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.5 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.4 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.3 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.2 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.1 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.1.0 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.0.1 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-1.0.0 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-0.0.2 lib/letsencrypt_webfaction/certificate_writer.rb
letsencrypt_webfaction-0.0.1 lib/letsencrypt_webfaction/certificate_writer.rb