Last active
January 12, 2017 01:02
-
-
Save markcerqueira/2fe0d1ab7654febaa6735316b72b3882 to your computer and use it in GitHub Desktop.
ACME challenge responder for Sinatra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController | |
# ACME Challenge responder. See: https://github.com/dmathieu/sabayon | |
# If you want to keep this code in a separate controller, remove /.well-known from | |
# the next line, make a new controller that inherits from ApplicationController (in | |
# this example ChallengeController), and put this line in your config.ru file: | |
# map('/.well-known/') { run ChallengeController } | |
get '/.well-known/acme-challenge/:token' do | |
data = [] | |
if ENV['ACME_KEY'] && ENV['ACME_TOKEN'] | |
data << { key: ENV['ACME_KEY'], token: ENV['ACME_TOKEN'] } | |
else | |
ENV.each do |k, v| | |
if d = k.match(/^ACME_KEY_([0-9]+)/) | |
index = d[1] | |
data << { key: v, token: ENV["ACME_TOKEN_#{index}"] } | |
end | |
end | |
end | |
data.each do |e| | |
if env['PATH_INFO'] == "/acme-challenge/#{e[:token]}" | |
status 200 | |
content_type 'text/plain' | |
body "#{e[:key]}" | |
"#{e[:key]}" | |
return | |
end | |
end | |
status 500 | |
content_type 'text/plain' | |
body 'No key found' | |
'No key found' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment