Skip to content

Commit

Permalink
Fixes pixielabs#16
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Merritt committed Feb 17, 2017
1 parent c678a6a commit 590edd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/letsencrypt-rails-heroku/letsencrypt.rb
Expand Up @@ -9,29 +9,33 @@ def self.configure
end

def self.challenge_configured?
configuration.acme_challenge_filename &&
configuration.acme_challenge_filename.start_with?(".well-known/") &&
configuration.acme_challenge_file_content
configuration.acme_challenge_filename &&
configuration.acme_challenge_filename.start_with?(".well-known/") &&
configuration.acme_challenge_file_content
end

class Configuration
attr_accessor :heroku_token, :heroku_app, :acme_email, :acme_domain, :acme_endpoint

# Not settable by user; part of the gem's behaviour.
attr_reader :acme_challenge_filename, :acme_challenge_file_content

def initialize
@heroku_token = ENV["HEROKU_TOKEN"]
@heroku_app = ENV["HEROKU_APP"]
@acme_email = ENV["ACME_EMAIL"]
@acme_domain = ENV["ACME_DOMAIN"]
@acme_endpoint = ENV["ACME_ENDPOINT"] || 'https://acme-v01.api.letsencrypt.org/'
@acme_challenge_filename = ENV["ACME_CHALLENGE_FILENAME"]
@heroku_token = ENV["HEROKU_TOKEN"]
@heroku_app = ENV["HEROKU_APP"]
@acme_email = ENV["ACME_EMAIL"]
@acme_domain = ENV["ACME_DOMAIN"]
@acme_endpoint = ENV["ACME_ENDPOINT"] || 'https://acme-v01.api.letsencrypt.org/'
@acme_challenge_filename = ENV["ACME_CHALLENGE_FILENAME"]
@acme_challenge_file_content = ENV["ACME_CHALLENGE_FILE_CONTENT"]
end

def valid?
heroku_token && heroku_app && acme_email && acme_domain
end

def middleware_loaded?
Rails.application.config.middleware.middlewares.include?("Letsencrypt::Middleware")
end
end
end
2 changes: 2 additions & 0 deletions lib/tasks/letsencrypt.rake
Expand Up @@ -10,6 +10,8 @@ namespace :letsencrypt 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, acme_email and acme_domain configured either via a `Letsencrypt.configure` block in an initializer or as environment variables." unless Letsencrypt.configuration.valid?

abort "The Letsencrypt middleware is not loaded" unless Letsencrypt.configuration.middleware_loaded?

# Set up Heroku client
heroku = PlatformAPI.connect_oauth Letsencrypt.configuration.heroku_token
heroku_app = Letsencrypt.configuration.heroku_app
Expand Down

0 comments on commit 590edd3

Please sign in to comment.