-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ru
41 lines (34 loc) · 969 Bytes
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "rack"
require "open-uri"
app = lambda do |env|
user = env["PATH_INFO"].sub("/", "").strip
if user == "team"
keys = Dir[File.join(File.dirname(__FILE__), "files", "*.pub")].map do |file|
File.read(file).strip
end.join("\n")
[200, {"Content-Type" => "text/plain"}, [keys + "\n"]]
else
# We are fetching data from github because:
# - it will be always more up-to-date
# - I don't want to worry about security issues
# when serving files from disk based on path
# - it just works
sources = [
"https://raw.github.com/monterail/keys/master/files/active/#{user}.pub",
"https://github.com/#{user}.keys"
]
key = nil
until key || sources.empty?
begin
key = open(sources.shift).readlines.first.strip
rescue OpenURI::HTTPError
end
end
if key
[200, {"Content-Type" => "text/plain"}, [key + "\n"]]
else
[404, {}, []]
end
end
end
run app