Class: Aspera::WebAuth::Server
- Inherits:
-
Aspera::WebServerSimple
- Object
- WEBrick::HTTPServer
- Aspera::WebServerSimple
- Aspera::WebAuth::Server
- Defined in:
- lib/aspera/web_auth/server.rb
Overview
start a local web server then start a browser that will callback the local server upon authentication store the final query
Instance Attribute Summary collapse
-
#additional_info ⇒ Array<String>?
readonly
Keys of the query that the page gives to the user as a code to paste in a terminal,
nilfor the standard page. -
#expected_path ⇒ Array<String>?
readonly
Keys of the query that the page gives to the user as a code to paste in a terminal,
nilfor the standard page. -
#reply_keys ⇒ Array<String>?
readonly
Keys of the query that the page gives to the user as a code to paste in a terminal,
nilfor the standard page.
Attributes inherited from Aspera::WebServerSimple
Instance Method Summary collapse
-
#initialize(endpoint_url, additional_info = nil, reply_keys: nil) ⇒ Server
constructor
A new instance of Server.
-
#received_request ⇒ Hash
wait for request on web server (main thread).
-
#signal_request(request) ⇒ nil
Called by web server thread on received request.
-
#wait_stopped(timeout = 10) ⇒ nil
Wait until the server thread has ended: the response of the last request (page shown to the user) is sent.
Methods inherited from Aspera::WebServerSimple
#<<, assert_protected, loopback?, read_chain_file, self_signed_cert, serve, servlet_parameters, #start, url
Constructor Details
#initialize(endpoint_url, additional_info = nil, reply_keys: nil) ⇒ Server
Returns a new instance of Server.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aspera/web_auth/server.rb', line 79 def initialize(endpoint_url, additional_info = nil, reply_keys: nil) uri = URI.parse(endpoint_url) super(uri) @reply_keys = reply_keys @mutex = Mutex.new @cond = ConditionVariable.new @expected_path = uri.path.empty? ? '/' : uri.path @query = nil @additional_info = additional_info # last argument (self) is provided to constructor of servlet mount(@expected_path, Servlet, self) # server runs in thread @thread = Thread.new { start } end |
Instance Attribute Details
#additional_info ⇒ Array<String>? (readonly)
Returns Keys of the query that the page gives to the user as a code to paste in a terminal, nil for the standard page.
74 75 76 |
# File 'lib/aspera/web_auth/server.rb', line 74 def additional_info @additional_info end |
#expected_path ⇒ Array<String>? (readonly)
Returns Keys of the query that the page gives to the user as a code to paste in a terminal, nil for the standard page.
74 75 76 |
# File 'lib/aspera/web_auth/server.rb', line 74 def expected_path @expected_path end |
#reply_keys ⇒ Array<String>? (readonly)
Returns Keys of the query that the page gives to the user as a code to paste in a terminal, nil for the standard page.
74 75 76 |
# File 'lib/aspera/web_auth/server.rb', line 74 def reply_keys @reply_keys end |
Instance Method Details
#received_request ⇒ Hash
wait for request on web server (main thread)
117 118 119 120 121 122 123 |
# File 'lib/aspera/web_auth/server.rb', line 117 def received_request # wait for signal from thread, unless the request was already received (signal is not memorized) @mutex.synchronize { @cond.wait(@mutex) while @query.nil? } # tell server thread to stop shutdown return @query end |
#signal_request(request) ⇒ nil
Called by web server thread on received request
105 106 107 108 109 110 111 112 113 |
# File 'lib/aspera/web_auth/server.rb', line 105 def signal_request(request) raise WEBrick::HTTPStatus::NotFound, "unexpected path: #{request.path}" unless request.path.eql?(@expected_path) # acquire lock and signal change @mutex.synchronize do @query = request.query @cond.signal end nil end |
#wait_stopped(timeout = 10) ⇒ nil
Wait until the server thread has ended: the response of the last request (page shown to the user) is sent.
To call after received_request, when the process does not continue with a long operation.
98 99 100 101 |
# File 'lib/aspera/web_auth/server.rb', line 98 def wait_stopped(timeout = 10) @thread.join(timeout) nil end |