Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ACME challenge responder for Sinatra
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