Class: GitAuth::WebApp
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- GitAuth::WebApp
- Includes:
- Loggable
- Defined in:
- lib/gitauth/web_app.rb
Class Method Summary collapse
- .check_auth ⇒ Object
- .has_auth? ⇒ Boolean
- .run(options = {}) ⇒ Object
- .stop ⇒ Object
- .update_auth ⇒ Object
Instance Method Summary collapse
-
#root_with_message(message) ⇒ Object
Misc Helpers.
Class Method Details
.check_auth ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gitauth/web_app.rb', line 54 def self.check_auth GitAuth.prepare if !has_auth? if $stderr.tty? logger.verbose = true puts "For gitauth to continue, you need to provide a username and password." update_auth else logger.fatal "You need to provide a username and password for GitAuth to function; Please run 'gitauth webapp` once" exit! end end end |
.has_auth? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/gitauth/web_app.rb', line 31 def self.has_auth? username = GitAuth::Settings["web_username"] password = GitAuth::Settings["web_password_hash"] !(username.blank? || password.blank?) end |
.run(options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gitauth/web_app.rb', line 68 def self.run( = {}) check_auth set handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') logger.info "Starting up web server on #{port}" handler.run self, :Host => host, :Port => port do |server| GitAuth::WebApp.current_server = server set :running, true end rescue Errno::EADDRINUSE => e logger.fatal "Server is already running on port #{port}" end |
.stop ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/gitauth/web_app.rb', line 82 def self.stop if current_server.present? current_server.respond_to?(:stop!) ? current_server.stop! : current_server.stop end exit! logger.debug "Stopped Server." end |
.update_auth ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gitauth/web_app.rb', line 37 def self.update_auth raw_username = Readline.readline('GitAuth Username (default is \'gitauth\'): ') raw_username = 'gitauth' if raw_username.blank? raw_password = '' while raw_password.blank? system "stty -echo" raw_password = Readline.readline('GitAuth Password: ') system "stty echo" print "\n" puts "You need to provide a password, please try again" if raw_password.blank? end GitAuth::Settings.update!({ :web_username => raw_username, :web_password_hash => Digest::SHA256.hexdigest(raw_password) }) end |
Instance Method Details
#root_with_message(message) ⇒ Object
Misc Helpers
295 296 297 |
# File 'lib/gitauth/web_app.rb', line 295 def () "/?message=#{URI.encode()}" end |