Class: DeployGate::BrowserLogin
- Inherits:
-
Object
- Object
- DeployGate::BrowserLogin
- Defined in:
- lib/deploygate/browser_login.rb
Constant Summary collapse
- DEFAULT_PORT =
64126
- LOGIN_URL =
"#{DeployGate::API::V1::Base::BASE_URL}/cli/login"
- CREDENTIAL_URL =
"#{DeployGate::API::V1::Base::BASE_URL}/cli/credential"
- NOTIFY_URL =
"#{DeployGate::API::V1::Base::BASE_URL}/cli/notify"
Instance Method Summary collapse
-
#initialize(port = nil) ⇒ BrowserLogin
constructor
A new instance of BrowserLogin.
- #start ⇒ Object
Constructor Details
#initialize(port = nil) ⇒ BrowserLogin
Returns a new instance of BrowserLogin.
9 10 11 12 13 14 15 16 |
# File 'lib/deploygate/browser_login.rb', line 9 def initialize(port = nil) @port = port || DEFAULT_PORT @login_uri = URI(LOGIN_URL) @login_uri.query = {port: @port, client: 'dg'}.to_query @credential_uri = URI(CREDENTIAL_URL) @notify_uri = URI(NOTIFY_URL) end |
Instance Method Details
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/deploygate/browser_login.rb', line 18 def start server = WEBrick::HTTPServer.new( :Port => @port, :BindAddress =>"localhost", :Logger => WEBrick::Log.new(STDOUT, 0), :AccessLog => [] ) begin Signal.trap("INT") { server.shutdown } server.mount_proc '/' do |req, res| res.status = WEBrick::HTTPStatus::RC_NO_CONTENT cancel = req.query['cancel'] notify_key = req.query['key'] unless cancel credential = get_credential(notify_key) DeployGate::Session.save(credential['name'], credential['token']) notify_finish(notify_key) DeployGate::Commands::Login.login_success() end server.stop end Launchy.open(@login_uri.to_s) server.start ensure server.shutdown end end |