From c1874d32a49222a5cdcf71e09495c926f40de22c Mon Sep 17 00:00:00 2001 From: Abigail McPhillips Date: Fri, 3 Feb 2017 10:55:26 +0000 Subject: [PATCH] opens url with domain from ACME_DOMAIN variable --- lib/letsencrypt-rails-heroku.rb | 1 + lib/letsencrypt-rails-heroku/exceptions.rb | 8 ++++++++ lib/tasks/letsencrypt.rake | 14 +++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 lib/letsencrypt-rails-heroku/exceptions.rb diff --git a/lib/letsencrypt-rails-heroku.rb b/lib/letsencrypt-rails-heroku.rb index 0d025c6..74addbc 100644 --- a/lib/letsencrypt-rails-heroku.rb +++ b/lib/letsencrypt-rails-heroku.rb @@ -1,5 +1,6 @@ require 'letsencrypt-rails-heroku/letsencrypt' require 'letsencrypt-rails-heroku/middleware' +require 'letsencrypt-rails-heroku/exceptions' if defined?(Rails) require 'letsencrypt-rails-heroku/railtie' diff --git a/lib/letsencrypt-rails-heroku/exceptions.rb b/lib/letsencrypt-rails-heroku/exceptions.rb new file mode 100644 index 0000000..f216c70 --- /dev/null +++ b/lib/letsencrypt-rails-heroku/exceptions.rb @@ -0,0 +1,8 @@ +module Letsencrypt + module Error + # Exception raised when LetsEncrypt encounters an issue verifying the challenge. + class VerificationError < StandardError; end + # Exception raised when an error occurs adding the certificate to Heroku. + class HerokuCertError < StandardError; end + end +end diff --git a/lib/tasks/letsencrypt.rake b/lib/tasks/letsencrypt.rake index 348bbf9..c5d97c0 100644 --- a/lib/tasks/letsencrypt.rake +++ b/lib/tasks/letsencrypt.rake @@ -8,7 +8,7 @@ namespace :letsencrypt do desc 'Renew your LetsEncrypt certificate' task :renew do # Check configuration looks OK - abort "letsencrypt-rails-heroku is configured incorrectly. Are you missing an environment variable or other configuration? You should have a heroku_token, heroku_app, acmp_email and acme_domain configured either via a `Letsencrypt.configure` block in an initializer or as environment variables." unless Letsencrypt.configuration.valid? + abort "letsencrypt-rails-heroku is configured incorrectly. Are you missing an environment variable or other configuration? You should have a heroku_token, heroku_app, acme_email and acme_domain configured either via a `Letsencrypt.configure` block in an initializer or as environment variables." unless Letsencrypt.configuration.valid? # Set up Heroku client heroku = PlatformAPI.connect_oauth Letsencrypt.configuration.heroku_token @@ -50,9 +50,8 @@ namespace :letsencrypt do # Wait for app to come up print "Testing filename works (to bring up app)..." - # Get the domain name from Heroku - hostname = heroku.domain.list(heroku_app).first['hostname'] - open("http://#{hostname}/#{challenge.filename}").read + # Open challenge url + open("http://#{domain}/#{challenge.filename}").read puts "Done!" print "Giving LetsEncrypt some time to verify..." @@ -65,7 +64,8 @@ namespace :letsencrypt do unless challenge.verify_status == 'valid' puts "Problem verifying challenge." - abort "Status: #{challenge.verify_status}, Error: #{challenge.error}" + failure_message = "Status: #{challenge.verify_status}, Error: #{challenge.error}" + raise Letsencrypt::Error::VerificationError, failure_message end puts "" @@ -85,7 +85,7 @@ namespace :letsencrypt do certificate = client.new_certificate(csr) # => # # Send certificates to Heroku via API - + # First check for existing certificates: certificates = heroku.sni_endpoint.list(heroku_app) @@ -107,7 +107,7 @@ namespace :letsencrypt do end rescue Excon::Error::UnprocessableEntity => e warn "Error adding certificate to Heroku. Response from Heroku’s API follows:" - abort e.response.body + raise Letsencrypt::Error::HerokuCertError, e.response.body end end