pdf_search 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/web_server.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d33439a4266cb68c08fcf67484f09ecc7ac39228387a8e8b0a54758f1569c84
|
4
|
+
data.tar.gz: 84f39eb8a771abaf45d5b5d38a1342065ba562a664afa2b8e99dbab1f651624a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84064889972907aa6c5a81ca08a88be0acf43de33ada6bf3d2dad8c44b90dc2e856554de64b9ab44ea29f62dce0e1e670c335a3f8f283de017460cf6702bf372
|
7
|
+
data.tar.gz: 3f0396b7533dfe0c8d48abd95a96cbafd9066fcffa937b8d4a71f2fab420f49d33a69ecef5004a6346effd94403ec1584588d660c0709b57cf2e1eeb434c8933
|
data/lib/web_server.rb
CHANGED
@@ -4,11 +4,33 @@ require 'json'
|
|
4
4
|
class PdfSearch::WebServer
|
5
5
|
attr_accessor :daemon
|
6
6
|
|
7
|
+
def basic_auth
|
8
|
+
return @basic_auth if @basic_auth != nil
|
9
|
+
|
10
|
+
config = { :Realm => 'BanalBI Pdf-Search' }
|
11
|
+
|
12
|
+
htpasswd = WEBrick::HTTPAuth::Htpasswd.new 'banalbi-pdf-search'
|
13
|
+
htpasswd.set_passwd config[:Realm], ENV['PDF_SEARCH_USERNAME'] , ENV['PDF_SEARCH_PASSWORD']
|
14
|
+
htpasswd.flush
|
15
|
+
|
16
|
+
config[:UserDB] = htpasswd
|
17
|
+
|
18
|
+
puts config.inspect
|
19
|
+
|
20
|
+
@basic_auth = WEBrick::HTTPAuth::BasicAuth.new config
|
21
|
+
end
|
22
|
+
|
7
23
|
def start
|
8
24
|
start_server = lambda do
|
9
25
|
server = WEBrick::HTTPServer.new(:Port => 80, :DocumentRoot => ::PdfSearch.relative_to_gem_path(['html']))
|
10
26
|
|
11
27
|
server.mount_proc '/search' do |request, response|
|
28
|
+
if [ENV['PDF_SEARCH_USERNAME'], ENV['PDF_SEARCH_PASSWORD']].all? do |env_var|
|
29
|
+
env_var != nil && env_var != ''
|
30
|
+
end
|
31
|
+
|
32
|
+
basic_auth.authenticate(request, response)
|
33
|
+
end
|
12
34
|
query = request.query["query"]
|
13
35
|
elastic_response = ::PdfSearch::ElasticSearchClient.search q: "text:#{query}"
|
14
36
|
response.body = response_html(elastic_response)
|