servel 0.32.0 → 0.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/servel.rb +37 -4
- data/lib/servel/cli.rb +5 -13
- data/lib/servel/config_parser.rb +22 -20
- data/lib/servel/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36dac91c1fba1bbaa2ab70a7dc39404996216867968c93438f503ccc8dd15631
|
4
|
+
data.tar.gz: fedf2fb5c899e69de6715c40b64c4d7c652f6f01c6bec40c99cea1780ce6c16a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b52f97da999645b081ad452866fb032e841f073dbb9e3be5c28b4501062cca015d131872c237fc14cf5920421a0671ef8114d984c7bc320c4183f407da66cb3
|
7
|
+
data.tar.gz: 3d621057dd5499b01a69251a08e3d18c3dab29435fde99313f43484d0ae53ba443ca9aec6c16b71369a8e0a25dd5319bf029104cf7c385bf32913cc4d928cc92
|
data/lib/servel.rb
CHANGED
@@ -9,18 +9,51 @@ require 'tty-config'
|
|
9
9
|
require 'thread'
|
10
10
|
require 'pathname'
|
11
11
|
require 'json'
|
12
|
+
require 'digest'
|
12
13
|
|
13
14
|
module Servel
|
14
|
-
def self.build_app(
|
15
|
+
def self.build_app(listings:, username: nil, password: nil)
|
16
|
+
app = build_listings_app(build_path_map(listings))
|
17
|
+
|
18
|
+
if username && username != ""
|
19
|
+
build_authentication_app(app: app, username: username, password: password)
|
20
|
+
else
|
21
|
+
app
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.build_authentication_app(app:, username:, password:)
|
26
|
+
hashed_username = Digest::SHA512.digest(username)
|
27
|
+
hashed_password = Digest::SHA512.digest(password)
|
28
|
+
|
29
|
+
Rack::Auth::Basic.new(app) do |submitted_username, submitted_password|
|
30
|
+
hashed_submitted_username = Digest::SHA512.digest(submitted_username)
|
31
|
+
hashed_submitted_password = Digest::SHA512.digest(submitted_password)
|
32
|
+
|
33
|
+
Rack::Utils.secure_compare(
|
34
|
+
"#{hashed_username}#{hashed_password}",
|
35
|
+
"#{hashed_submitted_username}#{hashed_submitted_password}"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.build_path_map(listings)
|
41
|
+
listings.map do |listing|
|
42
|
+
listing = { listing => nil } if listing.is_a?(String)
|
43
|
+
|
44
|
+
root, url_root = listing.keys.first, listing.values.first || "/"
|
45
|
+
[Pathname.new(root).realpath, url_root]
|
46
|
+
end.to_h
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.build_listings_app(path_map)
|
15
50
|
url_map = path_map.map { |root, url_root| [url_root, Servel::App.new(root)] }.to_h
|
16
51
|
url_map["/"] = Servel::HomeApp.new(path_map.values) unless url_map.keys.include?("/")
|
17
52
|
|
18
53
|
Rack::URLMap.new(url_map)
|
19
54
|
end
|
20
55
|
|
21
|
-
|
22
|
-
@config ||= Servel::ConfigParser.new.config
|
23
|
-
end
|
56
|
+
|
24
57
|
end
|
25
58
|
|
26
59
|
require "servel/version"
|
data/lib/servel/cli.rb
CHANGED
@@ -5,20 +5,12 @@ class Servel::CLI
|
|
5
5
|
:binds
|
6
6
|
]
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def initialize
|
9
|
+
@config = Servel::ConfigParser.new.config
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
Servel.config.
|
14
|
-
|
15
|
-
|
16
|
-
root, url_root = listing.keys.first, listing.values.first || "/"
|
17
|
-
[Pathname.new(root).realpath, url_root]
|
18
|
-
end.to_h
|
19
|
-
end
|
20
|
-
|
21
|
-
def puma_options
|
22
|
-
Servel.config.to_h.transform_keys(&:to_sym).slice(*ALLOWED_PUMA_OPTIONS)
|
12
|
+
def start
|
13
|
+
app = Servel.build_app(**@config.slice(:listings, :username, :password))
|
14
|
+
Rack::Handler::Puma.run(app, **@config.slice(*ALLOWED_PUMA_OPTIONS))
|
23
15
|
end
|
24
16
|
end
|
data/lib/servel/config_parser.rb
CHANGED
@@ -2,17 +2,19 @@ class Servel::ConfigParser
|
|
2
2
|
attr_reader :config
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
@
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
|
14
|
-
@
|
5
|
+
@tty_config = TTY::Config.new
|
6
|
+
@tty_config.filename = "servel"
|
7
|
+
@tty_config.append_path(Dir.pwd)
|
8
|
+
@tty_config.append_path((Pathname.new(Dir.home) + ".servel").to_s)
|
9
|
+
@tty_config.append_path(Dir.home)
|
10
|
+
@tty_config.env_prefix = "servel"
|
11
|
+
@tty_config.autoload_env
|
12
|
+
@tty_config.read if @tty_config.exist?
|
13
|
+
|
14
|
+
@tty_config.append(*parse_argv, to: :listings)
|
15
15
|
parse_binds
|
16
|
+
|
17
|
+
@config = @tty_config.to_h.transform_keys(&:to_sym)
|
16
18
|
end
|
17
19
|
|
18
20
|
def parse_argv
|
@@ -23,21 +25,21 @@ class Servel::ConfigParser
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def parse_binds
|
26
|
-
return parse_ssl_bind if @
|
28
|
+
return parse_ssl_bind if @tty_config.fetch(:cert) && @tty_config.fetch(:key)
|
27
29
|
|
28
|
-
host = @
|
29
|
-
port = @
|
30
|
-
@
|
31
|
-
@
|
30
|
+
host = @tty_config.fetch(:host)
|
31
|
+
port = @tty_config.fetch(:port)
|
32
|
+
@tty_config.set(:Host, value: host) if host
|
33
|
+
@tty_config.set(:Port, value: port) if port
|
32
34
|
end
|
33
35
|
|
34
36
|
def parse_ssl_bind
|
35
|
-
host = @
|
36
|
-
port = @
|
37
|
-
key = Pathname.new(@
|
38
|
-
cert = Pathname.new(@
|
37
|
+
host = @tty_config.fetch(:host, default: ::Puma::ConfigDefault::DefaultTCPHost)
|
38
|
+
port = @tty_config.fetch(:port, default: ::Puma::ConfigDefault::DefaultTCPPort)
|
39
|
+
key = Pathname.new(@tty_config.fetch(:key)).expand_path
|
40
|
+
cert = Pathname.new(@tty_config.fetch(:cert)).expand_path
|
39
41
|
|
40
42
|
query = URI.encode_www_form(key: key, cert: cert)
|
41
|
-
@
|
43
|
+
@tty_config.append("ssl://#{host}:#{port}?#{query}", to: :binds)
|
42
44
|
end
|
43
45
|
end
|
data/lib/servel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.33.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brenton "B-Train" Fletcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|