Module: Servel
- Defined in:
- lib/servel.rb,
lib/servel/version.rb
Defined Under Namespace
Modules: Instrumentation
Classes: App, CLI, ConfigParser, Entry, EntryFactory, HamlContext, HomeApp, Index
Constant Summary
collapse
- VERSION =
"0.33.0"
Class Method Summary
collapse
Class Method Details
.build_app(listings:, username: nil, password: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/servel.rb', line 15
def self.build_app(listings:, username: nil, password: nil)
app = build_listings_app(build_path_map(listings))
if username && username != ""
build_authentication_app(app: app, username: username, password: password)
else
app
end
end
|
.build_authentication_app(app:, username:, password:) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/servel.rb', line 25
def self.build_authentication_app(app:, username:, password:)
hashed_username = Digest::SHA512.digest(username)
hashed_password = Digest::SHA512.digest(password)
Rack::Auth::Basic.new(app) do |submitted_username, submitted_password|
hashed_submitted_username = Digest::SHA512.digest(submitted_username)
hashed_submitted_password = Digest::SHA512.digest(submitted_password)
Rack::Utils.secure_compare(
"#{hashed_username}#{hashed_password}",
"#{hashed_submitted_username}#{hashed_submitted_password}"
)
end
end
|
.build_listings_app(path_map) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/servel.rb', line 49
def self.build_listings_app(path_map)
url_map = path_map.map { |root, url_root| [url_root, Servel::App.new(root)] }.to_h
url_map["/"] = Servel::HomeApp.new(path_map.values) unless url_map.keys.include?("/")
Rack::URLMap.new(url_map)
end
|
.build_path_map(listings) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/servel.rb', line 40
def self.build_path_map(listings)
listings.map do |listing|
listing = { listing => nil } if listing.is_a?(String)
root, url_root = listing.keys.first, listing.values.first || "/"
[Pathname.new(root).realpath, url_root]
end.to_h
end
|