Skip to content

Instantly share code, notes, and snippets.

@markcerqueira
Last active January 12, 2017 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markcerqueira/2fe0d1ab7654febaa6735316b72b3882 to your computer and use it in GitHub Desktop.
Save markcerqueira/2fe0d1ab7654febaa6735316b72b3882 to your computer and use it in GitHub Desktop.
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